Schema
is a contract/promise between the server
and client
when exchanging data.
Schema
defines a collection of types and the relationships between those types.
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 has a query
type and may or may not have a 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 query.
You can define schema with a template literal with graphql-tag
.
const gql = require("graphql-tag"); const typeDefs = gql` # Schema definitions go here `; module.exports = typeDefs;