graphql-python / graphql-python/graphene
Root Value example doesn't work
- Lenguaje dominante
- Python
- Estrellas
- 8.2k
- Forks
- 818
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
The [Root Value](https://docs.graphene-python.org/en/latest/execution/execute/#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.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza con la sección enlazada «Root Value» de la documentación e inspecciona el ejemplo completo que la rodea. Haz que la definición de User, el nombre del campo, el nombre del resolver, el campo consultado y los valores de ejemplo sean coherentes para que el ejemplo sea autónomo y ejecutable; verifica el ejemplo documentado después de la edición.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- documentation
- Tipo de issue
- Documentación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 55/100