Input types

As of release 1.1.0, the FaunaDB 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 FaunaDB 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 FaunaDB 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 FaunaDB 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
}

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!