我是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;
}
}
}
})
});
Run Code Online (Sandbox Code Playgroud)
stu*_*ilo 10
多个"查询"实际上只是一个Query类型上的多个字段.所以只需添加更多字段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!';
}
}
}
}),
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2655 次 |
最近记录: |