-
Notifications
You must be signed in to change notification settings - Fork 352
feat: CATALYST-1664 add graphql proxy in middleware #2825
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
base: canary
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: de0d201 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
c6acb4f to
2b416ac
Compare
9e1889f to
e1ce5a8
Compare
e1ce5a8 to
54d7c74
Compare
54d7c74 to
26e8309
Compare
26e8309 to
d4892a8
Compare
d4892a8 to
ed14c99
Compare
ed14c99 to
de0d201
Compare
|
Marking as |
What/Why?
Add GraphQL proxy middleware to enable client-side GraphQL requests through the storefront. This middleware proxies authenticated GraphQL requests from allowed clients (such as checkout-sdk-js) to the BigCommerce Storefront API, automatically handling customer authentication and channel resolution.
Testing
Valid request to the middleware:
Request without valid header:
Request with invalid query (since it's a browser request):
Request with valid query:
Migration
Step 1
Create a new file
core/middlewares/with-graphql-proxy.ts:Step 2
Update
core/middleware.tsto include the new middleware in the composition chain:import { composeMiddlewares } from './middlewares/compose-middlewares'; import { withAnalyticsCookies } from './middlewares/with-analytics-cookies'; import { withAuth } from './middlewares/with-auth'; import { withChannelId } from './middlewares/with-channel-id'; + import { withGraphqlProxy } from './middlewares/with-graphql-proxy'; import { withIntl } from './middlewares/with-intl'; import { withRoutes } from './middlewares/with-routes'; export const middleware = composeMiddlewares( withAuth, withIntl, withAnalyticsCookies, withChannelId, + withGraphqlProxy, withRoutes, );The
withGraphqlProxymiddleware should be placed afterwithChannelId(to access the resolved locale) and beforewithRoutesin the middleware chain.