graphql-python / graphql-python/graphql-core-legacy
Enum default_value serialization issue
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 371
- 派生
- 175
- PR 合并指标
- 30 天内没有已合并 PR
描述
Originally reported in graphene issue #691
Argument default_value serializes enum value instead of name. graphql spec does not support enum values and graphql-js serializes enums to the name not value. graphql-python is not consistent with graphql-js. I attempted to find a workaround by setting the enum value to a string of the name but teh result is a string that includes escaped quotes.
Using the name of the enum doesn't work:
class MyEnum(graphene.Enum):
FOO=0
BAR=1
foobar = graphene.List(FooBar, my_enum=graphene.Argument(MyEnum, default_value=MyEnum.FOO.name))
This results in the defaultValue being "\"FOO\"". This does not follow the graphql spec for enums and breaks with third party introspection. Specifically i'm trying to stitch a graphene remote schema and the invalid defaultValue results in a null returned in the merged schema (using graphql-tools).
Using a string value doesn't work either:
class MyEnum(graphene.Enum):
FOO="FOO"
BAR="BAR"
This also doesn't work with using MyEnum.FOO.value for default_value nor setting it specifically to the static string "FOO".
I tried looking for how default_value gets resolved for enums but haven't been able to track it down. I think if we can just get the string value for default_value to not include the escaped string quotes then my schema stitching will work. I haven't been able to figure out how to define an enum so that this will happen.
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先复现 enum 参数 default_value 的示例,并跟踪默认值在 schema introspection 期间是如何序列化的。将结果与 graphql-js 的行为进行比较;当 enum 默认值以其名称输出、没有转义的字符串引号,并且可以被 graphql-tools 用于 schema stitching 时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- graphql, python
- 领域
- api, backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100