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

batch-execute enhancements #3588

Merged
merged 15 commits into from
Sep 29, 2021
Merged

batch-execute enhancements #3588

merged 15 commits into from
Sep 29, 2021

Conversation

gmac
Copy link
Contributor

@gmac gmac commented Sep 25, 2021

Description

Batch execution is a really good feature. Unfortunately, it's a hidden gem within the mono-repo at the moment with little attention given outside of the built-in schema stitching option. This PR works on changing that by making batch execution friendlier for general use. There are some possible points of contention here, so let's discuss...

  1. BUG FIX: See 44ba4cb. The current implementation has a couple bugs involving fragment definitions:

    1. Fixes the renaming of fragment definitions/spreads to always run when necessary; at present this step only runs in the presence of variable definitions.
    2. Fixes invalid orphaned fragment definitions left behind after the root scope inlines fragments. Involves filtering out any fragments that no longer have an implementing spread.
  2. Within splitResults, errors without a path are now returned to all requests in the batch. This is really important for general usability: right now, batch execution swallows unpathed errors such as schema validations and complexity limits. These errors (particularly schema validations) will rarely be encountered by schema stitching, but are commonplace when batching hand-written queries. The downside of returning all unpathed errors is that all results in the batch will report the same validation error even though it may only apply to one request in the batch, but over-reporting feels better than under-reporting.

  3. I've reduced the graphqlTools0_ prefix down to just _0_... heavily inspired by Bramble. Given that batching rewrites all root scope aliases, we're not really at risk of conflicting with anything, and the graphqlTools prefix divulges too much information about the underlying implementation, IMO. The simpler prefix is more generic and doesn't encourage analytics or instrumentation based on weak signals. It also lends itself to being documented as a generic capability in higher-level product features.

  4. Adds a local test suite for the batch-execute package.

Lastly, I've added a page of documentation about this fantastic package that is both remarkably powerful and quite easy to use. With documentation circulating, we may see some renewed interest in this hidden gem of GraphQL Tools.

Curious of your thoughts here, @yaacovCR.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests and linter rules pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@changeset-bot
Copy link

changeset-bot bot commented Sep 25, 2021

🦋 Changeset detected

Latest commit: 7229033

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

@vercel
Copy link

vercel bot commented Sep 25, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/theguild/graphql-tools/8i7BBqoyptioGuce3ceA68k5PND5
✅ Preview: https://graphql-tools-git-fork-gmac-gmac-batch-execute-theguild.vercel.app

@gmac gmac changed the title ccccccvejllvdffdveindgflnkvgegteibehvchfdbfr batch-execute enhancements Sep 25, 2021
@yaacovCR
Copy link
Collaborator

It all looks great to me. Very important to highlight that batch execution as implemented here is based almost entirely on the amazing work at Gatsby by @vladar see gatsbyjs/gatsby#22347

@gmac
Copy link
Contributor Author

gmac commented Sep 27, 2021

I added that Gatsby PR link into the documentation page to give due credit. Rah rah, open source!

@gmac
Copy link
Contributor Author

gmac commented Sep 27, 2021

Calling this installment ready to go, @ardatan. I'll have a followup to this that fixes some bugs with fragments... those will probably be best reviewed on their own.


if (executionVariableNames.length > 0) {
if (executionVariableNames.length > 0 || hasFragmentDefinitions) {
Copy link
Contributor Author

@gmac gmac Sep 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yaacovCR – have a look at 44ba4cb. I've fixed a couple bugs related to fragments here:

  1. Fragments weren't getting prefixed unless there were also variables.
  2. Inlined root fragments were allowed to leave an invalid orphaned fragment definition. This now filters out fragment definitions unless they have a surviving spread implementation.

@gmac
Copy link
Contributor Author

gmac commented Sep 27, 2021

Thanks for the feedback, gents. Looks tighter now and fixes more bugs.

import { DocumentNode, DefinitionNode, OperationTypeNode, OperationDefinitionNode, Kind } from 'graphql';

export function operationTypeFromDocument(document: DocumentNode): OperationTypeNode {
for (const def of document.definitions) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe getOperationAST from graphql-js. But in case of multiple operations given in the same document, we will need operationName as well.

@ardatan
Copy link
Owner

ardatan commented Sep 29, 2021

Thank you @gmac <3

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.

3 participants