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

[typescript-resolvers] Fix resolvers union types used in ResolversParentTypes #9206

Merged
merged 7 commits into from
Mar 21, 2023

Conversation

eddeee888
Copy link
Collaborator

@eddeee888 eddeee888 commented Mar 20, 2023

Description

This fixes an unintentional change caused by #9069

Discussion: #9069 (comment)

Previously, objects with mappable fields are converted to Omit format that references its own type group or ResolversTypes or ResolversParentTypes e.g.

export type ResolversTypes = {
  Book: ResolverTypeWrapper<BookMapper>;
  BookPayload: ResolversTypes["BookResult"] | ResolversTypes["StandardError"];
  // Note: `result` on the next line references `ResolversTypes["Book"]`
  BookResult: ResolverTypeWrapper<Omit<BookResult, "result"> & { result?: Maybe<ResolversTypes["Book"]> }>;
  StandardError: ResolverTypeWrapper<StandardError>;
};
export type ResolversParentTypes = {
  Book: BookMapper;
  BookPayload: ResolversParentTypes["BookResult"] | ResolversParentTypes["StandardError"];
  // Note: `result` on the next line references `ResolversParentTypes["Book"]`
  BookResult: Omit<BookResult, "result"> & { result?: Maybe<ResolversParentTypes["Book"]> };
  StandardError: StandardError;
};

In #9069, we extracted resolver union types to its own group:

export type ResolversUnionTypes = {
  // Note: `result` on the next line references `ResolversTypes["Book"]` which is only correct for the `ResolversTypes` case
  BookPayload: (Omit<BookResult, "result"> & { result?: Maybe<ResolversTypes["Book"]> }) | StandardError;
};
export type ResolversTypes = {
  Book: ResolverTypeWrapper<BookMapper>;
  BookPayload: ResolverTypeWrapper<ResolversUnionTypes["BookPayload"]>;
  BookResult: ResolverTypeWrapper<Omit<BookResult, "result"> & { result?: Maybe<ResolversTypes["Book"]> }>;
  StandardError: ResolverTypeWrapper<StandardError>;
};
export type ResolversParentTypes = {
  Book: BookMapper;
  BookPayload: ResolversUnionTypes["BookPayload"];
  BookResult: Omit<BookResult, "result"> & { result?: Maybe<ResolversParentTypes["Book"]> };
  StandardError: StandardError;
};

This change creates an extra ResolversUnionParentTypes that is referenced by ResolversParentTypes to ensure backwards compatibility:

export type ResolversUnionTypes = {
  BookPayload: (Omit<BookResult, "result"> & { result?: Maybe<ResolversParentTypes["Book"]> }) | StandardError;
};
// ... and the reference is changed in ResolversParentTypes:
export type ResolversParentTypes = {
  // ... other fields
  BookPayload: ResolversUnionParentTypes["BookPayload"];
};

Type of change

  • Bug fix (non-breaking change which fixes an issue)

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 Environment:

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

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

@changeset-bot
Copy link

changeset-bot bot commented Mar 20, 2023

🦋 Changeset detected

Latest commit: d886ebf

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

This PR includes changesets to release 9 packages
Name Type
@graphql-codegen/visitor-plugin-common Patch
@graphql-codegen/typescript-resolvers Patch
@graphql-codegen/typescript-document-nodes Patch
@graphql-codegen/gql-tag-operations Patch
@graphql-codegen/typescript-operations Patch
@graphql-codegen/typed-document-node Patch
@graphql-codegen/typescript Patch
@graphql-codegen/graphql-modules-preset Patch
@graphql-codegen/client-preset Patch

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/cli 3.3.0-alpha-20230321083703-d886ebfb7 npm ↗︎ unpkg ↗︎
@graphql-codegen/visitor-plugin-common 3.1.0-alpha-20230321083703-d886ebfb7 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-document-nodes 3.0.3-alpha-20230321083703-d886ebfb7 npm ↗︎ unpkg ↗︎
@graphql-codegen/gql-tag-operations 2.0.3-alpha-20230321083703-d886ebfb7 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-operations 3.0.3-alpha-20230321083703-d886ebfb7 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-resolvers 3.2.0-alpha-20230321083703-d886ebfb7 npm ↗︎ unpkg ↗︎
@graphql-codegen/typed-document-node 3.0.3-alpha-20230321083703-d886ebfb7 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript 3.0.3-alpha-20230321083703-d886ebfb7 npm ↗︎ unpkg ↗︎
@graphql-codegen/client-preset 2.1.2-alpha-20230321083703-d886ebfb7 npm ↗︎ unpkg ↗︎
@graphql-codegen/graphql-modules-preset 3.1.2-alpha-20230321083703-d886ebfb7 npm ↗︎ unpkg ↗︎
@graphql-codegen/plugin-helpers 4.2.0-alpha-20230321083703-d886ebfb7 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://a1145403.graphql-code-generator.pages.dev

Copy link
Collaborator Author

@eddeee888 eddeee888 Mar 21, 2023

Choose a reason for hiding this comment

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

Not sure if I went overboard explaining this bug in this changeset. Happy to cut down if needed. 😀

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, I think this is great!

@n1ru4l n1ru4l merged commit e567901 into master Mar 21, 2023
@n1ru4l n1ru4l deleted the fix-resolvers-union-types branch March 21, 2023 10:30
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.

2 participants