Schemas

Example schema

Schema conventions using a Thing object as an example:

type Query {
    thing (
        id: ID! @doc(description: "Entity ID of the thing.")
    ): Thing! @resolver(class: "\\Resolvers\\Thing") @doc(description: "The thing by its ID.")
}

type Mutation {
    createThing (input: ThingInput!): ThingOutput @resolver(class: "\\Resolvers\\CreateThing") @doc(description:"Create a thing.")
    deleteThing (id: ID!): Boolean @resolver(class: "\\Resolvers\\DeleteThing") @doc(description:"Delete a thing.")
    updateThing (input: ThingInput!): ThingOutput @resolver(class: "\\Resolvers\\UpdateThing") @doc(description:"Update a thing.")
}

type Thing {
    id: Int! @doc(description: "Entity ID of the thing.")
    color: ThingColorEnum @doc(description: "Color of the thing.")
    is_movable: Boolean! @doc(description: "If the thing is movable or not.")
    name: String! @doc(description: "Name of the thing.")
    position: ThingPosition !@doc(description: "Coordinates of the thing.")
    weight: Number! @doc(description: "Weight of the thing in kilograms.")
}

type ThingPosition {
    lat: Number! @doc(description: "Latitude of the thing.")
    lon: Number! @doc(description: "Longitude of the thing.")
}

input ThingInput {
    id: Int! @doc(description: "Entity ID of the thing.")
    color: ThingColorEnum @doc(description: "Color of the thing.")
    is_movable: Boolean! @doc(description: "If the thing is movable or not.")
    name: String! @doc(description: "Name of the thing.")
    position: ThingPosition !@doc(description: "Coordinates of the thing.")
    weight: Number! @doc(description: "Weight of the thing in kilograms.")
}

type ThingOutput {
    thing: Thing!
}

enum ThingColorEnum @doc(description: "Color of the thing.") {
    BLUE
    GREEN
    RED
    YELLOW
}

Naming conventions

Query
Query thing noun
Mutation
Mutation createThing verbNoun
Mutation updateThing verbNoun
Mutation deleteThing verbNoun
Type
Type Thing noun This Type convention defines available response fields in a “thing” Query.
Type ThingNode nounNoun This Type convention defines available response fields for a sub-object of the parent “Thing”. The parent noun is treated as a namespace to avoid collisions.
Type as Input/Output
Type ThingInput adjectiveNoun This Type convention defines the request vars in a “createThing” or “updateThing” mutation.
Type ThingOutput adjectiveNoun This Type convesion defines standard response fields for a Query or Mutation. When this Type pattern is implemented, it’s used in multiple CRUD operations usually.