Let's say my graphql server wants to fetch the following data as JSON where person3
and person5
are some id's:
"persons": {
"person3": {
"id": "person3",
"name": "Mike"
},
"person5": {
"id": "person5",
"name": "Lisa"
}
}
Question: How to create the schema type definition with apollo?
The keys person3
and person5
here are dynamically generated depending on my query (i.e. the area
used in the query). So at another time I might get person1
, person2
, person3
returned.
As you see persons
is not an Iterable, so the following won't work as a graphql type definition I did with apollo:
type Person {
id: String
name: String
}
type Query {
persons(area: String): [Person]
}
The keys in the persons
object may always be different.
One solution of course would be to transform the incoming JSON data to use an array for persons
, but is there no way to work with the data as such?
b
andg
beingdynamically generated depending on my query
? Does the presence of one or the other depend on the fields present in the request? – Daniel Reardenb
andg
are id's. Perhaps I should make that clearer in the question. The query will contain options to only get a subset of people, so for one query the response will contain people with id'sa
,b
,c
and for another query for exampleb
andg
as in the question. – Andrub
toperson3
andg
toperson 5
and added some text and a variable to make it clearer. The query will contain options to only get a subset of people as now outlined in the text. – Andru