Skip to content

Instantly share code, notes, and snippets.

@VictorKabata
Created October 29, 2022 17:21
Show Gist options
  • Save VictorKabata/bf7081ac458244b58687509edd5bb172 to your computer and use it in GitHub Desktop.
Save VictorKabata/bf7081ac458244b58687509edd5bb172 to your computer and use it in GitHub Desktop.
fields := graphql.Fields{
"notes": &graphql.Field{
Name: "Get all notes",
Type: graphql.NewList(noteType),
Description: "Get list of all notes",
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
return notes, nil
},
},
"note": &graphql.Field{
Name: "Get note by ID",
Type: noteType,
Description: "Get note by ID",
Args: graphql.FieldConfigArgument{"id": &graphql.ArgumentConfig{Type: graphql.Int}},
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
id, isValid := params.Args["id"].(int)
if isValid {
for _, note := range notes {
if note.ID == id {
return note, nil
}
}
}
return nil, nil
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment