简体   繁体   中英

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.

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. How can I require that the inputForm argument is required in the schema? 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.

If, however, I add an (.) to the ITC object I believe that just tells JS to require that argument and not the GraphQL schema.

args: {
  id: 'ID!'
  inputForm: InputFormITC!
}

I worked around this by doing something like 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?

The graphql-compose InputTypeComposer shows a "NonNull" getter for input types. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM