0no-co / GraphQLSP

TypeScript LSP plugin that finds GraphQL documents in your code and provides diagnostics, auto-complete and hover-information.
https://gql-tada.0no.co
MIT License
332 stars 13 forks source link

Persisted document hashes do not include recursive fragments #329

Closed felamaslen closed 1 month ago

felamaslen commented 1 month ago

Related to #326, which addressed the special case of a document including a fragment which itself did not include any other fragments.

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 does not work when you have a query including a fragment which itself includes another fragment.

Steps to reproduce:

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

export const FragmentADocument = graphql(`
  fragment FragmentA on MyType {
    id
  }
`);

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

import { FragmentADocument } from './FragmentA';

export const FragmentBDocument = graphql(`
  fragment FragmentB on MyType {
    ...FragmentA
  }
`, [FragmentADocument]);

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

import { FragmentBDocument } from './FragmentB';

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

  2. Update FragmentA - 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.