Describe available data
Define an API contract
GraphQL · Const
A GraphQL schema defines the types and capabilities available from a service. GraphQL validates incoming operations against this contract before executing them, so clients can request supported data predictably.
A GraphQL schema is the contract describing the types, fields, arguments, and directives available through a service. Incoming operations are validated against that contract and then executed, allowing clients to request only supported fields and receive predictable results.
schema { query: Query }query ProductName($id: ID!) {
product(id: $id) {
name
}
}A client sends a query whose fields are checked against the service schema before execution.
Define an API contract
Validate client operations
Generate API reference material
Enable client discovery
A schema is the collection of capabilities exposed by a GraphQL service. It defines the available types and the relationships between them, and requests are validated and executed against it.
Follow-up: How can clients discover the contract? They can use GraphQL introspection, including the __schema and __type meta-fields, when the service exposes introspection.
Object types represent fetchable kinds of objects, and their fields describe the data that can be selected. Fields can also declare arguments and return types, forming the structure clients query.
Follow-up: What other named type categories exist? The documentation identifies Scalar, Enum, Interface, Union, and Input Object types in addition to Object types.
The schema is used during request processing: an incoming operation is checked against the defined types and fields, then executed only if it conforms to that contract. This lets clients make predictable selections.
Follow-up: What role do directives play? They annotate schema elements so validation or execution can treat those elements differently.
Object typesScalar typesEnum typesInterface typesUnion typesInput Object typesDirectivesIntrospection