Howtographql: GraphQL-Python: mutate() got an unexpected keyword argument 'url'

Created on 9 Nov 2017  路  3Comments  路  Source: howtographql/howtographql

I try follow https://www.howtographql.com/graphql-python/3-mutations/ but got error
"graphql.error.located_error.GraphQLLocatedError: mutate() got an unexpected keyword argument 'url' "

Code like:

...code

1

class CreateLink(graphene.Mutation):
id = graphene.Int()
url = graphene.String()
description = graphene.String()

#2
class Input:
    url = graphene.String()
    description = graphene.String()

#3
@staticmethod
def mutate(root, input, context, info):
    link = Link(
        url=input.get('url'),
        description=input.get('description')
    )
    link.save()

    return CreateLink(
        id=link.id,
        url=link.url,
        description=link.description,
    )

4

class Mutation(graphene.AbstractType):
create_link = CreateLink.Field()

When try run:
mutation{
createLink(
url:"https://github.com/",
description:"XXXXX"
){
id
url
description
}
}

Got error

Most helpful comment

See if you're using the v2 of Graphene... It has a change with the Input class. Try replacing "Input" with "Arguments":

Mutation.Input

Mutation.Input is now deprecated in favor of using Mutation.Arguments (ClientIDMutation still uses Input).

Before:

class User(Mutation):
    class Input:
        name = String()

With 2.0:

class User(Mutation):
    class Arguments:
        name = String()

Also mutate has change:
https://github.com/graphql-python/graphene/blob/master/UPGRADE-v2.0.md

Read the 2.0 update docs and you'll be fine!

All 3 comments

See if you're using the v2 of Graphene... It has a change with the Input class. Try replacing "Input" with "Arguments":

Mutation.Input

Mutation.Input is now deprecated in favor of using Mutation.Arguments (ClientIDMutation still uses Input).

Before:

class User(Mutation):
    class Input:
        name = String()

With 2.0:

class User(Mutation):
    class Arguments:
        name = String()

Also mutate has change:
https://github.com/graphql-python/graphene/blob/master/UPGRADE-v2.0.md

Read the 2.0 update docs and you'll be fine!

The tutorial needs to be updated :( I'll try to look into that ASAP!

The tutorial is updated! This can be closed 馃帀

Was this page helpful?
0 / 5 - 0 ratings