我是GraphQL的新手。如果这是显而易见的,请原谅我。
除了使用buildSchema之外,还有一种使用new GraphQLSchema定义多个查询/突变的方法吗
这就是我现在所拥有的。
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;
}
}
}
})
});发布于 2017-03-07 15:00:11
多个“查询”实际上只是一种查询类型上的多个字段。因此,只需向GraphQLObjectType添加更多字段,如下所示:
query: new graphql.GraphQLObjectType({
name: 'RootQueryType',
fields: {
count: {
type: graphql.GraphQLInt,
resolve: function () {
return count;
}
},
myNewField: {
type: graphql.String,
resolve: function () {
return 'Hello world!';
}
}
}
}),https://stackoverflow.com/questions/42634742
复制相似问题