HomeToolsAbout a20k

Input

What is it

Data passed to schema's resolver/field

  • Argument values can be hardcoded or pass via GraphQL input variable
# schema definition type Query { resources: [Resource!]! resource(format: DataFormat!): Resource! }
  • resources field returns array of Resource type data
    • Corresponding resolver does not take an input
  • resource field returns object of Resource type after taking in format argument
    • Resolver consumes the input value and executes function

Difference: input vs no input

For resource field, argument/input allows user to narrow down the data returned.

For resources field, the field is an all-or-nothing return as we can only get back predefined results.

# schema definition field resource(format: DataFormat!): Resource!
  • resource would be the field name
  • format would be the argument name
  • DataFormat would be the argument's data type
    • required by !, makes it non-nullable argument
    • will result in error when other types are passed
  • Resource would be the return data type on the field
    • required by !, makes it non-nullable

Client

# client query query GetResource { resource(format: "jpeg") { id data } }

The argument on the client query and the schema can be named anything.

  • It does not have to match the field name on the schema

For example, when we are passing argument id,

© VincentVanKoh