@graphcommerce/graphql 10.1.0-canary.32 → 10.1.0-canary.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Change Log
2
2
 
3
+ ## 10.1.0-canary.34
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2646](https://github.com/graphcommerce-org/graphcommerce/pull/2646) [`35707a1`](https://github.com/graphcommerce-org/graphcommerce/commit/35707a1f68a6b8c97de5d22221a7c9229961cd7a) - Add a `terminatingLink` prop to `GraphQLProvider` to override the terminating link at the tail of the Apollo link chain (by default the `HttpLink` to the Mesh backend).
8
+
9
+ Because the terminating link runs after every context-setting link (customer auth token, store, cache-id, header links), this lets you route specific operations to a different transport while still inheriting all request headers. The motivating case is file uploads: `File`/`Blob` variables must be sent as a `multipart/form-data` request (e.g. via `apollo-upload-client`'s `UploadHttpLink`), which the default `HttpLink` cannot serialize. Previously such an upload link had to be prepended via `links`, where it terminated _before_ the auth/header links could run — dropping the customer token from multipart requests, so a logged-in customer's cart mutations were rejected. Supplying the upload-aware split as `terminatingLink` keeps it at the tail, so uploads inherit the token like any other operation. ([@paales](https://github.com/paales))
10
+
11
+ ## 10.1.0-canary.33
12
+
3
13
  ## 10.1.0-canary.32
4
14
 
5
15
  ## 10.1.0-canary.31
@@ -20,7 +20,27 @@ export const globalApolloClient: { current: ApolloClient | null } = {
20
20
  }
21
21
 
22
22
  export type GraphQLProviderProps = AppProps &
23
- Omit<ApolloClientConfigInput, 'storefront'> & { children: React.ReactNode }
23
+ Omit<ApolloClientConfigInput, 'storefront'> & {
24
+ children: React.ReactNode
25
+ /**
26
+ * Overrides the terminating link at the tail of the Apollo link chain (by default the `HttpLink`
27
+ * connection to the Mesh backend). Because it sits *after* every context-setting link (customer
28
+ * auth token, store, cache-id, header links), use it to route specific operations to a different
29
+ * transport while still inheriting all request headers.
30
+ *
31
+ * The motivating case is file uploads: `File`/`Blob` variables must be sent as a
32
+ * `multipart/form-data` request (e.g. via `apollo-upload-client`'s `UploadHttpLink`), which the
33
+ * default `HttpLink` cannot serialize. Providing the upload-aware split here keeps it at the tail
34
+ * of the chain, so uploads still pick up the customer token instead of going out unauthenticated.
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * const terminatingLink = ApolloLink.split(hasUploadFiles, uploadHttpLink, httpLink)
39
+ * <GraphQLProvider {...props} terminatingLink={terminatingLink} />
40
+ * ```
41
+ */
42
+ terminatingLink?: ApolloLink
43
+ }
24
44
 
25
45
  /**
26
46
  * The GraphQLProvider allows us to configure the ApolloClient and provide it to the rest of the
@@ -29,7 +49,7 @@ export type GraphQLProviderProps = AppProps &
29
49
  * Take a look at the props to see possible customization options.
30
50
  */
31
51
  export function GraphQLProvider(props: GraphQLProviderProps) {
32
- const { children, links, migrations, policies, pageProps, router } = props
52
+ const { children, links, migrations, policies, pageProps, router, terminatingLink } = props
33
53
  const state = (pageProps as { apolloState?: unknown }).apolloState
34
54
 
35
55
  const stateRef = useRef(state)
@@ -58,8 +78,10 @@ export function GraphQLProvider(props: GraphQLProviderProps) {
58
78
  const link = ApolloLink.from([
59
79
  ...(typeof window === 'undefined' ? [errorLink, measurePerformanceLink] : []),
60
80
  ...config.current.links,
61
- // The actual Http connection to the Mesh backend.
62
- new HttpLink({ uri: '/api/graphql', credentials: 'same-origin' }),
81
+ // The actual Http connection to the Mesh backend. Overridable via `terminatingLink` so
82
+ // e.g. multipart file uploads can be routed to a different transport while still inheriting
83
+ // every header set by the links above.
84
+ terminatingLink ?? new HttpLink({ uri: '/api/graphql', credentials: 'same-origin' }),
63
85
  ])
64
86
 
65
87
  const cache = createCache()
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/graphql",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "10.1.0-canary.32",
5
+ "version": "10.1.0-canary.34",
6
6
  "sideEffects": false,
7
7
  "main": "index.ts",
8
8
  "prettier": "@graphcommerce/prettier-config-pwa",
@@ -28,12 +28,12 @@
28
28
  "rxjs": "^7.8.2"
29
29
  },
30
30
  "peerDependencies": {
31
- "@graphcommerce/eslint-config-pwa": "^10.1.0-canary.32",
32
- "@graphcommerce/graphql-codegen-near-operation-file": "10.1.0-canary.32",
33
- "@graphcommerce/graphql-codegen-relay-optimizer-plugin": "10.1.0-canary.32",
34
- "@graphcommerce/next-config": "^10.1.0-canary.32",
35
- "@graphcommerce/prettier-config-pwa": "^10.1.0-canary.32",
36
- "@graphcommerce/typescript-config-pwa": "^10.1.0-canary.32",
31
+ "@graphcommerce/eslint-config-pwa": "^10.1.0-canary.34",
32
+ "@graphcommerce/graphql-codegen-near-operation-file": "10.1.0-canary.34",
33
+ "@graphcommerce/graphql-codegen-relay-optimizer-plugin": "10.1.0-canary.34",
34
+ "@graphcommerce/next-config": "^10.1.0-canary.34",
35
+ "@graphcommerce/prettier-config-pwa": "^10.1.0-canary.34",
36
+ "@graphcommerce/typescript-config-pwa": "^10.1.0-canary.34",
37
37
  "@graphql-mesh/plugin-http-details-extensions": "*",
38
38
  "react": "^19.2.0",
39
39
  "react-dom": "^19.2.0"