@graphcommerce/graphql 2.103.1
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 +69 -0
- package/README.md +1 -0
- package/_playwright/apolloClient.fixture.ts +38 -0
- package/apollo-client.graphql +2 -0
- package/index.ts +7 -0
- package/measurePerformanceLink.ts +62 -0
- package/migrateCache.ts +14 -0
- package/package.json +30 -0
- package/tsconfig.json +5 -0
- package/typePolicies.ts +18 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [2.103.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.103.0...@graphcommerce/graphql@2.103.1) (2021-09-27)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @graphcommerce/graphql
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# 2.103.0 (2021-09-27)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* ignore md files from triggering version updates ([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* **graphql:** introduced new graphql package that holds all generated files ([a3e7aa0](https://github.com/ho-nl/m2-pwa/commit/a3e7aa05540540533b5ced9a95f1f802ecbe499f))
|
|
25
|
+
* **graphql:** introducing local schema migrations ([e77ef8a](https://github.com/ho-nl/m2-pwa/commit/e77ef8ad4cd5723e2352dec937b45ee976929b24))
|
|
26
|
+
* next.js 11 ([7d61407](https://github.com/ho-nl/m2-pwa/commit/7d614075a778f488045034f74be4f75b93f63c43))
|
|
27
|
+
* **playwright:** added new playwright package to enable browser testing ([6f49ec7](https://github.com/ho-nl/m2-pwa/commit/6f49ec7595563775b96ebf21c27e39da1282e8d9))
|
|
28
|
+
* renamed all packages to use [@graphcommerce](https://github.com/graphcommerce) instead of [@reachdigital](https://github.com/reachdigital) ([491e4ce](https://github.com/ho-nl/m2-pwa/commit/491e4cec9a2686472dac36b79f999257c0811ffe))
|
|
29
|
+
* upgraded to nextjs 11 ([0053beb](https://github.com/ho-nl/m2-pwa/commit/0053beb7ef597c190add7264256a0eaec35868da))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Reverts
|
|
33
|
+
|
|
34
|
+
* Revert "chore: upgrade @apollo/client" ([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# Change Log
|
|
41
|
+
|
|
42
|
+
All notable changes to this project will be documented in this file. See
|
|
43
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
44
|
+
|
|
45
|
+
# [2.102.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.101.3...@graphcommerce/graphql@2.102.0) (2021-08-12)
|
|
46
|
+
|
|
47
|
+
### Features
|
|
48
|
+
|
|
49
|
+
- upgraded to nextjs 11
|
|
50
|
+
([0053beb](https://github.com/ho-nl/m2-pwa/commit/0053beb7ef597c190add7264256a0eaec35868da))
|
|
51
|
+
|
|
52
|
+
## [2.101.3](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.101.2...@graphcommerce/graphql@2.101.3) (2021-08-09)
|
|
53
|
+
|
|
54
|
+
### Reverts
|
|
55
|
+
|
|
56
|
+
- Revert "chore: upgrade @apollo/client"
|
|
57
|
+
([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
|
|
58
|
+
|
|
59
|
+
# [2.101.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql@2.100.10...@graphcommerce/graphql@2.101.0) (2021-07-26)
|
|
60
|
+
|
|
61
|
+
### Bug Fixes
|
|
62
|
+
|
|
63
|
+
- ignore md files from triggering version updates
|
|
64
|
+
([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
|
|
65
|
+
|
|
66
|
+
### Features
|
|
67
|
+
|
|
68
|
+
- **playwright:** added new playwright package to enable browser testing
|
|
69
|
+
([6f49ec7](https://github.com/ho-nl/m2-pwa/commit/6f49ec7595563775b96ebf21c27e39da1282e8d9))
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# GraphQL generation package, used by other packages.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* eslint-disable no-empty-pattern */
|
|
2
|
+
import {
|
|
3
|
+
ApolloClient,
|
|
4
|
+
FetchResult,
|
|
5
|
+
InMemoryCache,
|
|
6
|
+
NormalizedCacheObject,
|
|
7
|
+
TypedDocumentNode,
|
|
8
|
+
} from '@apollo/client'
|
|
9
|
+
import { getOperationName } from '@apollo/client/utilities'
|
|
10
|
+
import { test as base, Page } from '@playwright/test'
|
|
11
|
+
|
|
12
|
+
type ApolloClientTest = {
|
|
13
|
+
apolloClient: ApolloClient<NormalizedCacheObject>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function waitForGraphQlResponse<Q, V>(
|
|
17
|
+
page: Page,
|
|
18
|
+
docOrName: string | TypedDocumentNode<Q, V>,
|
|
19
|
+
): Promise<FetchResult<Q>> {
|
|
20
|
+
const name = typeof docOrName === 'string' ? docOrName : getOperationName(docOrName)
|
|
21
|
+
const response = await page.waitForResponse(
|
|
22
|
+
(r) => r.request().postDataJSON()?.operationName === name,
|
|
23
|
+
)
|
|
24
|
+
return (await response?.json()) as FetchResult<Q>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const test = base.extend<ApolloClientTest>({
|
|
28
|
+
apolloClient: async ({}, use) => {
|
|
29
|
+
const client = new ApolloClient({
|
|
30
|
+
uri: process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT || 'http://localhost:3001/api/graphql',
|
|
31
|
+
credentials: 'same-origin',
|
|
32
|
+
cache: new InMemoryCache({}),
|
|
33
|
+
})
|
|
34
|
+
await use(client)
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
export { test }
|
package/index.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { ApolloLink } from '@apollo/client/core'
|
|
3
|
+
|
|
4
|
+
const slowOperationThreshold = 1000
|
|
5
|
+
const slowResolverThreshold = 300
|
|
6
|
+
|
|
7
|
+
interface TracingFormat {
|
|
8
|
+
version: 1
|
|
9
|
+
startTime: string
|
|
10
|
+
endTime: string
|
|
11
|
+
duration: number
|
|
12
|
+
execution: {
|
|
13
|
+
resolvers: {
|
|
14
|
+
path: (string | number)[]
|
|
15
|
+
parentType: string
|
|
16
|
+
fieldName: string
|
|
17
|
+
returnType: string
|
|
18
|
+
startOffset: number
|
|
19
|
+
duration: number
|
|
20
|
+
}[]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const measurePerformanceLink = new ApolloLink((operation, forward) => {
|
|
25
|
+
if (typeof global.window !== 'undefined') {
|
|
26
|
+
return forward(operation)
|
|
27
|
+
}
|
|
28
|
+
// Called before operation is sent to server
|
|
29
|
+
operation.setContext({ measurePerformanceLinkStart: new Date().valueOf() })
|
|
30
|
+
return forward(operation).map((data) => {
|
|
31
|
+
// Called after server responds
|
|
32
|
+
const time: number =
|
|
33
|
+
new Date().valueOf() - (operation.getContext().measurePerformanceLinkStart as number)
|
|
34
|
+
let vars =
|
|
35
|
+
Object.keys(operation.variables).length > 0 ? `(${JSON.stringify(operation.variables)})` : ''
|
|
36
|
+
if (vars.length > 100) {
|
|
37
|
+
vars = `${vars.substr(0, 100)}…`
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (data.extensions?.tracing && time > slowOperationThreshold) {
|
|
41
|
+
const tracing = data.extensions?.tracing as TracingFormat
|
|
42
|
+
|
|
43
|
+
const duration = Math.round(tracing.duration / (1000 * 1000))
|
|
44
|
+
|
|
45
|
+
console.group(`[slow] ${operation.operationName}${vars}`)
|
|
46
|
+
console.info(`operations ${duration}ms, mesh: ${time - duration}ms`)
|
|
47
|
+
|
|
48
|
+
tracing.execution.resolvers
|
|
49
|
+
.filter((resolver) => resolver.duration > slowResolverThreshold * 1000 * 1000)
|
|
50
|
+
.forEach((resolver) =>
|
|
51
|
+
console.info(
|
|
52
|
+
`${operation.operationName}.${resolver.path.join('.')}[${Math.round(
|
|
53
|
+
resolver.duration / (1000 * 1000),
|
|
54
|
+
)}ms]`,
|
|
55
|
+
),
|
|
56
|
+
)
|
|
57
|
+
console.groupEnd()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return data
|
|
61
|
+
})
|
|
62
|
+
})
|
package/migrateCache.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ApolloCache, NormalizedCacheObject } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export type MigrateCache = (
|
|
4
|
+
oldCache: ApolloCache<NormalizedCacheObject>,
|
|
5
|
+
newCache: ApolloCache<NormalizedCacheObject>,
|
|
6
|
+
) => void
|
|
7
|
+
|
|
8
|
+
export const migrateCacheHandler = (
|
|
9
|
+
oldCache: ApolloCache<NormalizedCacheObject>,
|
|
10
|
+
newCache: ApolloCache<NormalizedCacheObject>,
|
|
11
|
+
migrations: MigrateCache[],
|
|
12
|
+
) => {
|
|
13
|
+
migrations.forEach((migration) => migration(oldCache, newCache))
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphcommerce/graphql",
|
|
3
|
+
"version": "2.103.1",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"main": "index.ts",
|
|
6
|
+
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
7
|
+
"browserslist": [
|
|
8
|
+
"extends @graphcommerce/browserslist-config-pwa"
|
|
9
|
+
],
|
|
10
|
+
"eslintConfig": {
|
|
11
|
+
"extends": "@graphcommerce/eslint-config-pwa",
|
|
12
|
+
"parserOptions": {
|
|
13
|
+
"project": "./tsconfig.json"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@graphcommerce/browserslist-config-pwa": "^3.0.1",
|
|
18
|
+
"@graphcommerce/eslint-config-pwa": "^3.0.1",
|
|
19
|
+
"@graphcommerce/prettier-config-pwa": "^3.0.1",
|
|
20
|
+
"@graphcommerce/typescript-config-pwa": "^3.0.1",
|
|
21
|
+
"@playwright/test": "^1.14.1"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@apollo/client": "^3.3.21",
|
|
25
|
+
"graphql": "^15.5.2",
|
|
26
|
+
"next": "^11.1.2",
|
|
27
|
+
"react": "^17.0.2",
|
|
28
|
+
"react-dom": "^17.0.2"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/tsconfig.json
ADDED
package/typePolicies.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { mergeDeep } from '@apollo/client/utilities'
|
|
2
|
+
import { TypedTypePolicies } from './generated/types'
|
|
3
|
+
|
|
4
|
+
export const mergeTypePolicies = (policies: TypedTypePolicies[]): TypedTypePolicies =>
|
|
5
|
+
mergeDeep(...policies)
|
|
6
|
+
|
|
7
|
+
const generateIdentifyer = (s: string) =>
|
|
8
|
+
Math.abs(
|
|
9
|
+
s.split('').reduce((a, b) => {
|
|
10
|
+
// eslint-disable-next-line no-param-reassign, no-bitwise
|
|
11
|
+
a = (a << 5) - a + b.charCodeAt(0)
|
|
12
|
+
// eslint-disable-next-line no-bitwise
|
|
13
|
+
return a & a
|
|
14
|
+
}, 0),
|
|
15
|
+
).toString()
|
|
16
|
+
|
|
17
|
+
export const getTypePoliciesVersion = (policies: TypedTypePolicies[]) =>
|
|
18
|
+
generateIdentifyer(JSON.stringify(policies))
|