How to create a schema for a property of an object that is an array of strings in GraphQL? I want the answer to look like this:
{
name: "colors",
keys: ["red", "blue"]
}
Here is my diagram
var keysType = new graphql.GraphQLObjectType({
name: 'keys',
fields: function() {
key: { type: graphql.GraphQLString }
}
});
var ColorType = new graphql.GraphQLObjectType({
name: 'colors',
fields: function() {
return {
name: { type: graphql.GraphQLString },
keys: { type: new graphql.GraphQLList(keysType)
};
}
});
When I run this request, I get an error message and no data, the error is just [{}]
query {colors {name, keys}}
However, when I run the request to return only the name, I get a successful response.
query {colors {name}}
How to create a schema that returns an array of strings when I request keys?
source
share