Last active
September 9, 2021 12:28
-
-
Save percybolmer/6f25a3921fd7cd0018a7316a8a007768 to your computer and use it in GitHub Desktop.
graphql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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