作者:大漠孤烟直1314 | 来源:互联网 | 2022-12-13 16:03
我正在为GraphQL模式编写一个变体:
const Schema = new GraphQLSchema({
mutation: new GraphQLObjectType({
name: 'Mutation',
fields: () => ({
person: {
type: GraphQLString,
args: {
name: {type: GraphQLString},
school: {type: GraphQLString},
},
resolve: mutatePerson,
},
}),
}),
});
我想确保mutatePerson
只有同时存在name
和school
参数时,该方法才能起作用。我该如何检查?
1> Daniel Reard..:
该GraphQLNonNull
类型的包装用于指定两个字段和参数非空。对于字段,这意味着查询结果中的字段值不能为null。对于参数,这意味着不能忽略该参数或将其值设置为null。因此,您的代码只需要看起来像这样:
args: {
name: {
type: new GraphQLNonNull(GraphQLString),
},
school: {
type: new GraphQLNonNull(GraphQLString),
},
},