GraphQL - Schema (Type)

> (World Wide) Web - (W3|WWW) > Web - (Web Service|Webservice) > GraphQL

1 - About

GraphQl defines a schema (type).

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

Advertising

3 - 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
}

3.1 - 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.