Reputation: 1
i am using graphene and getting 'name' is an invalid keyword argument for GuestMutation error what is it related to?
//models.py
class Guest(models.Model):
name = models.CharField(max_length=100)
phone = models.IntegerField()
def __str__(self):
return self.name
//schema.py
class GuestType(DjangoObjectType):
class Meta:
model = Guest
fields = ('id','name','phone')
class GuestMutation (graphene.Mutation):
class Arguments:
name = graphene.String(required=True)
phone = graphene.Int(required=True)
guest = graphene.Field(GuestType)
@classmethod
def mutate(cls, root,info,name,phone):
guest = Guest(name=name, phone=phone)
guest.save()
return GuestMutation(name=name, phone=phone)
class Mutation(graphene.ObjectType):
add_guest = GuestMutation.Field()
error message
Traceback (most recent call last): File "/home/ahmed/Documents/Django/Shalleh/my-project-env/lib/python3.8/site-packages/promise/promise.py", line 489, in _resolve_from_executor executor(resolve, reject) File "/home/ahmed/Documents/Django/Shalleh/my-project-env/lib/python3.8/site-packages/promise/promise.py", line 756, in executor return resolve(f(*args, **kwargs)) File "/home/ahmed/Documents/Django/Shalleh/my-project-env/lib/python3.8/site-packages/graphql/execution/middleware.py", line 75, in make_it_promise return next(*args, **kwargs) File "/home/ahmed/Documents/Django/Shalleh/booking/schema.py", line 66, in mutate return GuestMutation(name=name, phone=phone) File "/home/ahmed/Documents/Django/Shalleh/my-project-env/lib/python3.8/site-packages/graphene/types/objecttype.py", line 169, in init raise TypeError( graphql.error.located_error.GraphQLLocatedError: 'name' is an invalid keyword argument for GuestMutation
Upvotes: 0
Views: 1139
Reputation:
You're returning the wrong information:
class GuestMutation (graphene.Mutation):
# What you accept as input
class Arguments:
name = graphene.String(required=True)
phone = graphene.Int(required=True)
# What you return as output
guest = graphene.Field(GuestType)
So as mentioned, you need to return the guest you created.
Upvotes: 0