-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Allow to run multiple operations (for query batching) #1635
Comments
@leoloso since we are the official spec reference implementation, then someone who is advancing this spec is free to open a PR to graphiql, however it won't ship with the official GraphiQL preset until it's official spec! |
actually, i will re-open this to make sure we enable this at a relatively early iteration of plugin scope. this would be a VERY useful feature to help advance, but we are currently focused on proposals at more advanced stages right now. more good news @leoloso - though we can't support this "officially" yet, and there is no plugin API yet, there are props that would allow you to do this, kinda. you'd still get the dropdown, but clicking any operation name would execute all of them if you want, as you can modify how the outbound http request is handled by the i wonder though, without implenting this in |
That's great, thanks @acao. To make it work, I've added a hack to my GraphQL server, where if the I appreciate your suggestion of removing the For instance, this is my GraphiQL working with my hack. You can run I'm eager to see GraphiQL supporting this feature :) |
how is this supposed to be implemented exactly, I can't seem to find an exact payload example in the spec? thats why i suggested removing if it's either sending one |
IMO, it looks like a really useful feature to have, though i imagine graphql-js validation might have issues with fragments with operations like these? for example, when you have |
Well, I actually created this issue as to start exploring for the best solution. I think that sending That's why I thought about a simple |
You're right about this. But I think this is not a new issue, this should be happening right now. What happens if you have 3 operations in your document, and all of them have a fragment, and hit Run selecting one of them for How is this tackled currently? Are they validated? Is there an error? |
ah! i forgot. |
@leoloso to answer your question more clearly, graphql-js allows you to define as many unused fragments as you want when executing an operation, so they are essentially ignored. it is apollo-client that does not allow unused fragments in an operation |
Hence, I believe you've provided an answer to your own concern:
Then, implementing this feature in GraphiQL should not be really a problem, since it doesn't break anything from And the community from Apollo client can adapt their code to make use of this feature (and I guess they will, since they provide query batching). |
@leoloso yes, I'm aware, thank you! |
I will be restructuring the repository here in the next few weeks after finishing up LSP/IDE extension efforts for the latest release, and then you can open a PR! |
Unfortunately I won't be able to open a PR, since JavaScript is not my domain, I'm a PHP developer. I posted this issue because I saw the need as a user of GraphiQL. I hope somebody else can jump in and help. |
for sure! otherwise, I'll be able to get to this in the next month realistically. @danielrearden offhand, is this already possible with |
@acao Nope, |
@leoloso looking into it some more, and though i think this would be a cool feature, i dont see it in the spec: http://spec.graphql.org/draft/#sec-Executing-Requests
|
@acao Yes, you're right. The foundations to work with are not in the spec yet. The spec proposal change is in graphql/graphql-spec#375:
Could a workaround that doesn't break the spec be considered? For instance, have It looks ugly, I admit that. Maybe we can take this conversation to that issue? Maybe it's possible to approve using |
Actually, I can't find in the spec that So then, as a workaround, what do you think of |
@leoloso workarounds would be less desirable. better to implement the intended spec. it looks like someone needs to champion this spec! i would suggest adding it to the agenda for the next working group meeting if you'd like to see it advanced further. ideally, once we have an accepted plugin API RFC, people can provide plugins for earlier stage strawman proposals like these. as a rule of thumb, I tend to implement Stage 3 draft proposals, using an opt-in approach if necessary. if someone can make a PR to enable this via an opt-in prop, and use that prop to render an alternative |
It sounds great, thanks @acao. I'll keep track of the issue for the spec, contribute to the discussion. I won't be able to champion this issue though (I don't have the expertise needed to know it works with |
@acao @leoloso This might make more sense as an addition to the GraphQL over HTTP spec instead. |
@danielrearden agreed, the last comment in the spec proposal said the same thing, however the spec itself does seem to require a single operation name per operation execution. so that part might need to be tweaked. but i think thats more of a discussion for the spec proposal than here. as far as graphiql itself is concerned, I’d be happy to make this an opt-in capability that is disabled by default, though that means we will need to keep up with any modifications to this spec before it’s adopted |
Hey @acao I would like to contribute to this! It would be great if you could brief me about the same. I have read the development and contribution guidelines and have gone through the codebase. |
that would be fantastic! a PR would be welcome. let’s make it an opt-in feature using a top-level GraphiQL, and as i mentioned before in this thread, the prop could then determine which execute button component is rendered, or determine how it’s rendered. the easiest approach would be for it to execute all operations in the editor. if you would like to provide a UX for selecting which operations, then that would be great. the list of chosen operationNames might be good to persist across sessions |
Okay thanks, I will start working on the PR. |
Hey @acao I have submitted the PR. |
Executing multiple queries in a single query is not part of the spec yet, but it has been requested, and several servers already implement it (such as Apollo).
Then, GraphiQL should allow to execute multiple operations against the server. However, when there are multiple operations in the document, the Run button only allows to select either one, but not many of them, or all of them.
Please notice in this screenshot, the 2 operations are expected to be executed together, but that's not possible:
Proposal
Add a configuration option
"runMultipleQueries"
which, whentrue
, if there is more than 1 operation in the document, also adds entry"Execute all"
in the Run button dropdown:The text was updated successfully, but these errors were encountered: