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

fix: Add loc getter on fragment documents for graphql-tag inter-compatibility #396

Merged
merged 6 commits into from
Sep 19, 2024

Conversation

kitten
Copy link
Member

@kitten kitten commented Sep 19, 2024

Summary

Unfortunately graphql-tag has several quirks, including concatenating all interpolations' source bodies and parsing them all as a whole. While it does so, it blindly uses document.loc without checking whether this property is undefined, despite it being optional.

This leads to an incompatibility since it's purposefully left out in graphql.web. However, during a gradual migration it's conceivable that gql.tada's graphql() fragments will be interpolated into graphql-tag's tag functions.

While this isn't recommended, since it's also possible to "blanket-migrate" from graphql-tag's gql function to graphql() functions from gql.tada, this would likely require codemods, so a partial migration isn't unlikely.

To solve this, we now add a loc getter, which creates a document, similar to how graphql-tag would expect it recursively. It also deduplicates documents to avoid graphql-tag receiving invalid input when a fragment is used multiple times.

Set of changes

  • Add concatLocSources utility
  • Add faux-loc getter on documents for fragment outputs

Copy link

changeset-bot bot commented Sep 19, 2024

🦋 Changeset detected

Latest commit: 8a29714

The changes in this PR will be included in the next version bump.

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

@kitten kitten changed the title fix(gql.tada): Add getter for loc for graphql-tag inter-compatibility fix: Add getter for loc for graphql-tag inter-compatibility Sep 19, 2024
@kitten kitten changed the title fix: Add getter for loc for graphql-tag inter-compatibility fix: Add loc getter on fragment documents for graphql-tag inter-compatibility Sep 19, 2024
@kitten kitten merged commit 971bdd0 into main Sep 19, 2024
2 checks passed
@kitten kitten deleted the @kitten/feat/graphql-tag-compat branch September 19, 2024 13:41
@github-actions github-actions bot mentioned this pull request Sep 19, 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