graphql-python / graphql-python/graphene

Self parameter is None in mutate method

Open
#810 27 comments 20 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
8.2k
Forks
818
PR merge metrics
No merged PRs in 30d

Description

I don't know, maybe it's not a bug and problem caused by rx, but i have this mutation

```python
class ExtendedMutation(graphene.Mutation):

ok = graphene.Boolean()
code = graphene.Int()
message = graphene.String()

def mutate(self, *_, **__):
return ExtendedMutation()

class UserLogin(ExtendedMutation):
class Arguments:
access_token = graphene.String()

access_token = graphene.String()

@login_required
def mutate(self, info, access_token):
response = client.login(access_token)
access_token = response.get('data', dict()).get('access_token', None)

return UserLogin(
access_token=access_token,
ok=response.get('ok'),
code=response.get('code'),
message=response.get('message')
)
```

and wrote such decorator
```python

def login_required(mutation):
@wraps(mutation)
def inner(obj, info, **kwargs):
access_token = request.headers.get('access_token', None)

print('obj: {}, info; {}, kwargs: {} '.format(obj, info, kwargs))
if not access_token:
return obj(
ok=False, code=401, message='You must login first'
)
return mutation(obj, info, **kwargs)
return inner
```

I wait for **UserLogin** object in **self** argument of **mutation** method, but it's equal None. Info is equal ResolveObject. When i wraps **mutate** method with `@classmethod` decorator, i got UserLogin login class, `info` is None and appears third position required argument which is actually is `info`.

Any ideas?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.