graphql-codegen-plugin-typescript-swr 0.7.0 → 0.8.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/.eslintrc.js +4 -11
- package/.idea/.gitignore +5 -0
- package/.idea/codeStyles/Project.xml +63 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/graphql-codegen-plugin-typescript-swr.iml +12 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +134 -0
- package/build/main/index.js +3 -2
- package/build/main/visitor.js +5 -6
- package/build/module/index.js +4 -3
- package/build/module/visitor.js +5 -6
- package/build/tsconfig.main.tsbuildinfo +1 -1
- package/build/tsconfig.module.tsbuildinfo +1 -1
- package/package-lock.json +9926 -5398
- package/package.json +16 -13
- package/src/index.ts +3 -8
- package/src/visitor.ts +4 -6
- package/tests/swr.spec.ts +2 -2
- package/tests/visitor.spec.ts +19 -0
- package/yarn.lock +1650 -1658
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-codegen-plugin-typescript-swr",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
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",
|
|
7
7
|
"module": "build/module/index.js",
|
|
8
8
|
"repository": "https://github.com/croutonn/graphql-codegen-plugin-typescript-swr",
|
|
9
9
|
"license": "MIT",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=12.0.0"
|
|
12
|
+
},
|
|
10
13
|
"keywords": [
|
|
11
14
|
"graphql",
|
|
12
15
|
"codegen",
|
|
@@ -30,13 +33,12 @@
|
|
|
30
33
|
"watch:build": "tsc -p tsconfig.json -w"
|
|
31
34
|
},
|
|
32
35
|
"peerDependencies": {
|
|
33
|
-
"graphql": "
|
|
36
|
+
"graphql": "<17.0.0"
|
|
34
37
|
},
|
|
35
38
|
"dependencies": {
|
|
36
|
-
"@graphql-codegen/plugin-helpers": "^
|
|
37
|
-
"@graphql-codegen/visitor-plugin-common": "^
|
|
39
|
+
"@graphql-codegen/plugin-helpers": "^2.3.1",
|
|
40
|
+
"@graphql-codegen/visitor-plugin-common": "^2.5.1",
|
|
38
41
|
"@types/micromatch": "^4.0.1",
|
|
39
|
-
"auto-bind": "^4.0.0",
|
|
40
42
|
"graphql-request": "^3.4.0",
|
|
41
43
|
"micromatch": "^4.0.4",
|
|
42
44
|
"pascal-case": "^3.1.2",
|
|
@@ -45,22 +47,23 @@
|
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"@graphql-codegen/testing": "^1.17.7",
|
|
48
|
-
"@graphql-codegen/typescript": "^
|
|
49
|
-
"@graphql-codegen/typescript-graphql-request": "^
|
|
50
|
-
"@graphql-codegen/typescript-operations": "^
|
|
50
|
+
"@graphql-codegen/typescript": "^2.0.0",
|
|
51
|
+
"@graphql-codegen/typescript-graphql-request": "^4.0.0",
|
|
52
|
+
"@graphql-codegen/typescript-operations": "^2.0.0",
|
|
51
53
|
"@types/jest": "^27.0.0",
|
|
52
54
|
"@types/node": "^16.0.0",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
54
|
-
"eslint": "^
|
|
55
|
-
"eslint
|
|
56
|
-
"eslint-config-airbnb
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
56
|
+
"@typescript-eslint/parser": "^5.4.0",
|
|
57
|
+
"eslint": "^8.0.0",
|
|
58
|
+
"eslint-config-airbnb": "^19.0.0",
|
|
59
|
+
"eslint-config-airbnb-typescript": "^16.0.0",
|
|
57
60
|
"eslint-config-prettier": "^8.3.0",
|
|
58
61
|
"eslint-import-resolver-typescript": "^2.4.0",
|
|
59
62
|
"eslint-plugin-import": "^2.23.3",
|
|
60
63
|
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
61
64
|
"eslint-plugin-react": "^7.23.2",
|
|
62
65
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
63
|
-
"graphql": "
|
|
66
|
+
"graphql": "<17.0.0",
|
|
64
67
|
"jest": "^27.0.6",
|
|
65
68
|
"jest-docblock": "^27.0.6",
|
|
66
69
|
"jest-junit": "^13.0.0",
|
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
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
LoadedFragment,
|
|
6
6
|
ParsedConfig,
|
|
7
7
|
} from '@graphql-codegen/visitor-plugin-common'
|
|
8
|
-
import autoBind from 'auto-bind'
|
|
9
8
|
import { GraphQLSchema, Kind, OperationDefinitionNode } from 'graphql'
|
|
10
9
|
import glob from 'micromatch'
|
|
11
10
|
import { pascalCase } from 'pascal-case'
|
|
@@ -111,8 +110,6 @@ export class SWRVisitor extends ClientSideBaseVisitor<
|
|
|
111
110
|
(Array.isArray(this.config.useSWRInfinite) &&
|
|
112
111
|
this.config.useSWRInfinite.length > 0)
|
|
113
112
|
|
|
114
|
-
autoBind(this)
|
|
115
|
-
|
|
116
113
|
const typeImport = this.config.useTypeImports ? 'import type' : 'import'
|
|
117
114
|
|
|
118
115
|
this._additionalImports.push(
|
|
@@ -127,8 +124,9 @@ export class SWRVisitor extends ClientSideBaseVisitor<
|
|
|
127
124
|
this._additionalImports.push(
|
|
128
125
|
`import type { SWRInfiniteConfiguration } from 'swr/infinite';`
|
|
129
126
|
)
|
|
127
|
+
this._additionalImports.push(`import useSWR from 'swr';`)
|
|
130
128
|
this._additionalImports.push(
|
|
131
|
-
`import
|
|
129
|
+
`import useSWRInfinite from 'swr/infinite';`
|
|
132
130
|
)
|
|
133
131
|
} else {
|
|
134
132
|
this._additionalImports.push(
|
|
@@ -138,10 +136,10 @@ export class SWRVisitor extends ClientSideBaseVisitor<
|
|
|
138
136
|
}
|
|
139
137
|
} else if (this._enabledInfinite) {
|
|
140
138
|
this._additionalImports.push(
|
|
141
|
-
`import useSWR, {
|
|
139
|
+
`import useSWR, { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';`
|
|
142
140
|
)
|
|
143
141
|
this._additionalImports.push(
|
|
144
|
-
`import { SWRInfiniteConfiguration } from 'swr/infinite';`
|
|
142
|
+
`import useSWRInfinite, { SWRInfiniteConfiguration } from 'swr/infinite';`
|
|
145
143
|
)
|
|
146
144
|
} else {
|
|
147
145
|
this._additionalImports.push(
|
package/tests/swr.spec.ts
CHANGED
|
@@ -234,10 +234,10 @@ async function test() {
|
|
|
234
234
|
const usage = basicUsage
|
|
235
235
|
const output = await validate(content, config, docs, schema, usage)
|
|
236
236
|
expect(content.prepend).toContain(
|
|
237
|
-
`import useSWR, {
|
|
237
|
+
`import useSWR, { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';`
|
|
238
238
|
)
|
|
239
239
|
expect(content.prepend).toContain(
|
|
240
|
-
`import { SWRInfiniteConfiguration } from 'swr/infinite';`
|
|
240
|
+
`import useSWRInfinite, { SWRInfiniteConfiguration } from 'swr/infinite';`
|
|
241
241
|
)
|
|
242
242
|
expect(output).toContain(readOutput('infinite'))
|
|
243
243
|
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { SWRVisitor } from '../src/visitor'
|
|
3
|
+
|
|
4
|
+
describe('SWRVisitor', () => {
|
|
5
|
+
describe('sdkContent', () => {
|
|
6
|
+
it('should export SWRInfiniteKeyLoader', () => {
|
|
7
|
+
const schema = new GraphQLSchema({
|
|
8
|
+
})
|
|
9
|
+
const visitor = new SWRVisitor(
|
|
10
|
+
schema,
|
|
11
|
+
[],
|
|
12
|
+
{
|
|
13
|
+
useSWRInfinite: ['_query_']
|
|
14
|
+
}
|
|
15
|
+
)
|
|
16
|
+
expect(visitor.sdkContent).toContain('export type SWRInfiniteKeyLoader<Data = unknown,')
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
});
|