⬡ GraphQL Beginner

What are interfaces in GraphQL?

Answer

Interfaces define a set of fields that implementing types must include. They are used to express shared structure across multiple types. Definition: interface Node { id: ID! }. Implementation: type User implements Node { id: ID! name: String! } type Post implements Node { id: ID! title: String! }. In queries, you can query interface fields directly and use inline fragments for type-specific fields: query { node(id: "1") { id ... on User { name } ... on Post { title } } }. Resolvers must implement a __resolveType function to determine the concrete type at runtime. A type can implement multiple interfaces: type Article implements Node & Searchable. Interfaces promote reuse and allow generic patterns like the Node interface (Relay global object identification).