I am new to GraphQL. Forgive me if this is obvious.
Beside using buildSchema
, is there a way to define more than one query/mutation using new GraphQLSchema
?
This is what I have right now.
const schema = new graphql.GraphQLSchema(
{
query: new graphql.GraphQLObjectType({
name: 'RootQueryType',
fields: {
count: {
type: graphql.GraphQLInt,
resolve: function () {
return count;
}
}
}
}),
mutation: new graphql.GraphQLObjectType({
name: 'RootMutationType',
fields: {
updateCount: {
type: graphql.GraphQLInt,
description: 'Updates the count',
resolve: function () {
count += 1;
return count;
}
}
}
})
});
Multiple "queries" are actually just multiple fields on one Query type. So just add more fields to that GraphQLObjectType
, like so:
query: new graphql.GraphQLObjectType({
name: 'RootQueryType',
fields: {
count: {
type: graphql.GraphQLInt,
resolve: function () {
return count;
}
},
myNewField: {
type: graphql.String,
resolve: function () {
return 'Hello world!';
}
}
}
}),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With