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

Add @defer directive support #9196

Merged
merged 59 commits into from
May 2, 2023
Merged

Add @defer directive support #9196

merged 59 commits into from
May 2, 2023

Conversation

beerose
Copy link
Contributor

@beerose beerose commented Mar 17, 2023

An extension PR to #8785. The main difference is that this PR generates a union of initial and deferred types instead of marking deferred types as optional. Reference: #8785 (comment)

Example in Hive: https://github.com/kamilkisiela/graphql-hive/compare/main...beerose:graphql-hive:add-defer?expand=1#diff-0defc8c1055b10af21b6f4dbf38e1ae168ce19de44dedb523676ce9034704782R173

Description

Found some legacy code and added more 🤡

Related #7885

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

Screenshots/Sandbox (if appropriate/relevant):

Adding links to sandbox or providing screenshots can help us understand more about this PR and take action on it as appropriate

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A
  • Test B

Test Environment:

  • OS:
  • @graphql-codegen/...:
  • NodeJS:

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 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...

hwillson and others added 3 commits March 16, 2023 11:38
This commit takes a first pass at introducing `@defer` typescript codegen
support. It follows a similar approach as the `@skip` / `@include`
functionality introduced in #5017.

Related issue: #7885
@changeset-bot
Copy link

changeset-bot bot commented Mar 17, 2023

🦋 Changeset detected

Latest commit: ccdac2a

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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 20, 2023

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-codegen/visitor-plugin-common 3.2.0-alpha-20230501115039-7ad08f56b npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-document-nodes 3.0.5-alpha-20230501115039-7ad08f56b npm ↗︎ unpkg ↗︎
@graphql-codegen/gql-tag-operations 3.0.2-alpha-20230501115039-7ad08f56b npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-operations 3.1.0-alpha-20230501115039-7ad08f56b npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-resolvers 3.3.0-alpha-20230501115039-7ad08f56b npm ↗︎ unpkg ↗︎
@graphql-codegen/typed-document-node 4.1.0-alpha-20230501115039-7ad08f56b npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript 3.1.0-alpha-20230501115039-7ad08f56b npm ↗︎ unpkg ↗︎
@graphql-codegen/client-preset 3.1.0-alpha-20230501115039-7ad08f56b npm ↗︎ unpkg ↗︎
@graphql-codegen/graphql-modules-preset 3.1.4-alpha-20230501115039-7ad08f56b npm ↗︎ unpkg ↗︎
@graphql-codegen/plugin-helpers 4.2.1-alpha-20230501115039-7ad08f56b npm ↗︎ unpkg ↗︎

@github-actions
Copy link
Contributor

github-actions bot commented Mar 20, 2023

💻 Website Preview

The latest changes are available as preview in: https://533e96b2.graphql-code-generator.pages.dev

@beerose beerose force-pushed the defer-support branch 2 times, most recently from 6a733d6 to 3a8577e Compare March 21, 2023 17:33
@beerose beerose changed the title WIP: Defer support Add @defer directive support Mar 21, 2023
@beerose beerose changed the title Add @defer directive support Add @defer directive support Mar 21, 2023
@beerose beerose marked this pull request as ready for review March 21, 2023 18:07
@n1ru4l n1ru4l requested review from n1ru4l and saihaj March 22, 2023 08:03
@beerose beerose requested a review from n1ru4l April 10, 2023 13:29
@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2023

diff --git a/website/algolia-lockfile.json b/website/algolia-lockfile.json
index 0f7eb7c78..c7a013b40 100644
--- a/website/algolia-lockfile.json
+++ b/website/algolia-lockfile.json
@@ -2018,6 +2018,11 @@
                 "title": "Fragment Masking with nested Fragments",
                 "anchor": "fragment-masking-with-nested-fragments"
               },
+              {
+                "children": [],
+                "title": "Fragment Masking with @defer directive",
+                "anchor": "fragment-masking-with-defer-directive"
+              },
               {
                 "children": [],
                 "title": "Fragment Masking and testing",

const fragName = fragDef?.name?.value;

const fields = fragName ? deferredFields[fragName] : [];
return fields.length > 0 && fields.every(field => data && field in data);
Copy link

Choose a reason for hiding this comment

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

While testing the release candidate which includes this PR, I realised that if an user has noUncheckedIndexedAccess turned on in their tsconfig.son, the fields variable might be undefined, hence doing fields.length or fields.every fails and TS complains about it. Not sure how to fix this. Should I open an issue? Also apologies if this is not the place to comment about this.

@beerose

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback! You can open an issue and I'll improve this function to work with noUncheckedIndexedAccess.

Copy link

Choose a reason for hiding this comment

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

Here: #9383. Thanks @beerose! I am happy to help testing this if needed. Cheers!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's a fix: #9385

Copy link

Choose a reason for hiding this comment

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

Here's a fix: #9385

Thanks!!

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.

5 participants