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.
overblog_graphql:
definitions:
schema:
# ...
mappings:
types:
-
type: graphql
dir: "%kernel.project_dir%/config/graphql/types"
# config/graphql/types/schema.types.graphql
type Character {
# Name of the character
name: String!
# This character appears in those episodes
appearsIn: [Episode]!
}
# Enumeration of episodes
enum Episode {
NEWHOPE @deprecated
EMPIRE
JEDI
}
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
}
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
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.