Implementing Interfaces in Mutations
We can implement interfaces in the mutations itself where the mutations require an input object to be passed in its argument. With the interface as its type, the input object will be expected to have the same types as its interface.
type Mutation {
addUser(input: AddUserInput!): User!
}
input AddUserInput {
name: String!
age: Int!
}
In the above example, addUser mutation accepts an input object that should have interface of AddUserInput. This implies that the input object will have all the fields of the interface.
Interfaces in GraphQL Schema
GraphQL is a powerful open-source query language for APIs. It is known for its flexibility and efficiency in fetching data from server endpoints. Unlike traditional REST APIs, which often have multiple endpoints for different resources, GraphQL typically exposes a single endpoint that allows clients to request exactly the data they need.
Interfaces in GraphQL help create a common set of fields and types that can be reused by other types or Queries. In this article, we will learn about the interfaces in GraphQL Schema.