-
Notifications
You must be signed in to change notification settings - Fork 2k
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
RFC: inputUnion type #1196
RFC: inputUnion type #1196
Conversation
Great work 👍 |
@tgriesser You did a great job with this PR 👍 |
@IvanGoncharov thanks! Thanks for pointing those out. I complete agree, I will work on a formal PR against the spec to go with this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Ran into this issue before and truly happy to see this.
What's about this PR? :) |
We need this too, please merge :-). |
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
any news about this PR? |
@lblazecki It was discussed on the last working group: |
Can you please be more detailed about this? |
@raderio see ongoing discussion in graphql/graphql-spec#395 |
@tgriesser let me know if theres any way we can help as the spec discussion rounds out. |
I've been working on getting this working in Then I can wire up I think our only possible option for an experimental shipment of The npm/yarn ecosystem doesn't handle using git branches for package management well, so there's not really a way we can get a standalone working branch of graphiql with In fact, I made this diagram to help myself get some tests running. Feature completion for the official underlying graphql ecosystem will necessitate PRs to all of these repositories, and requisite updates by downstream consumers of So, P.S. I have some ideas and have done some experiments... I'm sure this has been discussed for a while... but imagine a world where a new language feature could be executed in one PR to the spec, and one reference PR to the entire ecosystem... with one type system... (this is a discussion for elsewhere, possibly an issue on the gls issue queue? or |
As for this PR, GraphQL Asia in BengalaruSo - if folks would like to see this working in Hoping I can write a script tomorrow to re-create this whole stack, requisite manual linking and all, so folks can run the prototype locally at GraphQL Asia? is just a What's nextJust getting the last of the validation working in About to wire up I'll just push my forked branches of each of the repos without opening PRs just yet, and the script will clone from my forks of:
|
Here's the working branches so far for
|
Welp, once I got everything wired up just right, your excellent PR @tgriesser had everything ready to go! (this is from the basic All the validation cases worked fine manually, where Only issue left is that for some reason the introspection result has no |
fyi, as of a couple months ago, @tgriesser's PR already worked standalone for schema execution from it seems that possible in I've been working on some additional tests for this PR that are helping me to get to the bottom of this! |
ok mostly got it! just a few more tweaks to this branch and the introspection query works. the above issue turned out to be just a missing condition for |
Almost done merging in the upstream |
@acao Is this the fork that was demo'd yesterday? |
@asprouse yes I demoed with this, alongside the This branch should be sufficient on its own for a server implementation with, say, If you'd like to be able to render the schema for a GUI client, you can use it alongside the Possibly this week I will roll a pre-packaged demo of |
https://github.com/acao/apollo-graphql-input-union-example here's a quick demo! |
@acao Checking this out now! |
As promised, here's a general utility script I created tonight that handles building all the linkages for you, if anyone wants to iterate on another fork of their own for the various proposals for https://www.npmjs.com/package/yarn-compose the readme demonstrates a config for re-creating the setup I described above, using the same branches that are linked from above in this PR. this way, you can switch out for other forks more quickly. |
I'm curious, a year and a half later, if there's still motivation to get this merged? This solves a very real need for us, and I know a great many other users have been very vocal about the lack of input unions. This seems like it would offer an obvious win. Could we get a little context as to why this is hanging around so long without getting merged? Thanks! |
@leebenson |
Understood, I realise this is tracking the spec. To be clear, I was querying the state of input unions in their entirety, with this PR representing (to my mind) the fullest concrete implementation. I've followed the numerous disparate threads on the topic, and conversation for the most part seems to have stalled (with the notable exception of https://github.com/graphql/graphql-spec/blob/master/rfcs/InputUnion.md 4 days ago-- which is encouraging!). I'm curious what the bottleneck is. |
@leebenson There are number of alternative proposals with its pros and cons. In the long run, we can't based language design on what PRs are ready to merge we should need to evaluate all alternative proposals. |
Fair point, understood, thanks. I guess I'm mostly just curious why it's taken 1.5+ years and what the current state is after all this time. And more importantly, if there's anything non-core contributors can be doing to help speed this up in some way. |
@leebenson Community can help by providing well-defined use cases for this feature: |
i haven’t had time to prepare an example, with GraphQL LSP work and all, however I had what i think would be a great idea for an example. imagine a mutation field that expects a GeoJSON feature collection as an argument, which would necessitate polymorphism to accept the various types of GeoJSON features, each with their own input object definition. Real world use case would be, say a tool where you can draw geojson features, or a remote data collection tool using GPS with an option to bulk upload/sync findings once the user has access to the network. the other fun aspect is an a freeform property inside each feature i think called properties |
@acao Thanks for idea 👍 One important note is that use cases preferably should be extracted from real-life I think we already have a lot of them in different issues across |
Many of the examples I've seen are from real-life. Certainly for us, the use-case isn't speculative. Even those that are, are analogous to real-life scenarios. I don't think an organization should necessarily spend time/money/resources on coding up to the point of discovering this obvious flaw before it's taken seriously. The attributes that render this limiting are the same regardless! The lack of concrete details in our case, is just because our particular business domain doesn't yet allow for public sharing specific blocks of code, so it's easier to talk in broad strokes. The interim TL;DR is that having input types match the flexibility of output types makes for a more balanced API for our users. This is true of a great many domains, since we're only talking about parity between inputs and outputs. Is there a particular reason why Facebook has elected in its design to demote inputs to second class types? In short (and nothing that hasn't already been discussed by others offering more concrete examples, so this isn't anything new): Instead of:
(which is verbose and results in a ton of repeated resolver code) Or:
(which is unsafe, since there's no way to mark the resolver as requiring exactly one input, which means deferring to brittle validation logic) We can just have:
(which is type safe even before hitting validation logic) Again, I'm a little surprised a year and a half later, there's still a request for comments, when the comments appear to be perfectly exhaustive and already cover a great number of obvious scenarios with no useful workarounds except to write tedious blocks of extra resolver code. Isn't it obvious that the lack of input unions causes verbosity, repeated code and demotes inputs as second-class versus outputs? What more does Facebook expect to see to promote this as a serious spec consideration? Who, how and when will such use-cases be tabled for discussion and a roadmap be given to either promote them to the spec or reject, so users like us that have gone all-in on GraphQL, don't spend another couple of years working around something that may trivially be implemented or not? Genuine questions -- seems to have dragged on for ages for no good reason and I'm not quite sure what's left to discuss or what kind of use-cases we're realistically hoping to see that haven't already been covered? |
@leebenson Idea behind this comment was that we shouldn't invent new examples and it's better to use ones that already reported in the graphql-spec repo. By real-life, I mean that developer/company NEEDS this feature for a particular case and is willing to formulate that. For example, your comment is a perfectly fine example of why you don't want to create a bunch of separate mutations.
There is so much separate discussion on GitHub so it's hard to keep track of it this is the exact idea behind RFC document to have everything in one place. On GraphQL WG we discussed this proposal and alternative proposals multiple times (~4-5 in last 2 years) and everyone agrees that it should be addressed, but there was no consensus on what should be added into spec. So the only reasonable approach is to start working formal RFC document and as I noted before the next step is to extract all reported use cases from GitHub issues: https://github.com/graphql/graphql-spec/blob/master/rfcs/InputUnion.md#use-cases |
Closing since since WG reached consensus on "one of" proposal as a way forward, see graphql/graphql-spec#825 |
A proposal in response to #207 and based on my comment on this issue.
Motivation:
Currently,
input
types are restricted to a single definition / type signature. When you wish to allow for variable mutation inputs for a single type you'll normally end up down one of two paths.This proposal aims to offer a third option,
inputUnion
With the current specification it isn't practical to repurpose
GraphQLUnionType
for inputs, as these deal withtype
rather thaninput
. Therefore, this PR proposes a new type,inputUnion
.From @leebyron in #207:
This PR attempts to allow the flexibility of input signatures, while also eliminating ambiguity by requiring that the
input
type is specified when fulfilling theinputUnion
via__inputname
.Details
inputUnion
type mirrors theunion
type, it is restricted to members being otherinput
types.inputUnion
are also valid as fields on aninput
type.inputUnion
is fulfilled, it must be fulfilled by a single member of theinputUnion
, as specified by the__inputname
arg.Benefits
input
types into complex type signaturesDrawbacks
__inputname
is a bit ugly, but it eliminates ambiguity.Unresolved questions:
__inputname
a valid option based on spec (__
is reserved for introspection, not sure if we can mirror this for execution)__inputname
make sense as the name for this?Should the(checked and this isn't permitted in a normalinputUnion
only allow for union ofinput
(as it is in this PR) or should we allow forscalar
/enum
?union
so it makes sense it wouldn't be supported here)