Skip to content

Instantly share code, notes, and snippets.

@bbuck
Last active March 27, 2017 06:48
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bbuck/74cb8446cdb49bf8ac22 to your computer and use it in GitHub Desktop.
Save bbuck/74cb8446cdb49bf8ac22 to your computer and use it in GitHub Desktop.
mutation _ {
newTodo: createTodo(text: "This is a todo mutation example") {
text
done
}
}
// more code
mutationType := graphql.NewObject(graphql.ObjectConfig{
Name: "TodoMutations",
Fields: graphql.Fields{
"createTodo": &graphql.Field{
Type: todoType,
Args: graphql.FieldConfigArgument{
"text": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.String),
},
},
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
text := params.Args["text"].(string)
todo := data.NewTodo(text)
todo.Save()
return todo, nil
},
},
},
})
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: queryType,
Mutation: mutationType,
})
// more codeL
{
"newTodo": {
"text": "This is a todo mutation example",
"done": false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment