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: initial support for graphql.persisted #240

Merged
merged 2 commits into from
Apr 5, 2024
Merged

Conversation

JoviDeCroock
Copy link
Member

@JoviDeCroock JoviDeCroock commented Feb 25, 2024

Related to 0no-co/gql.tada#77

This is an initial PR to support graphql.persisted as an LSP target, the goal is to provide semantic diagnostics for:

  • missing type-argument
  • erroneous type-argument (no reference found for instance)
  • missing hash argument

Another goal is to provide a code-action to generate the hash associated with this invocation where we'll check whether there is a missing, or missmatched hash present and then present the user with a prompt to generate a SHA256 for the document we have found through following the TypeArgument.

We could also provide diagnostics for missmatched arguments, i.e. when the hash isn't correct compared to the hash we calculate for the referenced document but because we want to allow for ease I opted out of that.

Risks of the above choice could be that a document evolves but the user forgets to generate a new persisted-hash.

Another choice we could make is to continuously maintain a persisted-operations.json file while development happens so that the user can feed this to their GraphQL server during dev, otherwise we might need to insert the definitions so normal query-texts can be sent during development. This in turn would force our hand in providing some kind of build tool that omits these arguments, an alternative would be to tell folks to do the following

useQuery({
  query: process.env.NODE_ENV === 'development' ? document : persistedHash,
})

The workflow enabled by this addition would be the following

const document = graphql(`
  query Pokemon ($id: String!) {
    pokemon(id: $id) {
      id
      name
    }
  }
`)

const persistedHash = graphql.persisted<
  // facilitates inferring the types for both
  // input and output in GraphQL client invocations
  typeof document
>(
  // User can click the prompt to generate a hash or insert their own
); 

The benefit of using the document as a type-argument is that when the bundle is built the user will have no references to the query-text left. For some GraphQL clients this could pose an issue and force us to add the definitions as the second argument for instance.

Copy link

changeset-bot bot commented Feb 25, 2024

⚠️ No Changeset found

Latest commit: 9a47817

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

@JoviDeCroock JoviDeCroock merged commit 097f83b into main Apr 5, 2024
1 check passed
@JoviDeCroock JoviDeCroock deleted the tada-persisted branch April 5, 2024 11:25
JoviDeCroock added a commit that referenced this pull request Apr 5, 2024
@github-actions github-actions bot mentioned this pull request Apr 5, 2024
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