graphql-core coerce_string used instead of graphene.String
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Empieza rastreando el manejo de escalares a través de graphene/types/schema.py y compara graphene/types/scalars.py con graphql/type/scalars.py. Reproduce el caso HttpUrl usando graphene.test.Client.execute y determina después si la corrección prevista consiste en conservar la coerción de graphene.String o alinearla con graphql-core. Se considera terminado cuando el comportamiento y la coerción esperada están cubiertos por una prueba de regresión.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Note: for support questions, please use stackoverflow. This repository's issues are reserved for feature requests and bug reports.
- What is the current behavior?
Not 100% sure this is a bug, but it seems not quite right.
graphene.String has the following coerce_string method:
https://github.com/graphql-python/graphene/blob/master/graphene/types/scalars.py#L144
This should mean that any value that is resolved via a graphene.String field gets cast to str
In contrast, graphql-core has this coerce_string method:
https://github.com/graphql-python/graphql-core/blob/a2d52df815f81a62649ee637999fc241af1e67a3/src/graphql/type/scalars.py#L176
...note that in graphql-core any value which passes an isinstance(val, str) check will not get cast to str.
I noticed this because I am using pydantic HttpUrl type in my parent object, the value is an HttpUrl instance (which passes an isinstance(val, str) check).
I noticed in my test cases that the HttpUrl value passes untouched through the graphene.test.Client.execute flow.
Looking at the graphene src this was puzzling because it seemed like it should get cast down to a plain string.
Stepping through with ipdb, I could see in complete_value method:
ipdb> pp result
HttpUrl('https://example.com/test-url, scheme='https', host='example.com', tld='com', host_type='domain', path='test-url')
ipdb> return_type
<graphql.type.definition.GraphQLScalarType object at 0x1059876a0>
ipdb> import inspect
ipdb> inspect.getsource(return_type.serialize)
'def coerce_string(value):\n # type: (Any) -> str\n if isinstance(value, string_types):\n return value\n\n if isinstance(value, bool):\n return u"true" if value else u"false"\n\n return text_type(value)\n'
ipdb> inspect.getsourcefile(return_type.serialize)
'/lib/python3.8/site-packages/graphql/type/scalars.py'
...so we have a graphql-core field rather than a graphene one, which explains why the cast to str didn't happen.
I am guessing it may be due to this code:
https://github.com/graphql-python/graphene/blob/f039af2810806ab42521426777b3a0d061b02802/graphene/types/schema.py#L148
Which raises the question... are the methods on graphene.String and friends just dead code?
Or if they're still used in some other circumstance, should they maybe delegate to corresponding graphql-core methods for sake of consistency, rather than having their own subtly different implementation?
If I change my type def to:
import graphene
class HttpUrl(graphene.String):
pass
class MyParent(graphene.ObjectType):
some_url = HttpUrl(required=True)
...then I get the graphene casting behaviour, again I think because we fall thru this check https://github.com/graphql-python/graphene/blob/f039af2810806ab42521426777b3a0d061b02802/graphene/types/schema.py#L148 and don't substitute a graphql-core type.
In the end this behaviour didn't break anything for me, but it's probably possible to imagine a scenario where it would.
- Lenguaje dominante
- Python
- Estrellas
- 8.2k
- Forks
- 818
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
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 mistakes Abierto🐛 bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
graphql-python/graphene#1389 · 5 comentarios · 2 reacciones ·
-
Support OneOf input object types Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 68/100
graphql-python/graphene#1606 ·
-
Python 3.14 support Abierto✨ 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
-
agent-ready documentation needs-triage
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
-
documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
-
Add https://search.jeremyh.xyz/ Abiertoinstance instance add
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
searxng/searx-instances#939 · 1 comentario ·
-
area-deployment area-integrations triage:bot-seen
Dificultad 2/5 Medio día Aptitud para principiantes 86/100