@graphcommerce/graphql 3.0.5 → 3.1.0

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,40 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1399](https://github.com/graphcommerce-org/graphcommerce/pull/1399) [`fb277d8e1`](https://github.com/graphcommerce-org/graphcommerce/commit/fb277d8e1e3612c5e9cf890a30d19cfd1ff70542) Thanks [@paales](https://github.com/paales)! - Now using [@graphql-yoga](https://github.com/dotansimha/graphql-yoga) for GraphQL which has full support for [envelop](https://www.envelop.dev/) plugins.
8
+
9
+ * [#1399](https://github.com/graphcommerce-org/graphcommerce/pull/1399) [`fb277d8e1`](https://github.com/graphcommerce-org/graphcommerce/commit/fb277d8e1e3612c5e9cf890a30d19cfd1ff70542) Thanks [@paales](https://github.com/paales)! - Added a new @graphcommerce/cli package to generate the mesh so it can be generated _inside_ the @graphcommerce/graphql-mesh package to allow for better future extensibility.
10
+
11
+ ### Patch Changes
12
+
13
+ - [#1399](https://github.com/graphcommerce-org/graphcommerce/pull/1399) [`da0ae7d02`](https://github.com/graphcommerce-org/graphcommerce/commit/da0ae7d0236e4908ba0bf0fa16656be516e841d4) Thanks [@paales](https://github.com/paales)! - Updated dependencies
14
+
15
+ - Updated dependencies [[`da0ae7d02`](https://github.com/graphcommerce-org/graphcommerce/commit/da0ae7d0236e4908ba0bf0fa16656be516e841d4)]:
16
+ - @graphcommerce/graphql-codegen-near-operation-file@3.0.10
17
+
18
+ ## 3.0.7
19
+
20
+ ### Patch Changes
21
+
22
+ - [#1378](https://github.com/graphcommerce-org/graphcommerce/pull/1378) [`b610a6e40`](https://github.com/graphcommerce-org/graphcommerce/commit/b610a6e4049e8c9e8b5d2aeff31b8e1bfc24abe5) Thanks [@paales](https://github.com/paales)! - Pin all versions internally so we can’t end up in an unfixable state for the user
23
+
24
+ ## 3.0.6
25
+
26
+ ### Patch Changes
27
+
28
+ - [#1368](https://github.com/graphcommerce-org/graphcommerce/pull/1368) [`892018809`](https://github.com/graphcommerce-org/graphcommerce/commit/8920188093d0422ec50580e408dc28ac5f93e46a) Thanks [@paales](https://github.com/paales)! - playwright waitForGraphQlResponse shouldn’t crash on non-graphql responses
29
+
30
+ * [#1369](https://github.com/graphcommerce-org/graphcommerce/pull/1369) [`ae6449502`](https://github.com/graphcommerce-org/graphcommerce/commit/ae64495024a455bbe5188588604368c1542840c9) Thanks [@paales](https://github.com/paales)! - Upgraded dependencies
31
+
32
+ - [#1368](https://github.com/graphcommerce-org/graphcommerce/pull/1368) [`892018809`](https://github.com/graphcommerce-org/graphcommerce/commit/8920188093d0422ec50580e408dc28ac5f93e46a) Thanks [@paales](https://github.com/paales)! - Do not recreate client cache when initialized once, fixes issue where the localStorage wasn't updated yet when a new page is loaded.
33
+
34
+ - Updated dependencies [[`ae6449502`](https://github.com/graphcommerce-org/graphcommerce/commit/ae64495024a455bbe5188588604368c1542840c9)]:
35
+ - @graphcommerce/graphql-codegen-near-operation-file@3.0.9
36
+ - @graphcommerce/graphql-codegen-relay-optimizer-plugin@3.0.6
37
+
3
38
  ## 3.0.5
4
39
 
5
40
  ### Patch Changes
@@ -1,27 +1,33 @@
1
1
  import { LocalStorageWrapper, CachePersistor } from 'apollo3-cache-persist'
2
2
  import { mergeDeep, ApolloCache, ApolloClient, NormalizedCacheObject } from './apollo'
3
- import type { TypedTypePolicies } from './generated/types'
3
+ import type { StrictTypedTypePolicies } from './generated/types'
4
4
  import { MigrateCache, migrateCacheHandler } from './migrateCache'
5
5
  import { getTypePoliciesVersion } from './typePolicies'
6
6
 
7
7
  const APOLLO_CACHE_PERSIST = 'apollo-cache-persist'
8
8
  const APOLLO_CACHE_VERSION = 'apollo-cache-version'
9
9
 
10
+ let persistor: CachePersistor<NormalizedCacheObject> | undefined
11
+
12
+ export const persistCache = () => persistor?.persist()
13
+
10
14
  /** Revives the cache from the localStorage if it is available. */
11
15
  export function createCacheReviver(
12
16
  client: ApolloClient<NormalizedCacheObject>,
13
17
  createCache: () => ApolloCache<NormalizedCacheObject>,
14
- policies: TypedTypePolicies[],
18
+ policies: StrictTypedTypePolicies[],
15
19
  migrations: MigrateCache[],
16
20
  incommingState: NormalizedCacheObject = {},
17
21
  ) {
18
22
  let state = incommingState
19
23
  const typePoliciesVersion = getTypePoliciesVersion(policies)
20
24
 
25
+ if (persistor) return
26
+
21
27
  if (typeof window !== 'undefined') {
22
28
  try {
23
29
  const { cache } = client
24
- const persistor = new CachePersistor({
30
+ persistor = new CachePersistor({
25
31
  cache,
26
32
  storage: new LocalStorageWrapper(window.localStorage),
27
33
  maxSize: false,
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": "3.0.5",
5
+ "version": "3.1.0",
6
6
  "sideEffects": false,
7
7
  "main": "index.ts",
8
8
  "prettier": "@graphcommerce/prettier-config-pwa",
@@ -13,15 +13,15 @@
13
13
  }
14
14
  },
15
15
  "devDependencies": {
16
- "@graphcommerce/eslint-config-pwa": "^4.1.1",
17
- "@graphcommerce/prettier-config-pwa": "^4.0.3",
16
+ "@graphcommerce/eslint-config-pwa": "^4.1.5",
17
+ "@graphcommerce/prettier-config-pwa": "^4.0.6",
18
18
  "@graphcommerce/typescript-config-pwa": "^4.0.2",
19
- "@playwright/test": "^1.19.2"
19
+ "@playwright/test": "^1.21.1"
20
20
  },
21
21
  "dependencies": {
22
22
  "@apollo/client": "^3.5.10",
23
- "@graphcommerce/graphql-codegen-near-operation-file": "^3.0.7",
24
- "@graphcommerce/graphql-codegen-relay-optimizer-plugin": "^3.0.5",
23
+ "@graphcommerce/graphql-codegen-near-operation-file": "3.0.10",
24
+ "@graphcommerce/graphql-codegen-relay-optimizer-plugin": "3.0.6",
25
25
  "@graphql-codegen/add": "3.1.1",
26
26
  "@graphql-codegen/fragment-matcher": "3.2.1",
27
27
  "@graphql-codegen/introspection": "2.1.1",
@@ -32,6 +32,6 @@
32
32
  "@graphql-codegen/typescript-document-nodes": "2.2.8",
33
33
  "@graphql-codegen/typescript-operations": "2.3.5",
34
34
  "apollo3-cache-persist": "^0.14.0",
35
- "graphql": "^16.3.0"
35
+ "graphql": "16.3.0"
36
36
  }
37
37
  }
@@ -18,18 +18,24 @@ export async function waitForGraphQlResponse<Q, V>(
18
18
  docOrName: string | TypedDocumentNode<Q, V>,
19
19
  ): Promise<FetchResult<Q>> {
20
20
  const name = typeof docOrName === 'string' ? docOrName : getOperationName(docOrName)
21
- const response = await page.waitForResponse(
22
- (r) => r.request().postDataJSON()?.operationName === name,
23
- )
21
+
22
+ const response = await page.waitForResponse((r) => {
23
+ try {
24
+ return r.request().postDataJSON()?.operationName === name
25
+ } catch (e) {
26
+ return false
27
+ }
28
+ })
29
+
24
30
  return (await response?.json()) as FetchResult<Q>
25
31
  }
26
32
 
27
33
  const test = base.extend<ApolloClientTest>({
28
34
  apolloClient: async ({}, use) => {
29
35
  const client = new ApolloClient({
30
- uri: process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT || 'http://localhost:3000/api/graphql',
36
+ uri: process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT,
31
37
  credentials: 'same-origin',
32
- cache: new InMemoryCache({}),
38
+ cache: new InMemoryCache(),
33
39
  })
34
40
  await use(client)
35
41
  },
package/typePolicies.ts CHANGED
@@ -1,7 +1,7 @@
1
+ import type { StrictTypedTypePolicies } from '@graphcommerce/graphql'
1
2
  import { mergeDeep } from './apollo'
2
- import type { TypedTypePolicies } from './generated/types'
3
3
 
4
- export const mergeTypePolicies = (policies: TypedTypePolicies[]): TypedTypePolicies =>
4
+ export const mergeTypePolicies = (policies: StrictTypedTypePolicies[]): StrictTypedTypePolicies =>
5
5
  mergeDeep(...policies)
6
6
 
7
7
  const generateIdentifyer = (s: string) =>
@@ -14,5 +14,5 @@ const generateIdentifyer = (s: string) =>
14
14
  }, 0),
15
15
  ).toString()
16
16
 
17
- export const getTypePoliciesVersion = (policies: TypedTypePolicies[]) =>
17
+ export const getTypePoliciesVersion = (policies: StrictTypedTypePolicies[]) =>
18
18
  generateIdentifyer(JSON.stringify(policies))