Support OneOf input object types
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 68/100
Research direction
Start at InputObjectType metadata handling and schema construction, then trace how GraphQLInputObjectType is created from the declared Meta options. Check graphql-core's is_one_of support and verify that the completed integration exposes isOneOf through introspection and enforces exactly one non-null member during input coercion.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
Graphene cannot currently express a GraphQL OneOf input object. This commonly arises when an input accepts one of several typed alternatives: defining every alternative as an optional field neither communicates the exactly-one constraint through the schema nor lets GraphQL enforce it during input coercion.
Related requests for input unions or heterogeneous input types have appeared in #721, #797, and #1228. PR #1342 proposed resolver-level validation for a similar exactly-one constraint, but that does not expose the constraint in the GraphQL type system.
Describe the solution you'd like
Allow an InputObjectType to opt into OneOf semantics through its metadata:
class PetInput(graphene.InputObjectType):
class Meta:
one_of = True
cat = graphene.InputField(CatInput)
dog = graphene.InputField(DogInput)
Graphene would pass this metadata through to graphql-core as GraphQLInputObjectType(is_one_of=True). graphql-core can then expose isOneOf through introspection and enforce OneOf schema and input-coercion rules, including requiring exactly one non-null member value.
Describe alternatives you've considered
Applications can validate optional fields in resolvers or use a custom decorator like the approach proposed in #1342. Those approaches duplicate validation, run later than GraphQL input coercion, and do not make the constraint visible to clients through schema introspection.
Additional context
OneOf input objects are now part of the GraphQL specification, and current graphql-core releases already provide the underlying is_one_of support. Graphene needs a public declaration mechanism and schema-construction integration to expose it.
- Dominant language
- Python
- Stars
- 8.2k
- Forks
- 818
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from graphql-python/graphene
-
Tutorial mistakes Open🐛 bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
graphql-python/graphene#1389 · 5 comments · 2 reactions ·
-
Python 3.14 support Open✨ enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 38/100
graphql-python/graphene#1601 · 2 comments ·
-
✨ enhancement
Difficulty 4/5 3-5 days Newbie friendliness 42/100
graphql-python/graphene#1600 ·
-
🐛 bug
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
graphql-python/graphene#1593 ·
-
🐛 bug
Difficulty 4/5 3-5 days Newbie friendliness 25/100
graphql-python/graphene#1592 ·
All issues in graphql-python/graphene
Similar issues
-
essnmx good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
[Feature] 奇物选择添加优先级 Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
syfoud/Simulated_Scepter#174 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Giskard-AI/giskard-oss#2840 · 1 comment ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Openarea: repo bug perceived difficulty: 2
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
yeti-platform/yeti#1380 ·