3

I am experiencing an issue with get_node method in a django object type definition. The method doesn't seem to be called in my case.

I even tried debugging with pdb by pausing execution inside the get_node method, didn't work either.

This is a sample of my code

class DocumentGQL(DjangoObjectType):
    class Meta:
        model = Document
        interfaces = (graphene.relay.Node,)

    @classmethod
    def get_node(cls, info, id):
        logger.info(id)
        ...

class Query(graphene.ObjectType):
    document = graphene.relay.Node.Field(DocumentGQL)

And console output "POST /graphql/ HTTP/1.1" 200 26

Graphql Query

{
  document(id:"e551a1e5-6fae-47c2-be87-3feeb802bf7f"){
    description
    id
  }
}

Graphql output

{
  "data": {
    "document": null
  }
}

I believe I followed the docs when doing this. Am I missing something? Kindly assist.

Rodgers Ouma
  • 103
  • 2
  • 13

1 Answers1

0

The problem is with the id you are passing to the query. Somewhere in the docs, is buried this little note:

The id returned by the Ship type when you query it will be a scalar which contains enough info for the server to know its type and its id.

For example, the instance Ship(id=1) will return U2hpcDox as the id when you query it (which is the base64 encoding of Ship:1), and which could be useful later if we want to query a node by its id.

So basically if the id of your document is e551a1e5-6fae-47c2-be87-3feeb802bf7f, then the proper way to do the query is to supply, an id of RG9jdW1lbnQ6ZTU1MWExZTUtNmZhZS00N2MyLWJlODctM2ZlZWI4MDJiZjdm in the query. Of course the above is simply the output of:

printf 'Document:e551a1e5-6fae-47c2-be87-3feeb802bf7f' | base64

I hope that helps. I was just in the same boat as you.

smac89
  • 39,374
  • 15
  • 132
  • 179