graphql-codegen-plugin-typescript-swr 0.7.2 → 0.8.2
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/.github/workflows/main.yml +2 -2
- package/build/main/index.js +3 -2
- package/build/module/index.js +4 -3
- package/build/tsconfig.main.tsbuildinfo +1 -1
- package/build/tsconfig.module.tsbuildinfo +1 -1
- package/jest.config.js +1 -1
- package/package.json +11 -11
- package/src/index.ts +3 -8
- package/src/visitor.ts +4 -2
- package/tests/outputs/autogenSWRKey.ts +1 -1
- package/yarn.lock +908 -858
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-codegen-plugin-typescript-swr",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "A GraphQL code generator plug-in that automatically generates utility functions for SWR.",
|
|
5
5
|
"main": "build/main/index.js",
|
|
6
6
|
"typings": "build/main/index.d.ts",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"watch:build": "tsc -p tsconfig.json -w"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"graphql": "
|
|
36
|
+
"graphql": "<17.0.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@graphql-codegen/plugin-helpers": "^2.
|
|
40
|
-
"@graphql-codegen/visitor-plugin-common": "^2.
|
|
39
|
+
"@graphql-codegen/plugin-helpers": "^2.3.1",
|
|
40
|
+
"@graphql-codegen/visitor-plugin-common": "^2.5.1",
|
|
41
41
|
"@types/micromatch": "^4.0.1",
|
|
42
|
-
"graphql-request": "^
|
|
42
|
+
"graphql-request": "^4.0.0",
|
|
43
43
|
"micromatch": "^4.0.4",
|
|
44
44
|
"pascal-case": "^3.1.2",
|
|
45
45
|
"swr": "^1.0.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@graphql-codegen/typescript": "^2.0.0",
|
|
51
51
|
"@graphql-codegen/typescript-graphql-request": "^4.0.0",
|
|
52
52
|
"@graphql-codegen/typescript-operations": "^2.0.0",
|
|
53
|
-
"@types/jest": "^
|
|
53
|
+
"@types/jest": "^28.0.0",
|
|
54
54
|
"@types/node": "^16.0.0",
|
|
55
55
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
56
56
|
"@typescript-eslint/parser": "^5.4.0",
|
|
@@ -63,14 +63,14 @@
|
|
|
63
63
|
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
64
64
|
"eslint-plugin-react": "^7.23.2",
|
|
65
65
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
66
|
-
"graphql": "
|
|
67
|
-
"jest": "^
|
|
68
|
-
"jest-docblock": "^
|
|
69
|
-
"jest-junit": "^
|
|
66
|
+
"graphql": "<17.0.0",
|
|
67
|
+
"jest": "^28.0.0",
|
|
68
|
+
"jest-docblock": "^28.0.0",
|
|
69
|
+
"jest-junit": "^14.0.0",
|
|
70
70
|
"npm-run-all": "^4.1.5",
|
|
71
71
|
"prettier": "^2.2.1",
|
|
72
72
|
"react": "^17.0.2",
|
|
73
|
-
"ts-jest": "^
|
|
73
|
+
"ts-jest": "^28.0.0",
|
|
74
74
|
"typescript": "^4.1.3"
|
|
75
75
|
},
|
|
76
76
|
"files": [
|
package/src/index.ts
CHANGED
|
@@ -4,15 +4,10 @@ import {
|
|
|
4
4
|
Types,
|
|
5
5
|
PluginValidateFn,
|
|
6
6
|
PluginFunction,
|
|
7
|
+
oldVisit,
|
|
7
8
|
} from '@graphql-codegen/plugin-helpers'
|
|
8
9
|
import { LoadedFragment } from '@graphql-codegen/visitor-plugin-common'
|
|
9
|
-
import {
|
|
10
|
-
visit,
|
|
11
|
-
GraphQLSchema,
|
|
12
|
-
concatAST,
|
|
13
|
-
Kind,
|
|
14
|
-
FragmentDefinitionNode,
|
|
15
|
-
} from 'graphql'
|
|
10
|
+
import { GraphQLSchema, concatAST, Kind, FragmentDefinitionNode } from 'graphql'
|
|
16
11
|
|
|
17
12
|
import { RawSWRPluginConfig } from './config'
|
|
18
13
|
import { SWRVisitor } from './visitor'
|
|
@@ -38,7 +33,7 @@ export const plugin: PluginFunction<RawSWRPluginConfig> = (
|
|
|
38
33
|
]
|
|
39
34
|
|
|
40
35
|
const visitor = new SWRVisitor(schema, allFragments, config)
|
|
41
|
-
|
|
36
|
+
oldVisit(allAst, { leave: visitor })
|
|
42
37
|
return {
|
|
43
38
|
prepend: visitor.getImports(),
|
|
44
39
|
content: visitor.sdkContent,
|
package/src/visitor.ts
CHANGED
|
@@ -219,8 +219,10 @@ export class SWRVisitor extends ClientSideBaseVisitor<
|
|
|
219
219
|
if (this._enabledInfinite) {
|
|
220
220
|
codes.push(` const utilsForInfinite = {
|
|
221
221
|
generateGetKey: <Data = unknown, Variables = unknown>(
|
|
222
|
-
id: string,
|
|
223
|
-
getKey: ${config.typesPrefix}SWRInfiniteKeyLoader${
|
|
222
|
+
id: ${config.autogenSWRKey ? 'SWRKeyInterface' : 'string'},
|
|
223
|
+
getKey: ${config.typesPrefix}SWRInfiniteKeyLoader${
|
|
224
|
+
config.typesSuffix
|
|
225
|
+
}<Data, Variables>
|
|
224
226
|
) => (pageIndex: number, previousData: Data | null) => {
|
|
225
227
|
const key = getKey(pageIndex, previousData)
|
|
226
228
|
return key ? [id, ...key] : null
|
|
@@ -2,7 +2,7 @@ export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionW
|
|
|
2
2
|
const sdk = getSdk(client, withWrapper);
|
|
3
3
|
const utilsForInfinite = {
|
|
4
4
|
generateGetKey: <Data = unknown, Variables = unknown>(
|
|
5
|
-
id:
|
|
5
|
+
id: SWRKeyInterface,
|
|
6
6
|
getKey: SWRInfiniteKeyLoader<Data, Variables>
|
|
7
7
|
) => (pageIndex: number, previousData: Data | null) => {
|
|
8
8
|
const key = getKey(pageIndex, previousData)
|