Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active September 9, 2021 12:28
Show Gist options
  • Save percybolmer/6f25a3921fd7cd0018a7316a8a007768 to your computer and use it in GitHub Desktop.
Save percybolmer/6f25a3921fd7cd0018a7316a8a007768 to your computer and use it in GitHub Desktop.
graphql
// genereateGopherType will assemble the Gophertype and all related fields
func generateGopherType(gs *gopher.GopherService) *graphql.Object {
return graphql.NewObject(graphql.ObjectConfig{
Name: "Gopher",
// Fields is the field values to declare the structure of the object
Fields: graphql.Fields{
"id": &graphql.Field{
Type: graphql.ID,
Description: "The ID that is used to identify unique gophers",
},
"name": &graphql.Field{
Type: graphql.String,
Description: "The name of the gopher",
},
"hired": &graphql.Field{
Type: graphql.Boolean,
Description: "True if the Gopher is employeed",
},
"profession": &graphql.Field{
Type: graphql.String,
Description: "The gophers last/current profession",
},
// Here we create a graphql.Field which is depending on the jobs repository, notice how the Gopher struct does not contain any information about jobs
// But this still works
"jobs": generateJobsField(gs),
}})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment