HomeToolsAbout

Schema

What is it

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.

  • Unified schema in GraphQL allows 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.

Template Literal

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;
AboutContact