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

Persisted document hashes do not include fragments #326

Closed
felamaslen opened this issue Jun 7, 2024 · 1 comment · Fixed by #327
Closed

Persisted document hashes do not include fragments #326

felamaslen opened this issue Jun 7, 2024 · 1 comment · Fixed by #327

Comments

@felamaslen
Copy link
Contributor

When calling graphql.persisted, the hash needs to change whenever the query changes, so that you don't end up with conflicts between your remotely stored persisted operations and what you have defined in the client. This works for the most part, but doesn't seem to include fragments imported into the query.

Steps to reproduce:

  1. Create the following code
// MyComponent.ts
import { graphql } from 'gql.tada';

export const MyFragmentDocument = graphql(`
  fragment MyFragment on MyType {
    id
  }
`);

// MyView.ts
import { graphql } from 'gql.tada';

import { MyFragmentDocument } from './MyComponent';

export const MyQueryDocument = graphql.persisted(
  'sha256:abc123',
  graphql(`
    query MyData {
      myType {
        ...MyFragment
      }
    }
  `, [MyFragmentDocument]),
);
  1. Run the graphqlsp code action on MyView.ts to insert the correct hash

  2. Update the fragment - e.g. change id to myProp

Expected behaviour

There is a new hash suggested by graphqlsp through the code action, since the imported fragment changed, changing the content of the document.

Actual behaviour

There is no new hash suggested by graphqlsp, suggesting that the fragment is not taken into account.

@felamaslen
Copy link
Contributor Author

I'd like to reopen this issue - the PR I merged fixed the inclusion of fragments one level deep, but this still does not work:

const Frag1Document = graphql(`
  fragment Frag1 on MyType {
    ...Frag2
  }
`)
const Frag2Document = graphql(`
  fragment Frag2 on MyType {
    prop
  }
`)
const MyDocument = graphql(`
  query My {
    myType {
      ...Frag1
    }
  }
`);

The hash is of a document including MyDocument and Frag1, but not Frag2.

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 a pull request may close this issue.

1 participant