Dataloader's documentation
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Documentación
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- graphql, python
- Área
- documentation
Línea de trabajo
Comienza con la documentación de DataLoader enlazada y revisa el ejemplo del resolver de User, incluidos root.best_friend_id, root.friend_ids y User.objects.filter(id__in=keys). Compara esos ejemplos con las funciones auxiliares descritas y aclara qué código es ejecutable y cuál es meramente ilustrativo. Se considera terminado cuando la documentación presenta un caso de uso autocontenido y bien definido, y explica el comportamiento esperado de la función de batch.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
The dataloader documentation is quite unclear in the current state, especially this piece of code:
class User(graphene.ObjectType):
name = graphene.String()
best_friend = graphene.Field(lambda: User)
friends = graphene.List(lambda: User)
def resolve_best_friend(root, info):
return user_loader.load(root.best_friend_id)
def resolve_friends(root, info):
return user_loader.load_many(root.friend_ids)
It's not clear how this could work, because as it's presented here, neither root.best_friend_id nor root.friend_ids would be defined. Wouldn't it make sense to describe a real use case? The current documentation is more or less useless because when you first read it you can't tell what is an approximation and what is not (example of another non-working bit of code User.objects.filter(id__in=keys)). I'm not even sure yet about all this because I know graphene rewrites classes but I don't know all the details since I only used it (and never contributed). So maybe there is to trickery hidden in these statements, but I really feel there are several errors in the provided examples.
Maybe the solution to this is only to add empty objects/resolver (pass) but with well defined types. So everything is clearly defined (but unimplemented).
I've tried to make sense about graphene + aioloader by writing three simple helpers function that create some batch functions:
from collections import defaultdict
from typing import Callable, Dict, List, Optional, Tuple, TypeVar
class OneToOne:
T = TypeVar("T")
K = TypeVar("K", str, int)
Query = Callable[[List[K]], List[T]]
Key = Callable[[T], K]
OneToMany = OneToOne
class ManyToMany:
T = TypeVar("T")
Query = Callable[[List[str]], List[Tuple[T, str]]]
def one_to_one(query: OneToOne.Query, key: OneToOne.Key):
async def batch_function(keys: List[str]) -> List[Optional[OneToOne.T]]:
user_objects = {key(obj): obj for obj in query(keys)}
return [user_objects.get(k) for k in keys]
return batch_function
def one_to_many(query: OneToMany.Query, key: OneToMany.Key):
async def batch_function(keys: List[str]) -> List[List[OneToMany.T]]:
objects = query(keys)
user_objects = defaultdict(list)
for obj in objects:
user_objects[key(obj)].append(obj)
return [user_objects.get(k) or [] for k in keys]
return batch_function
def many_to_many(query: ManyToMany.Query):
async def batch_function(keys: List[str]) -> List[List[ManyToMany.T]]:
obj_key_pairs = query(keys)
user_objects: Dict[str, List[ManyToMany.T]] = defaultdict(list)
for obj, k in obj_key_pairs:
user_objects[k].append(obj)
return [user_objects.get(k) or [] for k in keys]
return batch_function
Describing this kind of functions might even help people understanding what is expected from them. I'm not sure yet these types (or even helper functions) are 100% correct, let me know if you find better solutions.
- Lenguaje dominante
- Python
- Estrellas
- 8.2k
- Forks
- 818
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Aún no hemos revisado los archivos de configuración de este proyecto. Empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de graphql-python/graphene
-
Tutorial mistakesAbierto🐛 bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
graphql-python/graphene#1389 · 5 comentarios · 2 reacciones ·
-
Support OneOf input object typesAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 68/100
graphql-python/graphene#1606 ·
-
Python 3.14 supportAbierto✨ enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 38/100
graphql-python/graphene#1601 · 2 comentarios ·
-
✨ enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
graphql-python/graphene#1600 ·
-
🐛 bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 55/100
graphql-python/graphene#1593 ·
Todos los issues de graphql-python/graphene
Issues similares
-
Broken links found in docsAbiertodocs pydanty:is-working
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
pydantic/pydantic-ai#8863 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
run-llama/llama_index#23278 ·
Los mantenedores suelen responder en 2 días
-
documentation from-review-extraction github-actions priority: low severity:nit
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
LearningCircuit/local-deep-research#6946 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
oracle/langchain-oracle#323 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
tenstorrent/tt-metal#58057 · 1 comentario ·
Los mantenedores suelen responder en 1 día