I’m trying to created a list of objects using graphql mutation
, but have been unsuccessful. I've identified the error, please see code snippets and comment on where the error is propagating.
Note: I'm using Graphene on Flask with Python 2.7
Here’s an example payload:
mutation UserMutation {
createUser(
phones: [
{
“number”: “609-777-7777”,
“label”: “home"
},
{
“number”: “609-777-7778”,
“label”: “mobile"
}
]
)
}
On the schema, I have the following:
class CreateUser(graphene.Mutation):
ok = graphene.Boolean()
...
phones = graphene.List(graphene.String()) # this is a list of string but what I need is a list of dicts!
In this chapter, we will learn mutation queries in GraphQL. Mutation queries modify data in the data store and returns a value. It can be used to insert, update, or delete data. Mutations are defined as a part of the schema. The syntax of a mutation query is given below −. mutation{ someEditOperation(dataField:"valueOfField"):returnType }
Mutations are defined as a part of the schema. mutation { someEditOperation (dataField:"valueOfField"):returnType } Let us understand how to add new student record into the datastore using a mutation query. Create a project folder by the name mutation-app. Change your directory to mutation-app from the terminal.
Most APIs, including the Microsoft Graph, require authorization before they’ll give you an access token that will allow you to call the API. This is often the most difficult part for someone new to pulling data from APIs (it was for me).
Now, press Ctrl+ Shift + Enter simultaneously to apply this formula. We will get our first extracted data in cells that match the condition Then drag around the fill handle towards the row and column. Thus, the resulting data will be shown which matches the condition.
For having a dict as a Input, you need to use InputObjectType
. (InputObjectType
s are like ObjectTypes but just for input data).
This example should work with graphene 1.0
.
class PhoneInput(graphene.InputObjectType):
number = graphene.String()
label = graphene.String()
class CreateUser(graphene.Mutation):
class Input:
phones = graphene.List(PhoneInput)
ok = graphene.Boolean()
class Mutation(graphene.ObjectType):
create_user = CreateUser.Field()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With