feat: CATALYST-1664 add graphql proxy in middleware #2825
+183
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.