I have a response from an external API
genre_ids: [0: 16, 1: 21, 2: 46];
At this point, I have no clue how to define a schema for something like that.
Asked
Active
Viewed 363 times
0

Ivan Baranov
- 355
- 2
- 3
- 10
1 Answers
1
not sure what 0: 1: 2: etc. are, but i assume, that it is index in the array. If you would like to implement arrays of integers or ids you should use GraphQL modifiers. It is called GraphQL List and you can do in your schema something like this in graphql-js.
genreIds: {
type: new GraphQLList(GraphQLID),
resolve: () => {
// your external api call
return [ 16, 21, 46]
}
}
If you would like to know more detail. I have recently published article on implementing arrays in GraphQL schema. Here is the full code on how you can implement fetching array of users. Btw. not sure what you would like to do with these ids, but it is better schema architecture to replace it with GraphQL object type and fetche the genres list based on these ids. I hope that it helps.
David

David Mraz
- 545
- 4
- 8
-
You guessed it 100% correct about the index. I was going in a totally wrong direction. But you nailed it with GraphQLID. Thank you! – Ivan Baranov Sep 03 '18 at 17:01
-
I am glad it helped you :) – David Mraz Sep 03 '18 at 17:55