Table of Contents

About

This article is about the schema (type) definition of GraphQL.

The implementation graphql/type module is the engine for defining GraphQL types and schema.

Example

The below type is a shorthand notation. The API is more expressive and allows types and fields to be documented. See the getting started schema starWarsSchema.js

enum Episode { NEWHOPE, EMPIRE, JEDI }
interface Character {
  id: String!  // ! means not null
  name: String
  friends: [Character]
  appearsIn: [Episode]
}
  • types implementing ther interface
type Human implements Character {
  id: String
  name: String
  friends: [Character]
  appearsIn: [Episode]
  homePlanet: String
}

type Droid implements Character {
  id: String
  name: String
  friends: [Character]
  appearsIn: [Episode]
  primaryFunction: String
}
  • The Entry point that defines the whole schema (by default, the name is Query)
type Query {
  hero(episode: Episode): Character
  human(id: String!): Human
  droid(id: String!): Droid
}

Built-in

  • String, Boolean - Are built-in scalars that the type system provided.
  • __Schema, __Type, __TypeKind, __Field, __InputValue, __EnumValue, __Directive preceded with a double underscore, indicating that they are part of the introspection system.