Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Root Value example doesn't work #1303

Open
zegelin opened this issue Jan 15, 2021 · 0 comments
Open

Root Value example doesn't work #1303

zegelin opened this issue Jan 15, 2021 · 0 comments
Labels

Comments

@zegelin
Copy link

zegelin commented Jan 15, 2021

The Root Value example in the documentation:

from graphene import ObjectType, Field, Schema

class Query(ObjectType):
    me = Field(User)

    def resolve_user(root, info):
        return {'id': root.id, 'firstName': root.name}

schema = Schema(Query)
user_root = User(id=12, name='bob')
result = schema.execute(
    '''
    query getUser {
        user {
            id
            firstName
            lastName
        }
    }
    ''',
    root=user_root
)
assert result.data['user']['id'] == user_root.id

doesn't work. Throws NameError: name 'User' is not defined.

What's not clear is:

  • Where User is defined -- is it defined somewhere else in the documentation? (hyperlink/inline)
  • The Query field is named me yet the resolver function is named resolve_user.
  • The executed query asks for user (not me).
  • The created User object (assigned to user_root) is constructed to have a name field, yet the query asks for the firstName and lastName fields. Sure, resolve_user returns a dict with id, and firstName, but this adds to the confusion.

Having various combinations of name, firstName and lastName is confusing, especially in an example that doesn't work.

sarathak added a commit to sarathak/graphene that referenced this issue Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant