Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Root Value example doesn't work

Aperta
#1,303 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
55/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
documentation

Direzione di ricerca

Inizia dalla sezione collegata «Root Value» nella documentazione ed esamina l’esempio completo che la circonda. Rendi coerenti la definizione di User, il nome del campo, il nome del resolver, il campo richiesto e i valori di esempio, in modo che l’esempio sia autonomo ed eseguibile; verifica l’esempio documentato dopo la modifica.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

🐛 bug

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.

Lingua principale
Python
Stelle
8.2k
Fork
818
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di graphql-python/graphene

Tutte le issue di graphql-python/graphene

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.