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

feat: Add @graphiql/plugin-batch-request #2994

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

samuelAndalon
Copy link

@samuelAndalon samuelAndalon commented Jan 13, 2023

Description

Hi all, this is Sam from Expedia Group, we recently added graphiql to graphql-kotlin with explorer and exporter plugin, at EG we heavily rely on batched requests from clients to GraphQL servers.

The graphiql@2 plugin API gave us an idea of a plugin that we really need, a way to create batched requests from an IDE, as currently playground, graphiql, insomina, postman offer that capabilty, forcing us to use raw http clients to make some requests for testing.

This PR that adds a batch-request plugin, relies on the editorContext to access to tabs and operations on each tab, then it presents the operations in a file tree format to have user to select which operations are going to be sent in a batch.

Please let us know your feedback and if this is indeed a candidate for a plugin.

Couple of notes:

  1. The plugin scope is for sending multiple graphQL operations with two approaches aliasing and arrays (server requires to be configured for array inputs).
  2. we could consider this PR as a continuation of this opened issue
  3. we use react-checkbox-tree to present tabs and operations.
  4. still need to work on the code-mirror graphql-results mode, as setting the batch response array in response editor causes some parsing issues.

Demo video:

batch-plugin-demo.mov

@changeset-bot
Copy link

changeset-bot bot commented Jan 13, 2023

⚠️ No Changeset found

Latest commit: a3ed4f2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 13, 2023

CLA Missing ID CLA Not Signed

@samuelAndalon samuelAndalon marked this pull request as ready for review January 17, 2023 21:02
@acao
Copy link
Member

acao commented Jan 18, 2023

thanks for this PR! it seems this plugin uses some non-public module sources currently. do you have an NPM version of these packages available?

10:26:42 PM: error An unexpected error occurred: "https://artylab.expedia.biz/api/npm/public-npm-virtual/react-checkbox-tree/-/react-checkbox-tree-1.8.0.tgz: Request failed "403 Forbidden"".

@samuelAndalon
Copy link
Author

Hi @acao yes, sorry! forgot to switch the npm registry, will apply the changes, along with some fixes regarding building the payload for the HTTP request.
Also if needed we could add an option to batch using aliases as an alternative as described here
https://the-guild.dev/graphql/tools/docs/batch-execution

will push registry changes along with other fixes.

@samuelAndalon
Copy link
Author

samuelAndalon commented Jan 26, 2023

@acao i just make the changes, also update the README.md

@samuelAndalon
Copy link
Author

samuelAndalon commented Feb 3, 2023

Hi all, an update here!, just added an option to also batch using aliases, took the batching algorithm from

https://github.com/ardatan/graphql-tools/blob/master/packages/batch-execute/src/mergeRequests.ts

image

@samuelAndalon
Copy link
Author

samuelAndalon commented Feb 15, 2023

Hi everyone, just circling back here, would it still make sense to have this plugin ? we are already using it but publishing it internally. We believe that this is something that could benefit the GraphQL community

@thomasheyenbrock
Copy link
Collaborator

Hey @samuelAndalon 👋 this plugin looks nothing short of awesome 😍 props for putting that together 👏

I do believe that this plugin is meaningful and probably delivers value also for other folks. I'm just not sure if this repo is the right place for it. A main motivator for introducing plugins was to enable folks to build and maintain their own things without us needing to build all feature requests first-class into GraphiQL. We do have some plugins (the explorer and code exporter) which are fairly general purpose and should also give an example of what you can build with the plugin API.

However, I do not think that all plugins should live in this repository. In particular, plugins that are opinionated or that focus on supporting GraphQL features that are not (yet) part of the latest spec version should not be maintained in this repo. This plugin doesn't match with that as batched requests are an extension of GraphQL that is not part of the spec. This is my personal opinion and we haven't aligned on this yet as maintainers, so I encourage other opinions here (cc @acao and @jonathanawesome, we could also discuss that in future working group sessions if desired).

I can definitely encourage you to publish this publicly on your end and share it with the community for now ⭐ that way you can share this with a broader audience until we figured out our strategy on which plugins should be maintained by us and which shouldn't.

@acao
Copy link
Member

acao commented Jul 5, 2023

I think this is awesome!

But I would rather see @graphiql/toolkit createGraphiQLFetcher() introduce a plugin API to support this behavior than to create an alternate query execution mechanism.

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

Successfully merging this pull request may close these issues.

4 participants