Skip to content

Latest commit

 

History

History
145 lines (113 loc) · 3.52 KB

graphql-schema-language.md

File metadata and controls

145 lines (113 loc) · 3.52 KB

GraphQL schema language

This section we show how to define schema types using GraphQL schema language. If you want to learn more about it, you can see the official documentation or this cheat sheet.

Configuration

overblog_graphql:
    definitions:
        schema:
            # ...
        mappings:
            types:
                -
                    type: graphql
                    dir: "%kernel.project_dir%/config/graphql/types"

Usage

Define Types

GraphQL documentation about types and fields.

# config/graphql/types/schema.types.graphql

type Character {
  # Name of the character
  name: String! 
  # This character appears in those episodes
  appearsIn: [Episode]!
}
Define Enumeration types

GraphQL documentation about Enumerations types.

# Enumeration of episodes
enum Episode {
  NEWHOPE @deprecated
  EMPIRE
  JEDI
}
Define Interfaces

GraphQL documentation about Interfaces.

interface Character {
  id: ID!
  name: String!
  friends: [Character] @deprecated(reason: "This field was deprecated!")
  appearsIn: [Episode]!
}
type Human implements Character {
  id: ID!
  name: String!
  friends: [Character]
  appearsIn: [Episode]!
  starships: [Starship]
  totalCredits: Int
}

type Droid implements Character {
  id: ID!
  name: String!
  friends: [Character]
  appearsIn: [Episode]!
  primaryFunction: String
}
Define queries

GraphQL documentation about Query type.

type RootQuery {
  # Access all characters
  characters: [Character]!
}

Do not forget to configure your schema query type, as described in the schema documentation.

overblog_graphql:
    definitions:
        schema:
            query: RootQuery
Define mutations

GraphQL documentation about Mutation type.

input CreateCharacter {
  name: String!
}

input UpdateCharacter {
  name: String!
}

type RootMutation {
  createCharacter(character: CreateCharacter!): Character!
  updateCharacter(characterId: ID!, character: UpdateCharacter!): Character!
}

Do not forget to configure your schema mutation type, as described in the schema documentation.

overblog_graphql:
    definitions:
        schema:
            mutation: RootMutation

When using this shorthand syntax, you define your field resolvers (and some more configuration) separately from the schema. Since the schema already describes all of the fields, arguments, and result types, the only thing left is a collection of callable that are called to actually execute these fields. This can be done using resolver-map.

Notes:

  • This feature is experimental and could be improve or change in future releases
  • Only type definition is allowed right now using this shorthand syntax
  • The definition of schema root query or/and mutation should still be done in main configuration file.