⬡ GraphQL Beginner

What are input types in GraphQL?

Answer

Input types are special object types used exclusively as arguments for mutations (and queries). They cannot be used as output types. They are defined with the input keyword: input CreatePostInput { title: String! content: String! authorId: ID! tags: [String!] }. Usage: type Mutation { createPost(input: CreatePostInput!): Post! }. Calling it: mutation { createPost(input: { title: "Hello", content: "World", authorId: "1" }) { id } }. Input types help organize complex argument lists into a single object, making the API cleaner. They can be nested: an input type can have fields of other input types. Unlike object types, input types cannot have fields that resolve to interfaces, unions, or regular object types.