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: use 'within-url-limit' for APQ requests #379

Merged
merged 2 commits into from
Apr 27, 2023

Conversation

NWRichmond
Copy link
Contributor

@NWRichmond NWRichmond commented Apr 27, 2023

Why are these changes introduced?

Addresses ENG-9515

APQ requests break when the URL exceeds 2048 characters

As described in urql-graphql/urql#3185, @urql/exchange-persisted currently sets urql's preferGetMethod setting to 'force'. This was causing problems with an especially large query in reference-stores/next/pages/collections/[handle].js.

This issue is demonstrated with @nacelle/storefront-sdk@/2.0.0-beta.10 in https://codesandbox.io/s/nacelle-storefront-sdk-2-0-0-demo-failure-to-fetch-with-prefergetmethod-force-2u9kjm.

What is this pull request doing?

This PR patches @urql/exchange-persisted using patch-package. The patch changes the preferGetMethod setting from 'force' to 'within-url-limit' when @urql/exchange-persisted's preferGetForPersistedQueries setting is set to true.

How to Test

  1. Check out the ENG-9515/patch-urql-exchange-persisted branch
  2. npm run bootstrap from the monorepo root
  3. Navigate to packages/storefront-sdk
  4. npm run build - the package should build without issues
  5. npm run coverage - all tests should pass with 100% coverage
  6. Navigate to reference-stores/next
  7. npm run build - the project should build without errors

I tested this change by publishing @nacelle/storefront-sdk@2.0.0-hotfix.0 with the v2-hotfix tag, and using it in a forked version of the bug demo Code Sandbox from above. As show in https://codesandbox.io/s/nacelle-storefront-sdk-2-0-0-demo-prefergetmethod-within-url-limits-hb0zkm?file=/src/index.ts, the request succeeds. Interestingly, it succeeds with a GET, without converting the request to a POST. I'm not yet sure why this works, but it's a good result nonetheless.

Checklist

  • This Pull Request aligns with nacelle-js' Code of Conduct.
  • You can follow your own "How to Test" instructions and get the expected result.

@NWRichmond NWRichmond requested a review from KrisQ April 27, 2023 13:53
@changeset-bot
Copy link

changeset-bot bot commented Apr 27, 2023

🦋 Changeset detected

Latest commit: 0fff540

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

@vercel
Copy link

vercel bot commented Apr 27, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nacelle-gatsby-reference-store ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 27, 2023 1:55pm
nacelle-gatsby-starter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 27, 2023 1:55pm
nacelle-next-reference-store ❌ Failed (Inspect) Apr 27, 2023 1:55pm
nacelle-next-starter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 27, 2023 1:55pm
nacelle-nuxt-reference-store ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 27, 2023 1:55pm
nacelle-nuxt-starter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 27, 2023 1:55pm

Copy link
Contributor

@KrisQ KrisQ left a comment

Choose a reason for hiding this comment

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

  • SDK builds
  • Next reference store builds
  • Requests use GET as expected
  • All tests are passing

@NWRichmond NWRichmond merged commit 74bbbaf into main Apr 27, 2023
@NWRichmond NWRichmond deleted the ENG-9515/patch-urql-exchange-persisted branch April 27, 2023 14:46
@NWRichmond NWRichmond changed the title fix: use POSTs when URL too long for GETs fix: use 'within-url-limit' for APQ requests Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants