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] Add meta field to typescript-resolvers plugin's output #9961

Merged
merged 6 commits into from May 15, 2024

Conversation

eddeee888
Copy link
Collaborator

@eddeee888 eddeee888 commented May 6, 2024

Description

Currently, we don't know easily what has been generated from the run without parsing through the output's content.

This PR adds a new optional meta to allow plugins to report certain things about the run.

This PR also makes @graphql-codegen/typescript-resolvers report generated resolver type names - after applying namingConvention - to meta. This allows plugins/presets (e.g. Server Preset) that relies on @graphql-codegen/typescript-resolvers plugin to import the generated resolver types without trying to match the namingConvention logic manually.

Type of change

Please delete options that are not relevant.

  • New interal feature

How Has This Been Tested?

  • Unit test

Copy link

changeset-bot bot commented May 6, 2024

🦋 Changeset detected

Latest commit: 861a158

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

This PR includes changesets to release 10 packages
Name Type
@graphql-codegen/plugin-helpers Patch
@graphql-codegen/visitor-plugin-common Minor
@graphql-codegen/typescript-resolvers Minor
@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

Copy link
Contributor

github-actions bot commented May 6, 2024

🚀 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 5.2.0-alpha-20240515093252-861a1585c727fb832ea0d17c816649b7091e7da6 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-document-nodes 4.0.7-alpha-20240515093252-861a1585c727fb832ea0d17c816649b7091e7da6 npm ↗︎ unpkg ↗︎
@graphql-codegen/gql-tag-operations 4.0.7-alpha-20240515093252-861a1585c727fb832ea0d17c816649b7091e7da6 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-operations 4.2.1-alpha-20240515093252-861a1585c727fb832ea0d17c816649b7091e7da6 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-resolvers 4.1.0-alpha-20240515093252-861a1585c727fb832ea0d17c816649b7091e7da6 npm ↗︎ unpkg ↗︎
@graphql-codegen/typed-document-node 5.0.7-alpha-20240515093252-861a1585c727fb832ea0d17c816649b7091e7da6 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript 4.0.7-alpha-20240515093252-861a1585c727fb832ea0d17c816649b7091e7da6 npm ↗︎ unpkg ↗︎
@graphql-codegen/client-preset 4.2.6-alpha-20240515093252-861a1585c727fb832ea0d17c816649b7091e7da6 npm ↗︎ unpkg ↗︎
@graphql-codegen/graphql-modules-preset 4.0.7-alpha-20240515093252-861a1585c727fb832ea0d17c816649b7091e7da6 npm ↗︎ unpkg ↗︎
@graphql-codegen/plugin-helpers 5.0.4-alpha-20240515093252-861a1585c727fb832ea0d17c816649b7091e7da6 npm ↗︎ unpkg ↗︎

Copy link
Contributor

github-actions bot commented May 6, 2024

💻 Website Preview

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

@@ -0,0 +1,6 @@
---
'@graphql-codegen/visitor-plugin-common': patch
Copy link
Owner

Choose a reason for hiding this comment

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

I assume that patch because this is kinda considered an internal API so it will not effect other users?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, internal API is also my thinking here. I'm happy to go either minor or path in this case though 🙂

@eddeee888 eddeee888 changed the title Add meta field to typescript-resolvers plugin's output [typescript-resolvers] Add meta field to typescript-resolvers plugin's output May 8, 2024
Copy link
Collaborator

@saihaj saihaj left a comment

Choose a reason for hiding this comment

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

should we only output these in generated content if we have DEBUG enabled? or maybe just output based on some config file?

To me doesn't make much difference cause I don't commit generated artifacts from codegen to a repo, but those who do it will create a big diff once they upgrade?

@eddeee888
Copy link
Collaborator Author

Hi @saihaj , the intention is that meta will not be printed to any generated files, therefore users won't see any difference in their artifacts.

The main use for these is to report metadata of the run for advanced use cases. For example, server preset needs to know the name of generated types so it can generate its import statements. Here's an example generated file from server preset:

import type { UserResolvers } from './../../types.generated';
export const User: UserResolvers = {
  /* Implement User resolver logic here */
};

If user applies namingConvention to change generated type to snake case though, the above would fail as we need to import user_resolvers instead of UserResolvers. One option is for server preset to implement the same namingConvention logic, which is cumbersome. With the meta field, server preset can just look to see the generated type names to generate the imports line:

import type { user_resolvers } from './../../types.generated'; // Server Preset can look into the `meta` field to know `user_resolvers` is the name of the generated type
export const User: user_resolvers = {
  /* Implement User resolver logic here */
};

Copy link
Collaborator

@n1ru4l n1ru4l left a comment

Choose a reason for hiding this comment

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

Approved, but I would use minor instead of patch as @dotansimha suggested 😇

@eddeee888 eddeee888 merged commit dfc5310 into master May 15, 2024
19 checks passed
@eddeee888 eddeee888 deleted the add-meta-resolver-plugin branch May 15, 2024 09:46
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.

None yet

4 participants