-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphQL Mesh will now be in read-only mode by default, so only a sing…
…le instance is created globally
- Loading branch information
Showing
12 changed files
with
133 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphcommerce/graphql-mesh': patch | ||
--- | ||
|
||
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 _will_ make the frontend considerably slower. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
extend input GraphCommerceConfig { | ||
""" | ||
The GraphQL Mesh will be loaded once and any modifications to resolvers will be ignored. When developing | ||
new resolvers this should be set to true. | ||
""" | ||
graphqlMeshEditMode: Boolean = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { MeshInstance } from '@graphql-mesh/runtime' | ||
import type { | ||
ServerAdapter, | ||
ServerAdapterBaseObject, | ||
ServerAdapterRequestHandler, | ||
} from '@whatwg-node/server' | ||
import { createBuiltMeshHTTPHandlerBase, getBuiltMeshBase } from '../.mesh' | ||
|
||
type MeshHTTPHandler<TServerContext = Record<string, unknown>> = ServerAdapter< | ||
TServerContext, | ||
ServerAdapterBaseObject<TServerContext, ServerAdapterRequestHandler<TServerContext>> | ||
> | ||
|
||
declare global { | ||
// eslint-disable-next-line vars-on-top, no-var | ||
var buildMesh: Promise<MeshInstance> | undefined | ||
|
||
// eslint-disable-next-line vars-on-top, no-var | ||
var builtMeshHandler: MeshHTTPHandler | undefined | ||
} | ||
|
||
const shouldGlobalThisMeshBeCreated = | ||
process.env.NODE_ENV === 'development' && import.meta.graphCommerce.graphqlMeshEditMode !== true | ||
|
||
/** | ||
* We are creating a global instance of the mesh so it doesn't get recreated on every change. | ||
* Creating the instance is a very long operation and with sufficiently complex schema's it can take | ||
* multiple seconds. During development it can happen multiple times during a single change. | ||
* | ||
* During development this creates a big advantage as we do not recreate the mesh on every reload. | ||
* This makes development a lot faster. | ||
* | ||
* The disadvantage of this is that the mesh and any resolvers custom resolver will not be refreshed | ||
* whenever code changes are made, to enable this set the config value `graphqlMeshEditMode: true` | ||
* in your graphcommerce.config.js or set the env variable `GC_GRAPHQL_MESH_EDIT_MODE=1`. | ||
*/ | ||
export function getBuiltMesh() { | ||
if (shouldGlobalThisMeshBeCreated) { | ||
globalThis.buildMesh ??= getBuiltMeshBase() | ||
return globalThis.buildMesh | ||
} | ||
return getBuiltMeshBase() | ||
} | ||
|
||
/** | ||
* Same as globalThisGetBuiltMesh but for the mesh handler. As the handler uses additional logic so | ||
* we can't re-use globalThisGetBuiltMesh. | ||
*/ | ||
export function createBuiltMeshHTTPHandler(): MeshHTTPHandler { | ||
if (shouldGlobalThisMeshBeCreated) { | ||
globalThis.builtMeshHandler ??= createBuiltMeshHTTPHandlerBase() as MeshHTTPHandler | ||
return globalThis.builtMeshHandler | ||
} | ||
return createBuiltMeshHTTPHandlerBase() as MeshHTTPHandler | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './api/createEnvelop' | ||
export * from './api/apolloLink' | ||
export * from './.mesh' | ||
export * from './api/globalThisMesh' | ||
export * from './utils/traverseSelectionSet' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"exclude": ["**/node_modules", "**/.*/"], | ||
"include": ["**/*.ts", "**/*.tsx"], | ||
"extends": "@graphcommerce/typescript-config-pwa/node.json" | ||
"extends": "@graphcommerce/typescript-config-pwa/nextjs.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters