How to match a resolver to a Node.Field
See original GitHub issueNot sure if the best place for this issue is here or at graphene repo (https://github.com/graphql-python/graphene), but here we go …
I have a Node.Field that I want to match to a resolver in order to apply token authentication/authorization. But it seems the resolver is completely ignored. Here is a code sample:
from graphene_django.types import DjangoObjectType
from graphene_django.filter import DjangoFilterConnectionField
from graphene import ObjectType, Node, String
from core.utils import validate_token
from .models import Paciente
class PacienteType(DjangoObjectType):
class Meta:
model = Paciente
interfaces = (Node, )
filter_fields = ['id', 'nome']
class Query(ObjectType):
paciente = Node.Field(PacienteType, id=String(), token=String())
paciente_all = DjangoFilterConnectionField(PacienteType, token=String())
def resolve_paciente(self, info, id=None, token=None):
usuario_id = validate_token(token)
if usuario_id is None:
return None
try:
return Paciente.objects.get(pk=id)
except:
return None
def resolve_paciente_all(self, info, token=None):
usuario_id = validate_token(token)
if usuario_id is None:
return []
return Paciente.objects.all()
Then I issue the following query
{
paciente(id: "UGFjaWVudGVUeXBlOjE=") {
id
}
}
Which I expected to be blank, since I’m not supplying any auth token, but it does return with one result. Am I missing something here that I have not seem, or this may be a bug?
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Writing query resolvers | Full-Stack Quickstart - Apollo GraphQL
A resolver function returns one of the following: Data of the type required by the resolver's corresponding schema field (string, integer, object, etc.)...
Read more >write field level resolver for a field in user type in graphql
I am trying to generate user id using uuid npm package for the id field in the user type. I am not sure...
Read more >Resolvers | NestJS - A progressive Node.js framework
To create a resolver, we create a class with resolver functions as methods, and annotate the class with the @Resolver() decorator.
Read more >Resolvers - Server-Side GraphQL in Node.js - Frontend Masters
Check out a free preview of the full Server-Side GraphQL in Node.js course: ... Resolvers must return the value type declared for the...
Read more >Tutorial: Lambda resolvers - AWS AppSync
You can use AWS Lambda with AWS AppSync to resolve any GraphQL field. ... The following example shows a Lambda function written in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try this, instead of:
paciente = Node.Field(PacienteType, id=String(), token=String())
do:
paciente = graphene.Field(PacienteType, id=String(), token=String())
or simply:
paciente = graphene.Field(PacienteType)
The documentation is non existent, and examples are very inconsistent, lack descriptions, lack the “why’s”, versions mixed, relay vs non-relay confused, etc. Looks like nobody is really in charge of this project so get ready for trial and error unfortunately.
I wish I knew how this worked, really is like magic to me