graphql-python / graphql-python/graphql-core-legacy
Enum default_value serialization issue
- Ngôn ngữ chính
- Python
- Star
- 372
- Fork
- 175
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
Originally reported in [graphene issue #691](https://github.com/graphql-python/graphene/issues/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:
```python
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:
```python
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.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Start by reproducing the enum argument default_value examples and tracing how default values are serialized during schema introspection. Compare the result with graphql-js behavior; done means an enum default is emitted as its name without escaped string quotes and can be consumed by graphql-tools schema stitching.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- graphql, python
- Lĩnh vực
- api, backend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 38/100