GraphQL Input types

As of release 1.1.0, the Fauna GraphQL API supports user-defined input types. For example:

input ActiveUserInput {
  username: String!
  timestamp: Time!
}

Input types are used to convey complex arguments to queries or field resolvers, or simply to establish a common name for frequently used arguments.

Naming considerations

The Fauna GraphQL API automatically creates input types for user-defined types. For example, when you create a User type:

type User {
  username: String!
}

the input type UserInput is automatically created for you:

input UserInput {
  username: String!
}

The Fauna GraphQL API also automatically creates the mutations createUser and updateUser, both of this use the auto-created UserInput input type.

Typically, you would not need to create input types yourself. If you define your own UserInput type, which does not include the username field, that could prevent the createUser and updateUser mutations from working correctly.

However, if you define a query or mutation that is connected to a user-defined Fauna function, using the @resolver directive, your function might require a custom input type to pass all of the required data. In this case, a best practice is to name your custom input type using the function name. For example:

input ActiveUserInput {
  username: String!
  timestamp: Time!
}

type Query {
  active(user: ActiveUserInput!): Boolean! @resolver
}

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!