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(preset/client): allow use of enumsAsConst config option #9574

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Stephen2
Copy link

@Stephen2 Stephen2 commented Jul 28, 2023

🚨 IMPORTANT: Please do not create a Pull Request without creating an issue first.

Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of the pull request.

Description

Allows 'enumsAsConst' option to be used with client preset. Extremely simple and safe. Based on requests here: #8562

Related # (issue)

#8562

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Tested on my local project, with a complex GraphQL schema, generating 2 types (masked & unmasked):

graphql.config.ts excerpt:

            generates: {
                'src/gql/': {
                    preset: 'client',
                    plugins: [],
                    config: {
                        // To generate string unions, instead of Enum, so backend <> frontend doesn't need conversion
                        enumsAsConst: true
                    },
                    presetConfig: {
                        fragmentMasking: {
                            unmaskFunctionName: 'getFragmentData'
                        }
                    }
                },

                // Backend server just returns the full shape of objects, and always has to return __typename or Apollo gets lost
                'src/gql/__backend__/': {
                    preset: 'client',
                    plugins: ['typescript-msw'],
                    config: {
                        nonOptionalTypename: true,

                        namingConvention: {
                            typeNames: './backend-gql-naming-fn'
                        },

                        // To generate string unions, instead of Enum, so backend <> frontend doesn't need conversion
                        enumsAsConst: true
                    },
                    presetConfig: {
                        fragmentMasking: false
                    }
                }
            }

Test Environment:

  • OS: MacOS 13.5 (22G74)
  • @graphql-codegen/...:
        "@graphql-codegen/cli": "4.0.1",
        "@graphql-codegen/client-preset": "4.0.1",
        "@graphql-codegen/typescript-msw": "^1.1.6",
  • NodeJS:
❯ node -v && npm -v
v16.20.1
8.19.4

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 Jul 28, 2023

🦋 Changeset detected

Latest commit: 70eb250

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

@Stephen2
Copy link
Author

Stephen2 commented Dec 6, 2023

Force pushed, to keep up to date. Any maintainer willing to engage with this PR? 🙏

@mvestergaard
Copy link
Contributor

@dylan-oleria Can this be merged please? We have functionality dependant on enumsAsConst, so can't use client preset currently.

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

3 participants