question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Retrieve authenticated user without supplying ID! when using relay

See original GitHub issue

Hi there! Thanks for the awesome library. I’m having a little problem I cant seem to find any documentation for. With a simple schema like this, I can ensure return the details for the authenticated user:

from django.contrib.auth import models
class UserType(DjangoObjectType):
    class Meta:
         model = models.User

class Query(ObjectType):
    user = graphene.Field(UserType)

    def resolve_user(self, args, context, info):
       if context.user.is_authenticated:
          return context.user

schema = graphene.Schema(query=Query)

So I can do a query like:

query {
  user {
    firstName
    lastName
    email
  }
}

and it returns the details for the currently-logged in user (i.e. me).

Now I’d like to set it up for use with relay, so I do this:

from django.contrib.auth import models
class UserNode(DjangoObjectType):
    class Meta:
         model = models.User
         interfaces = (relay.Node, )

class Query(AbstractType):
    user = relay.Node.Field(UserNode)

    def resolve_user(self, args, context, info):
       if context.user.is_authenticated:
          return context.user

Now when I run the same query, I get

 `"Field \"user\" argument \"id\" of type \"ID!\" is required but not provided.",`

Is there any way to avoid having to supply relay ID? Am I right in thinking overriding get_node will not help much, since id is a required argument?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
louisdvscommented, Jul 25, 2018

Thanks @BossGrand, This tripped me up for a while trying to access and filter django object id’s using relay.

It would be great if the documentation was updated to show using Relay with DjangoFilterConnectionField(Node) for returning (and paginating) a set of results and then graphene.Field(Node) for accessing a single result with access to the underlying database model id.

1reaction
BossGrandcommented, Apr 12, 2017

@JamesRamm

class Query(AbstractType):
    user = relay.Node.Field(UserNode)

should be

import graphene
class Query(AbstractType):
    user = graphene.Field(UserNode)

In general when defining graphene types, you will use graphene.field

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authentication with GraphQL, React & Relay Tutorial
In this section, you'll learn how you can implement authentication functionality with Relay and Graphcool to provide a login to the user.
Read more >
Getting Started with Relay - Auth0
Learn how to get started with a Relay app and how to protect the GraphQL endpoint with JWT authentication.
Read more >
Authentication and Access Control with Relay - Stack Overflow
If anyone has problems with this topic: I made an example repo for Relay/GraphQL/express authentication based on dimadima's answer.
Read more >
PetitPotam – NTLM Relay to AD CS - Penetration Testing Lab
It could be executed by supplying standard user credentials and using the IP of the system which NTLM Relay is configured and the...
Read more >
Detecting NTLM Relay Attacks with CrowdStrike Identity ...
Because an authenticated user can still trigger an NTLM authentication from the domain controller, the NTLM relay attack vector remains relevant ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found