Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active September 10, 2021 10:03
Show Gist options
  • Save percybolmer/309878780d0f6ac8c92ea70d1fac93f7 to your computer and use it in GitHub Desktop.
Save percybolmer/309878780d0f6ac8c92ea70d1fac93f7 to your computer and use it in GitHub Desktop.
graphql
// ResolveJobs is used to find all jobs related to a gopher
func (gs *GopherService) ResolveJobs(p graphql.ResolveParams) (interface{}, error) {
// Fetch Source Value
g, ok := p.Source.(Gopher)
if !ok {
return nil, errors.New("source was not a Gopher")
}
// Here we extract the Argument Company
company := ""
if value, ok := p.Args["company"]; ok {
company, ok = value.(string)
if !ok {
return nil, errors.New("id has to be a string")
}
}
// Find Jobs Based on the Gophers ID
jobs, err := gs.jobs.GetJobs(g.ID, company)
if err != nil {
return nil, err
}
return jobs, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment