Schema
is a contract/promise between the server
and client
when exchanging data.
Schema
defines a collection of types and the relationships among themeselves.
clients
to see exactly what data is available and then request a specific subset of the data with a single optimized query.type Starship { id: ID! name: String! # length takes argument of unit w/ default valueof METER length(unit: LengthUnit = METER): Float }
There are two types that are special within a schema:
schema { query: Query mutation: Mutation }
Every GraphQL service always have a query
type.
mutation
type.These types are the same as a regular object type, but they are special because they define the entry point
of every GraphQL queries and mutations.
typeDefs
is synonymous with schema
.
schema
definitions written as SDL
(Schema Definition Language
).typeDefs
can be an array of strings
.
schema
definition.Apollo Server will merge all the typeDefs
together when starting the server.
You can define schema
/typeDefs
with a template literal with graphql-tag
.
Apollo server also provides gql
from @apollo/server
.
const gql = require("graphql-tag"); const typeDefs = gql` # Schema definitions go here `; module.exports = typeDefs;