@graphcommerce/graphql-mesh 9.0.4-canary.6 → 9.0.4-canary.9

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
+ ## 9.0.4-canary.9
4
+
5
+ ## 9.0.4-canary.8
6
+
7
+ ### Patch Changes
8
+
9
+ - [#2480](https://github.com/graphcommerce-org/graphcommerce/pull/2480) [`4075474`](https://github.com/graphcommerce-org/graphcommerce/commit/40754746e3d3a05193525ebf94247ed85b6f111d) - GraphQL Mesh will now be in read-only mode by default, so only a single instance is created globally. This means it doesn't get recreated on each page compilation and fast refresh. Creating the instance is an expensive operation and can take multiple seconds and during development (and this can happen multiple times during a single change). Now only a single instance is created during development. To make sure changes are picked up during development set the config value `graphqlMeshEditMode: true` in your graphcommerce.config.js or set the env variable `GC_GRAPHQL_MESH_EDIT_MODE=1`. This is the same as the old behavior and this _will_ make the frontend considerably slower. ([@paales](https://github.com/paales))
10
+
11
+ ## 9.0.4-canary.7
12
+
3
13
  ## 9.0.4-canary.6
4
14
 
5
15
  ## 9.0.4-canary.5
@@ -0,0 +1,7 @@
1
+ extend input GraphCommerceConfig {
2
+ """
3
+ The GraphQL Mesh will be loaded once and any modifications to resolvers will be ignored. When developing
4
+ new resolvers this should be set to true.
5
+ """
6
+ graphqlMeshEditMode: Boolean = false
7
+ }
@@ -1,13 +1,13 @@
1
1
  import type { NextApiRequest, NextApiResponse } from 'next'
2
- import { createBuiltMeshHTTPHandler } from '../.mesh'
3
-
4
- const handler = createBuiltMeshHTTPHandler()
2
+ import { createBuiltMeshHTTPHandler } from './globalThisMesh'
5
3
 
6
4
  // eslint-disable-next-line @typescript-eslint/require-await
7
5
  export const createServer = async (endpoint: string) => {
8
6
  if (endpoint !== '/api/graphql')
9
7
  throw Error('Moving the GraphQL Endpoint is not supported at the moment')
10
- return (req: NextApiRequest, res: NextApiResponse) => {
8
+
9
+ const handler = createBuiltMeshHTTPHandler()
10
+ return async (req: NextApiRequest, res: NextApiResponse) => {
11
11
  res.setHeader('Access-Control-Allow-Origin', req.headers.origin || '*')
12
12
  const requestedHeaders = req.headers['access-control-request-headers']
13
13
  if (requestedHeaders) {
@@ -20,6 +20,6 @@ export const createServer = async (endpoint: string) => {
20
20
  return
21
21
  }
22
22
 
23
- handler(req, res)
23
+ await handler(req, res)
24
24
  }
25
25
  }
@@ -0,0 +1,55 @@
1
+ import type { MeshInstance } from '@graphql-mesh/runtime'
2
+ import type {
3
+ ServerAdapter,
4
+ ServerAdapterBaseObject,
5
+ ServerAdapterRequestHandler,
6
+ } from '@whatwg-node/server'
7
+ import { createBuiltMeshHTTPHandlerBase, getBuiltMeshBase } from '../.mesh'
8
+
9
+ type MeshHTTPHandler<TServerContext = Record<string, unknown>> = ServerAdapter<
10
+ TServerContext,
11
+ ServerAdapterBaseObject<TServerContext, ServerAdapterRequestHandler<TServerContext>>
12
+ >
13
+
14
+ declare global {
15
+ // eslint-disable-next-line vars-on-top, no-var
16
+ var buildMesh: Promise<MeshInstance> | undefined
17
+
18
+ // eslint-disable-next-line vars-on-top, no-var
19
+ var builtMeshHandler: MeshHTTPHandler | undefined
20
+ }
21
+
22
+ const shouldGlobalThisMeshBeCreated =
23
+ process.env.NODE_ENV === 'development' && import.meta.graphCommerce.graphqlMeshEditMode !== true
24
+
25
+ /**
26
+ * We are creating a global instance of the mesh so it doesn't get recreated on every change.
27
+ * Creating the instance is a very long operation and with sufficiently complex schema's it can take
28
+ * multiple seconds. During development it can happen multiple times during a single change.
29
+ *
30
+ * During development this creates a big advantage as we do not recreate the mesh on every reload.
31
+ * This makes development a lot faster.
32
+ *
33
+ * The disadvantage of this is that the mesh and any resolvers custom resolver will not be refreshed
34
+ * whenever code changes are made, to enable this set the config value `graphqlMeshEditMode: true`
35
+ * in your graphcommerce.config.js or set the env variable `GC_GRAPHQL_MESH_EDIT_MODE=1`.
36
+ */
37
+ export function getBuiltMesh() {
38
+ if (shouldGlobalThisMeshBeCreated) {
39
+ globalThis.buildMesh ??= getBuiltMeshBase()
40
+ return globalThis.buildMesh
41
+ }
42
+ return getBuiltMeshBase()
43
+ }
44
+
45
+ /**
46
+ * Same as globalThisGetBuiltMesh but for the mesh handler. As the handler uses additional logic so
47
+ * we can't re-use globalThisGetBuiltMesh.
48
+ */
49
+ export function createBuiltMeshHTTPHandler(): MeshHTTPHandler {
50
+ if (shouldGlobalThisMeshBeCreated) {
51
+ globalThis.builtMeshHandler ??= createBuiltMeshHTTPHandlerBase() as MeshHTTPHandler
52
+ return globalThis.builtMeshHandler
53
+ }
54
+ return createBuiltMeshHTTPHandlerBase() as MeshHTTPHandler
55
+ }
package/index.ts CHANGED
@@ -1,4 +1,7 @@
1
+ /* eslint-disable import/export */
1
2
  export * from './api/createEnvelop'
2
3
  export * from './api/apolloLink'
3
4
  export * from './.mesh'
5
+ // @ts-expect-error getBuiltMesh and createBuiltMeshHTTPHandler are re-exported here and override the export from .mesh
6
+ export * from './api/globalThisMesh'
4
7
  export * from './utils/traverseSelectionSet'
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/graphql-mesh",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "9.0.4-canary.6",
5
+ "version": "9.0.4-canary.9",
6
6
  "main": "index.ts",
7
7
  "dependencies": {
8
8
  "@whatwg-node/fetch": "^0.10.1",
@@ -14,9 +14,9 @@
14
14
  },
15
15
  "peerDependencies": {
16
16
  "@apollo/client": "*",
17
- "@graphcommerce/eslint-config-pwa": "^9.0.4-canary.6",
18
- "@graphcommerce/prettier-config-pwa": "^9.0.4-canary.6",
19
- "@graphcommerce/typescript-config-pwa": "^9.0.4-canary.6",
17
+ "@graphcommerce/eslint-config-pwa": "^9.0.4-canary.9",
18
+ "@graphcommerce/prettier-config-pwa": "^9.0.4-canary.9",
19
+ "@graphcommerce/typescript-config-pwa": "^9.0.4-canary.9",
20
20
  "@graphql-mesh/runtime": "*",
21
21
  "@graphql-mesh/types": "*"
22
22
  },
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "exclude": ["**/node_modules", "**/.*/"],
3
3
  "include": ["**/*.ts", "**/*.tsx"],
4
- "extends": "@graphcommerce/typescript-config-pwa/node.json"
4
+ "extends": "@graphcommerce/typescript-config-pwa/nextjs.json"
5
5
  }