strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

Implement oneOf for input types

Open patrick91 opened this issue 1 year ago • 4 comments

Might be worth implementing this upcoming feature, unions are not allowed in input types and this is a good alternative to that, also should be easy to implement in code 😊

https://stepzen.com/blog/coming-soon-to-graphql-the-oneof-input-object

It's also been implemented in other libraries, for example async GraphQL (a rust library)

From: https://github.com/strawberry-graphql/strawberry/discussions/2420#discussioncomment-4499708

The specs: https://github.com/graphql/graphql-spec/pull/825/files

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

patrick91 avatar Dec 26 '22 23:12 patrick91

Would that be

@strawberry.mutations.oneOf()
def foo(arg1: Optional[str], arg2: Optional[int]):
    ...

or use enums like async-graphql?

nrbnlulu avatar Feb 13 '23 09:02 nrbnlulu

Any progress on that? It seems the PR is open and ready but no one approves it :(

Aponace avatar Jul 03 '23 14:07 Aponace

@Aponace while the PR adds the directive, it doesn't add runtime support for it, we'd need to implement that to make it work 😊

patrick91 avatar Jul 03 '23 15:07 patrick91

@patrick91 I'm interested in implementing this!

It seems like we could take https://github.com/strawberry-graphql/strawberry/pull/2560 to add @oneOf as a schema directive, and maybe we could add a ValidationRule that is added to all schemas? Since this directive would apply on execution, feels more appropriate for a "native" extension or something similar to operation directives.

Seems like the logic is straightforward, just not 100% sure on where the implementation should live.

bradleyoesch avatar Jan 31 '24 13:01 bradleyoesch