[英]graphql-compose: require argument that's an input type
Below is an example of a resolver I'm writing that's using graphql-compose to help build up our schema.下面是我正在编写的解析器示例,它使用graphql-compose来帮助构建我们的模式。
const createResolver = schemaComposer.createResolver({
kind: 'mutation',
name: 'SomeNameHere',
type: SomeTypeNameTC,
args: {
inputForm: InputFormITC,
},
resolve: ({ args }) => {
return createInputForm(args.inputForm);
}
});
My question is regarding the args
section of the resolver.我的问题是关于解析器的
args
部分。 How can I require that the inputForm
argument is required in the schema?我如何要求模式中需要
inputForm
参数? If I were to declare an ID to also be passed in, as an example, I could require the ID in the schema by adding an exclamation mark.例如,如果我要声明要传入的 ID,我可以通过添加感叹号在架构中要求 ID。
If, however, I add an (.) to the ITC object I believe that just tells JS to require that argument and not the GraphQL schema.但是,如果我向 ITC object 添加一个 (.),我相信这只是告诉 JS 需要该参数而不是 GraphQL 模式。
args: {
id: 'ID!'
inputForm: InputFormITC!
}
I worked around this by doing something like inputForm: 'InputFormInput!'
我通过执行类似
inputForm: 'InputFormInput!'
来解决这个问题but I'd rather have the actual object to make it easier to jump around in our IDE. Is such a thing possible in graphql-compose?但我宁愿有实际的 object 以便更容易在我们的 IDE 中跳来跳去。在 graphql-compose 中这样的事情可能吗?
The graphql-compose InputTypeComposer shows a "NonNull" getter for input types. graphql-compose InputTypeComposer显示了输入类型的“NonNull”getter。 To require an input type argument to be required the syntax would look like so:
要要求输入类型参数是必需的,语法如下所示:
args: {
inputForm: InputFormITC.NonNull
}
When viewing the schema, the input type will now show an exclamation mark (.) indicating that it's a required argument.查看架构时,输入类型现在将显示一个感叹号 (.),表明它是必需的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.