If you’re new to GraphQL, a good starting point is the official Introduction to GraphQL.
Schema
One of the core features of GraphQL is that the API is defined by a schema. The schema describes the types, interfaces, implementations, and attributes, and which operations are available. It’s a great way to see what input and output the API expects. The Queries, Mutations, and Types sections of the API Reference are generated from the Validio schema.Objects and types
Each operation (query, mutation, or subscription) can consist of one or more objects, used to construct the request and the response as you want. An object describes types and their attributes. A type has a name that describes what it is and, optionally, fields and the types of those fields. If a type ends with an exclamation mark (!), the field is required and is always present.
GraphQL
Operations
When you interact with a GraphQL API, you use operations to describe your request: queries, mutations, or subscriptions.- Queries are used to fetch data.
- Mutations are used to create, delete, or update data.
- Subscriptions are used to stream data from the server over a long-lived request, similar to gRPC streams or websockets.
The operations are fields on special root types,
Query and Mutation. These root types describe the entry point of every request.listPersons query accepts an input of type ListPersonsInput, which carries a payload to the server, and the server responds with a list of persons. The list type ends with an exclamation mark, so there is always a list and never null.
GraphQL
Interfaces
An interface describes characteristics of an object that can be shared across multiple types. Interfaces are used when a resource can have multiple variants, just like objects in object-oriented programming. For example, anAnimal interface can describe the attributes shared across animals, while each animal has its own implementation with attributes specific to it.
GraphQL
GraphQL
Fragments
You will sometimes see fragments used in this documentation. Fragments are reusable building blocks that help you build complex queries by inlining the definitions. For more information about fragments, see the GraphQL documentation. In the following example, a fragment onPerson is reused for all fields that return a Person:
GraphQL
Caveats
If you’re new to GraphQL, there are some things that are good to know beyond what it is and how it’s designed, especially if you come from a RESTful background. These are common things that new users run into.Field names must be unique
When you spread specific implementations of an interface (that is, when an operation can return multiple types) and they share a field name, you must use an alias on one of them so that all field names are unique. To create an alias, write a name followed by a colon before the field you’re selecting:GraphQL