Created
October 29, 2022 17:21
-
-
Save VictorKabata/bf7081ac458244b58687509edd5bb172 to your computer and use it in GitHub Desktop.
This file contains 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
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