Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active September 9, 2021 05:26
Show Gist options
  • Save percybolmer/550c3a4014f0a584cae84ac037c21351 to your computer and use it in GitHub Desktop.
Save percybolmer/550c3a4014f0a584cae84ac037c21351 to your computer and use it in GitHub Desktop.
Graphql
func main() {
// Create the Gopher Repository
gopherService := gopher.NewService(gopher.NewMemoryRepository())
// We create yet another Fields map, one which holds all the different queries
fields := graphql.Fields{
// We define the Gophers query
"gophers": &graphql.Field{
// It will return a list of GopherTypes, a List is an Slice
// We defined our Type in the Schemas package earlier
Type: graphql.NewList(schemas.GopherType),
// We change the Resolver to use the gopherRepo instead, allowing us to access all Gophers
Resolve: gopherRepo.ResolveGophers,
// Description explains the field
Description: "Query all Gophers",
},
}
........
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment