Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active September 7, 2021 17:45
Show Gist options
  • Save percybolmer/9580f68a05854efb91e66d5d8bcdf935 to your computer and use it in GitHub Desktop.
Save percybolmer/9580f68a05854efb91e66d5d8bcdf935 to your computer and use it in GitHub Desktop.
graphql
// GopherService is the service that holds all repositories
type GopherService struct {
gophers Repository
}
// NewService is a factory that creates a new GopherService
func NewService(repo Repository) GopherService {
return GopherService{
gophers: repo,
}
}
// ResolveGophers will be used to retrieve all available Gophers
func (gs GopherService) ResolveGophers(p graphql.ResolveParams) (interface{}, error) {
// Fetch gophers from the Repository
gophers, err := gs.gophers.GetGophers()
if err != nil {
return nil, err
}
return gophers, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment