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

Support documentVariableSuffix when using documentMode: 'external' #674

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

Conversation

abrenneke
Copy link

@abrenneke abrenneke commented Mar 31, 2024

Description

This implements the fix suggested in #141

This is correctly appending Document to the operations externally imported for me, which is fixing all compiler errors.

If there's a better way to support this, I'm open to suggestions, but this is working well for me. Will add tests etc if requested.

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

How Has This Been Tested?

Tested with a yarn patch on personal code.

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

This implements the fix suggested in dotansimha#141

This is correctly appending `Document` to the operations externally imported for me, which is fixing all compiler errors.

If there's a better way to support this, I'm open to suggestions, but this is working well for me.
Copy link

changeset-bot bot commented Mar 31, 2024

⚠️ No Changeset found

Latest commit: 6c8b0db

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -186,7 +186,7 @@ export class ReactApolloVisitor extends ClientSideBaseVisitor<
documentVariableName: string,
): string {
return this.config.documentMode === DocumentMode.external
? `Operations.${node.name?.value ?? ''}`
? `Operations.${node.name?.value ?? ''}${this.config.documentVariableSuffix}`
Copy link

@eddeee888 eddeee888 Jan 7, 2025

Choose a reason for hiding this comment

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

There's a special mode for importDocumentNodeExternallyFrom called near-operation-file that is intended to be used with Webpack GraphQL Loader. This loader allows the operation name from a .graphql file. For example, if we have the following file:

# document.graphql
query starwarCharacters {...}

then we can import and use it like this:

import * Operations from './document.graphql'

useQuery(Operations.starwarCharacters)

node.name?.value in this case is starwarCharacters. This key must match the operation name.


So, I think in this case, adding this.config.documentVariableSuffix here might impact the GraphQL loader use case because it requires documentVariableSuffix=''.

The fix is more likely this:

this.config.documentMode === DocumentMode.external &&
      this.config.importDocumentNodeExternallyFrom === 'near-operation-file'
      ? `Operations.${node.name?.value ?? ''}`
      : `Operations.${documentVariableName}`;

Could you try this change and update the tests please?

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