Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polymorphic input types #619

Open
oojacoboo opened this issue Feb 10, 2020 · 9 comments
Open

Polymorphic input types #619

oojacoboo opened this issue Feb 10, 2020 · 9 comments

Comments

@oojacoboo
Copy link

I'd like to go ahead and present this RFC for implementation, possibly early as it looks to have full support. Or, at the least, I'd like to get the discussion and ideas flowing for implementation in the future.

https://github.com/graphql/graphql-spec/blob/master/rfcs/InputUnion.md

This is particularly of interest in cases where you have an update mutation that has optional relational inputs. In this case, you have to support creating and updating for the relation. It's also the case for one:many relationships, if you wish to update relations within a parent mutation.

There are a number of other use cases that are also important. The above use case is one that we're finding to be very common and a continual frustration point with the API/schema.

@alanpoulain
Copy link
Contributor

alanpoulain commented Apr 21, 2020

This implementation would be very useful for API Platform (related issues: api-platform/core#1964, api-platform/core#3258).
Maybe it would be a way to enforce this long-awaited feature.

@vladar
Copy link
Member

vladar commented Jun 8, 2020

We'll add it but it has to become a part of the spec first and implemented in the reference implementation (graphql-js).

@zimzat
Copy link
Contributor

zimzat commented Nov 11, 2020

It's worth noting that since this issue was created, the RFC has gone on a complete tangent from the original "accepted" solution. Instead of introducing a new directive called @oneOf that's only valid on input objects, they've decided to introduce a new syntax type prefix called tagged that functionally does the same thing (but is not backwards compatible and is unclear what it does just based on the name).

In my projects I've decided to embrace the @oneOf directive, since I can implement it locally without waiting for a library or syntax update, and ignore the concept of tagged since it's not likely to get into the official Spec for possibly another year or two.

@aszenz
Copy link

aszenz commented Jun 8, 2021

The current rfc i could find on this is graphql/graphql-spec#825 which moves back to a directive approach using oneOf instead of a new tagged type.

@Roensby
Copy link

Roensby commented Nov 8, 2022

@zimzat did you make a custom directive of @oneOf that you can share?

@zimzat
Copy link
Contributor

zimzat commented Nov 11, 2022

@Roensby The implementation was limited to the directive declaration and a helper method to validate. I didn't build it into the library as an input validation rule because we only had half a dozen places it was used.

directive @oneOf on INPUT_OBJECT
    private function validateOneOf(array $args): void
    {
        if (count($args) !== 1) {
            throw new RequestError('@oneOf requires only one property to be set');
        }
    }

@justlevine
Copy link

ICYMI this got merged into graphql-js three weeks ago graphql/graphql-js#3513

@spawnia
Copy link
Collaborator

spawnia commented Jul 17, 2023

I am not planning to work on this myself just now, but will happily accept pull requests that implement @oneOf like graphql/graphql-js#3513. Please also incorporate graphql/graphql-js#3937.

@armetiz
Copy link

armetiz commented Jun 27, 2024

Hi there,

Is anyone planed to work on this feature?
If not, could you please provide some tips to help people to contribute?

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants