Home |
---|
GGql includes three approaches to linking Go code to a GraphQL schema document. In this examples directory each of those approaches are demonstrated. If you are new to GraphQL it would be best to start with the reflection example as it includes a lengthy tutorial style README.md file.
All examples use a common schema for simple musical data.
type Query {
artist(name: String!): Artist
artists: [Artist]
}
type Mutation {
like(artist: String!, song: String!): Song
}
type Artist {
name: String!
songs: [Song]
origin: [String]
}
type Song {
name: String!
artist: Artist
duration: Int
release: Date
likes: Int
}
scalar Date
While this schema is not very complex, it does provide the foundation for extending to more examples with GraphQL Unions, Interfaces, and Fragments.
The features supported by each approach are summarized in the following comparison matrix:
Feature | Reflection | Interface | Root |
---|---|---|---|
Auto resolve (map GraphQL to Go) | ✔️ | ||
GraphQL types as Go interfaces | ✔️ | ||
Non-slice lists or collections | ✔️ | ||
Run time defined type mapping | ✔️ | ||
Field arguments | ✔️ | ✔️ | |
Compile time resolver checking | ✔️ | ||
Supports directive use | ✔️ | ✔️ | |
Fragment condition | ✔️ | ||
GraphQL Union and Interfaces | ✔️ |