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: reduce code output of client preset #10073

Merged
merged 3 commits into from
Jul 30, 2024

Conversation

n1ru4l
Copy link
Collaborator

@n1ru4l n1ru4l commented Jul 28, 2024

We don't need all these types for the GraphQL schema for client preset. I added an option to omit them within @graphql-codegen/visitor-plugin-common and @graphql-codegen/typescript and enabled this option by default for the client preset.

For GraphQL Hive this reduces the generated code for the client preset by over 50%. Also, see the diff and removed code here from the fixtures/examples. :D

We could even reduce generated enums and scalars to only those used within the provided graphql documents. However, let's keep that for another time.

Copy link

changeset-bot bot commented Jul 28, 2024

🦋 Changeset detected

Latest commit: bdd83b3

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

This PR includes changesets to release 1 package
Name Type
@graphql-codegen/client-preset Minor

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 Jul 28, 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/client-preset 4.4.0-alpha-20240729201742-bdd83b330efab9495a17e7cf0a8226c750fc1772 npm ↗︎ unpkg ↗︎

Copy link
Contributor

github-actions bot commented Jul 28, 2024

💻 Website Preview

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

@n1ru4l n1ru4l force-pushed the feat-slimmer-client-preset-output branch from bd811eb to 0e7e51f Compare July 28, 2024 12:43
@n1ru4l n1ru4l force-pushed the feat-slimmer-client-preset-output branch from bcb1bf8 to e57eefd Compare July 28, 2024 12:49
@n1ru4l n1ru4l requested review from eddeee888 and saihaj July 28, 2024 12:51
@n1ru4l n1ru4l changed the title feat: reduce code output feat: reduce code output of client preset Jul 28, 2024
@n1ru4l n1ru4l requested a review from eddeee888 July 30, 2024 08:58
Copy link
Collaborator

@eddeee888 eddeee888 left a comment

Choose a reason for hiding this comment

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

Nice one!

@n1ru4l n1ru4l merged commit 8471a18 into master Jul 30, 2024
19 checks passed
@n1ru4l n1ru4l deleted the feat-slimmer-client-preset-output branch July 30, 2024 12:15
@saihaj
Copy link
Collaborator

saihaj commented Oct 7, 2024

Released @graphql-codegen/client-preset@4.4.0

@jacquesg
Copy link

jacquesg commented Oct 7, 2024

This is a massive breaking change, upgrading from 4.3.X to 4.4 the default should not have changed.

@jacquesg
Copy link

jacquesg commented Oct 7, 2024

Even undoing the patch locally results in the generated file being broken:

diff --git a/codegen.ts b/codegen.ts
index 28d74543..5fcad7cf 100644
--- a/codegen.ts
+++ b/codegen.ts
@@ -6,7 +6,11 @@ const config: CodegenConfig = {
   generates: {
     './src/api/deianira/generated/': {
       preset: 'client',
-      plugins: [],
+      plugins: [
+        {
+          [`typescript`]: {},
+        },
+      ],
src/api/deianira/generated/graphql.ts:5950:13 - error TS2300: Duplicate identifier 'UpdateZoneInput'.

5950 export type UpdateZoneInput = {
                 ~~~~~~~~~~~~~~~


Found 1148 errors in the same file, starting at: src/api/deianira/generated/graphql.ts:13

@asgeo1
Copy link

asgeo1 commented Oct 8, 2024

Breaking my app also because I was actually using those types! @n1ru4l do you know how we can get the original behaviour back?

I can see onlyEnumTypes: true, onlyOperationTypes:true were added in the PR, but I don't get how we can revert them back to their original values in a graphql-codgen.ts config file.

@piotr-czerwik
Copy link

Same for the app I am working on - we relied on these types.

I've tried adding

onlyEnumTypes: false,
onlyOperationTypes: false,

to the configuration hoping it will 'revert' the current defaults to the previous ones, but it seems not having any effect...

@bmulholland
Copy link
Contributor

Filed as #10167

@nebbles
Copy link

nebbles commented Oct 11, 2024

PR #10155 adds onlyEnumTypes and onlyOperationTypes to the overridable config.

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.

8 participants