graphql-codegen-plugin-typescript-swr 0.8.4 → 0.8.6

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.
Files changed (124) hide show
  1. package/README.md +5 -0
  2. package/build/main/config.d.ts +27 -0
  3. package/build/main/config.js +3 -0
  4. package/build/main/index.d.ts +6 -0
  5. package/build/main/index.js +35 -0
  6. package/build/main/visitor.d.ts +30 -0
  7. package/build/main/visitor.js +160 -0
  8. package/build/module/config.d.ts +27 -0
  9. package/build/module/config.js +2 -0
  10. package/build/module/index.d.ts +6 -0
  11. package/build/module/index.js +30 -0
  12. package/build/module/visitor.d.ts +30 -0
  13. package/build/module/visitor.js +153 -0
  14. package/package.json +5 -2
  15. package/.editorconfig +0 -13
  16. package/.eslintrc.js +0 -63
  17. package/.github/CONTRIBUTING.md +0 -3
  18. package/.github/ISSUE_TEMPLATE.md +0 -9
  19. package/.github/PULL_REQUEST_TEMPLATE.md +0 -7
  20. package/.github/workflows/main.yml +0 -28
  21. package/.gitignore +0 -8
  22. package/.prettierignore +0 -3
  23. package/.prettierrc.json +0 -4
  24. package/.vscode/extensions.json +0 -8
  25. package/.vscode/launch.json +0 -29
  26. package/.vscode/settings.json +0 -41
  27. package/dev-test/.env +0 -1
  28. package/dev-test/codegen.yml +0 -357
  29. package/dev-test/githunt/__generated__/comment-added.subscription.stencil-component.tsx +0 -47
  30. package/dev-test/githunt/__generated__/comment.query.stencil-component.tsx +0 -68
  31. package/dev-test/githunt/__generated__/comments-page-comment.fragment.stencil-component.tsx +0 -20
  32. package/dev-test/githunt/__generated__/current-user.query.stencil-component.tsx +0 -34
  33. package/dev-test/githunt/__generated__/feed-entry.fragment.stencil-component.tsx +0 -30
  34. package/dev-test/githunt/__generated__/feed.query.stencil-component.tsx +0 -40
  35. package/dev-test/githunt/__generated__/new-entry.mutation.stencil-component.tsx +0 -35
  36. package/dev-test/githunt/__generated__/repo-info.fragment.stencil-component.tsx +0 -26
  37. package/dev-test/githunt/__generated__/submit-comment.mutation.stencil-component.tsx +0 -35
  38. package/dev-test/githunt/__generated__/vote-buttons.fragment.stencil-component.tsx +0 -16
  39. package/dev-test/githunt/__generated__/vote.mutation.stencil-component.tsx +0 -41
  40. package/dev-test/githunt/comment-added.subscription.graphql +0 -11
  41. package/dev-test/githunt/comment.query.graphql +0 -33
  42. package/dev-test/githunt/comments-page-comment.fragment.graphql +0 -9
  43. package/dev-test/githunt/current-user.query.graphql +0 -6
  44. package/dev-test/githunt/feed-entry.fragment.graphql +0 -13
  45. package/dev-test/githunt/feed.query.graphql +0 -8
  46. package/dev-test/githunt/flow.flow.js +0 -367
  47. package/dev-test/githunt/graphql-declared-modules.d.ts +0 -87
  48. package/dev-test/githunt/new-entry.mutation.graphql +0 -5
  49. package/dev-test/githunt/repo-info.fragment.graphql +0 -12
  50. package/dev-test/githunt/schema.js +0 -3
  51. package/dev-test/githunt/schema.json +0 -1750
  52. package/dev-test/githunt/submit-comment.mutation.graphql +0 -5
  53. package/dev-test/githunt/typed-document-nodes.ts +0 -892
  54. package/dev-test/githunt/types.apolloAngular.sdk.ts +0 -570
  55. package/dev-test/githunt/types.apolloAngular.ts +0 -491
  56. package/dev-test/githunt/types.avoidOptionals.ts +0 -266
  57. package/dev-test/githunt/types.d.ts +0 -261
  58. package/dev-test/githunt/types.enumsAsTypes.ts +0 -261
  59. package/dev-test/githunt/types.flatten.preResolveTypes.ts +0 -289
  60. package/dev-test/githunt/types.immutableTypes.ts +0 -267
  61. package/dev-test/githunt/types.preResolveTypes.compatibility.ts +0 -368
  62. package/dev-test/githunt/types.preResolveTypes.onlyOperationTypes.ts +0 -156
  63. package/dev-test/githunt/types.preResolveTypes.ts +0 -293
  64. package/dev-test/githunt/types.reactApollo.customSuffix.tsx +0 -634
  65. package/dev-test/githunt/types.reactApollo.hooks.tsx +0 -621
  66. package/dev-test/githunt/types.reactApollo.preResolveTypes.tsx +0 -648
  67. package/dev-test/githunt/types.reactApollo.tsx +0 -621
  68. package/dev-test/githunt/types.reactApollo.v2.tsx +0 -635
  69. package/dev-test/githunt/types.stencilApollo.tsx +0 -484
  70. package/dev-test/githunt/types.ts +0 -266
  71. package/dev-test/githunt/types.urql.tsx +0 -444
  72. package/dev-test/githunt/types.vueApollo.ts +0 -647
  73. package/dev-test/githunt/vote-buttons.fragment.graphql +0 -6
  74. package/dev-test/githunt/vote.mutation.graphql +0 -9
  75. package/dev-test/setup.js +0 -3
  76. package/dev-test/test-message/documents.ts +0 -46
  77. package/dev-test/test-message/schema.graphql +0 -23
  78. package/dev-test/test-message/types.tsx +0 -237
  79. package/dev-test/test-schema/env.types.ts +0 -35
  80. package/dev-test/test-schema/flow-types.flow.js +0 -139
  81. package/dev-test/test-schema/local/schema-ast.js +0 -2
  82. package/dev-test/test-schema/local/schema-formats.js +0 -20
  83. package/dev-test/test-schema/local/schema-object.js +0 -2
  84. package/dev-test/test-schema/local/schema-text.js +0 -2
  85. package/dev-test/test-schema/local/schema.graphql +0 -8
  86. package/dev-test/test-schema/resolvers-federation.ts +0 -233
  87. package/dev-test/test-schema/resolvers-root.ts +0 -178
  88. package/dev-test/test-schema/resolvers-types.ts +0 -168
  89. package/dev-test/test-schema/schema-ast.js +0 -2
  90. package/dev-test/test-schema/schema-federation.graphql +0 -30
  91. package/dev-test/test-schema/schema-formats.js +0 -38
  92. package/dev-test/test-schema/schema-json.js +0 -2
  93. package/dev-test/test-schema/schema-object.js +0 -2
  94. package/dev-test/test-schema/schema-text.js +0 -2
  95. package/dev-test/test-schema/schema-with-imports.graphql +0 -9
  96. package/dev-test/test-schema/schema-with-root.graphql +0 -22
  97. package/dev-test/test-schema/schema.graphql +0 -19
  98. package/dev-test/test-schema/schema.json +0 -1070
  99. package/dev-test/test-schema/types.preResolveTypes.onlyOperationTypes.ts +0 -19
  100. package/dev-test/test-schema/types.preResolveTypes.ts +0 -44
  101. package/dev-test/test-schema/typings.avoidOptionals.ts +0 -27
  102. package/dev-test/test-schema/typings.enum.ts +0 -19
  103. package/dev-test/test-schema/typings.immutableTypes.ts +0 -27
  104. package/dev-test/test-schema/typings.ts +0 -156
  105. package/dev-test/test-schema/typings.wrapped.ts +0 -29
  106. package/dev-test/tsconfig.json +0 -18
  107. package/jest.config.js +0 -30
  108. package/renovate.json +0 -2
  109. package/src/config.ts +0 -29
  110. package/src/index.ts +0 -54
  111. package/src/visitor.ts +0 -259
  112. package/tests/outputs/autogenSWRKey.ts +0 -46
  113. package/tests/outputs/excludeQueries.ts +0 -13
  114. package/tests/outputs/infinite.ts +0 -49
  115. package/tests/outputs/mutations.ts +0 -19
  116. package/tests/outputs/rawRequest.ts +0 -19
  117. package/tests/outputs/straight.ts +0 -19
  118. package/tests/swr.spec.ts +0 -306
  119. package/tests/visitor.spec.ts +0 -19
  120. package/tsconfig.json +0 -32
  121. package/tsconfig.main.json +0 -11
  122. package/tsconfig.module.json +0 -13
  123. package/yarn-error.log +0 -5477
  124. package/yarn.lock +0 -5359
package/tests/swr.spec.ts DELETED
@@ -1,306 +0,0 @@
1
- import fs from 'fs'
2
- import { resolve } from 'path'
3
-
4
- import { Types, mergeOutputs } from '@graphql-codegen/plugin-helpers'
5
- import { validateTs } from '@graphql-codegen/testing'
6
- import {
7
- plugin as tsPlugin,
8
- TypeScriptPluginConfig,
9
- } from '@graphql-codegen/typescript'
10
- import { plugin as graphQLRequestPlugin } from '@graphql-codegen/typescript-graphql-request'
11
- import { GraphQLRequestPluginConfig } from '@graphql-codegen/typescript-graphql-request/visitor'
12
- import {
13
- plugin as tsDocumentsPlugin,
14
- TypeScriptDocumentsPluginConfig,
15
- } from '@graphql-codegen/typescript-operations'
16
- import { parse, GraphQLSchema, buildClientSchema } from 'graphql'
17
-
18
- import { RawSWRPluginConfig } from '../src/config'
19
- import { plugin } from '../src/index'
20
-
21
- type PluginsConfig = Partial<
22
- TypeScriptPluginConfig &
23
- TypeScriptDocumentsPluginConfig &
24
- GraphQLRequestPluginConfig &
25
- RawSWRPluginConfig
26
- >
27
-
28
- const readOutput = (name: string): string =>
29
- fs.readFileSync(resolve(__dirname, `./outputs/${name}.ts`), 'utf-8')
30
-
31
- describe('SWR', () => {
32
- const schema = buildClientSchema(require('../dev-test/githunt/schema.json'))
33
-
34
- const basicDoc = parse(/* GraphQL */ `
35
- query feed {
36
- feed {
37
- id
38
- commentCount
39
- repository {
40
- owner {
41
- avatar_url
42
- }
43
- }
44
- }
45
- }
46
- query feed2($v: String!) {
47
- feed {
48
- id
49
- }
50
- }
51
- query feed3($v: String) {
52
- feed {
53
- id
54
- }
55
- }
56
- query feed4($v: String! = "TEST") {
57
- feed {
58
- id
59
- }
60
- }
61
- `)
62
-
63
- const basicUsage = `
64
- async function test() {
65
- const client = new GraphQLClient('');
66
- const sdk = getSdkWithHooks(client);
67
-
68
- await sdk.feed();
69
- await sdk.feed3();
70
- await sdk.feed4();
71
- const result = await sdk.feed2({ v: "1" });
72
- if (result.feed) {
73
- if (result.feed[0]) {
74
- const id = result.feed[0].id
75
- }
76
- }
77
- }`
78
-
79
- const validate = async (
80
- content: Types.PluginOutput,
81
- config: PluginsConfig,
82
- docs: Types.DocumentFile[],
83
- pluginSchema: GraphQLSchema,
84
- usage: string
85
- ) => {
86
- const m = mergeOutputs([
87
- await tsPlugin(pluginSchema, docs, config, { outputFile: '' }),
88
- await tsDocumentsPlugin(pluginSchema, docs, config),
89
- await graphQLRequestPlugin(pluginSchema, docs, config),
90
- content,
91
- usage,
92
- ])
93
-
94
- await validateTs(m)
95
-
96
- return m
97
- }
98
-
99
- describe('sdk', () => {
100
- it('Should generate import declarations of output correctly', async () => {
101
- const config: PluginsConfig = {}
102
- const docs = [{ location: '', document: basicDoc }]
103
- const usage = ``
104
-
105
- const content = (await plugin(schema, docs, config, {
106
- outputFile: 'graphql.ts',
107
- })) as Types.ComplexPluginOutput
108
-
109
- expect(content.prepend).toContain(
110
- `import useSWR, { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';`
111
- )
112
-
113
- await validate(content, config, docs, schema, usage)
114
- })
115
-
116
- it('Should support useTypeImports', async () => {
117
- const config: PluginsConfig = { useTypeImports: true }
118
- const docs = [{ location: '', document: basicDoc }]
119
- const usage = ``
120
-
121
- const content = (await plugin(schema, docs, config, {
122
- outputFile: 'graphql.ts',
123
- })) as Types.ComplexPluginOutput
124
-
125
- expect(content.prepend).toContain(`import useSWR from 'swr';`)
126
- expect(content.prepend).toContain(
127
- `import type { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';`
128
- )
129
-
130
- await validate(content, config, docs, schema, usage)
131
- })
132
- })
133
-
134
- describe('plugin-typescript-swr', () => {
135
- it('Should generate Hooks API of output correctly', async () => {
136
- const config: PluginsConfig = {}
137
- const docs = [{ location: '', document: basicDoc }]
138
-
139
- const content = (await plugin(schema, docs, config, {
140
- outputFile: 'graphql.ts',
141
- })) as Types.ComplexPluginOutput
142
-
143
- const usage = basicUsage
144
- const output = await validate(content, config, docs, schema, usage)
145
- expect(output).toContain(readOutput('straight'))
146
- })
147
-
148
- it('Should generate the output from which mutation operation has been removed', async () => {
149
- const config: PluginsConfig = {}
150
- const document = parse(/* GraphQL */ `
151
- query feed {
152
- feed {
153
- id
154
- commentCount
155
- repository {
156
- owner {
157
- avatar_url
158
- }
159
- }
160
- }
161
- }
162
- query feed2($v: String!) {
163
- feed {
164
- id
165
- }
166
- }
167
- query feed3($v: String) {
168
- feed {
169
- id
170
- }
171
- }
172
- query feed4($v: String! = "TEST") {
173
- feed {
174
- id
175
- }
176
- }
177
- mutation submitComment(
178
- $repoFullName: String!
179
- $commentContent: String!
180
- ) {
181
- submitComment(
182
- repoFullName: $repoFullName
183
- commentContent: $commentContent
184
- ) {
185
- ...CommentsPageComment
186
- }
187
- }
188
- fragment CommentsPageComment on Comment {
189
- id
190
- postedBy {
191
- login
192
- html_url
193
- }
194
- createdAt
195
- content
196
- }
197
- `)
198
- const docs = [{ location: '', document }]
199
-
200
- const content = (await plugin(schema, docs, config, {
201
- outputFile: 'graphql.ts',
202
- })) as Types.ComplexPluginOutput
203
-
204
- const usage = basicUsage
205
- const output = await validate(content, config, docs, schema, usage)
206
- expect(output).toContain(readOutput('mutations'))
207
- })
208
-
209
- it('Should work `excludeQueries` option correctly', async () => {
210
- const config: PluginsConfig = {
211
- excludeQueries: ['feed[2-3]', 'hoge', 'foo'],
212
- }
213
- const docs = [{ location: '', document: basicDoc }]
214
-
215
- const content = (await plugin(schema, docs, config, {
216
- outputFile: 'graphql.ts',
217
- })) as Types.ComplexPluginOutput
218
-
219
- const usage = basicUsage
220
- const output = await validate(content, config, docs, schema, usage)
221
- expect(output).toContain(readOutput('excludeQueries'))
222
- })
223
-
224
- it('Should work `useSWRInfinite` option correctly', async () => {
225
- const config: PluginsConfig = {
226
- useSWRInfinite: ['feed[24]'],
227
- }
228
- const docs = [{ location: '', document: basicDoc }]
229
-
230
- const content = (await plugin(schema, docs, config, {
231
- outputFile: 'graphql.ts',
232
- })) as Types.ComplexPluginOutput
233
-
234
- const usage = basicUsage
235
- const output = await validate(content, config, docs, schema, usage)
236
- expect(content.prepend).toContain(
237
- `import useSWR, { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';`
238
- )
239
- expect(content.prepend).toContain(
240
- `import useSWRInfinite, { SWRInfiniteConfiguration } from 'swr/infinite';`
241
- )
242
- expect(output).toContain(readOutput('infinite'))
243
- })
244
- })
245
-
246
- it('Should work `autogenSWRKey` option correctly', async () => {
247
- const config: PluginsConfig = {
248
- autogenSWRKey: true,
249
- useSWRInfinite: ['feed[24]'],
250
- }
251
- const docs = [{ location: '', document: basicDoc }]
252
-
253
- const content = (await plugin(schema, docs, config, {
254
- outputFile: 'graphql.ts',
255
- })) as Types.ComplexPluginOutput
256
-
257
- const usage = basicUsage
258
- const output = await validate(content, config, docs, schema, usage)
259
- expect(output).toContain(readOutput('autogenSWRKey'))
260
- })
261
-
262
- it('Should work `rawRequest` option correctly', async () => {
263
- const config: PluginsConfig = {
264
- rawRequest: true,
265
- }
266
- const docs = [{ location: '', document: basicDoc }]
267
-
268
- const content = (await plugin(schema, docs, config, {
269
- outputFile: 'graphql.ts',
270
- })) as Types.ComplexPluginOutput
271
-
272
- const usage = basicUsage
273
- const output = await validate(content, config, docs, schema, usage)
274
- expect(output).toContain(
275
- "import { ClientError } from 'graphql-request/dist/types'"
276
- )
277
- expect(output).toContain(readOutput('rawRequest'))
278
- })
279
-
280
- it('Should work `typesPrefix` and `typesSuffix` option correctly', async () => {
281
- const typesPrefix = 'P'
282
- const typesSuffix = 'S'
283
- const config: PluginsConfig = {
284
- typesPrefix,
285
- typesSuffix,
286
- useSWRInfinite: ['feed'],
287
- }
288
- const docs = [{ location: '', document: basicDoc }]
289
-
290
- const content = (await plugin(schema, docs, config, {
291
- outputFile: 'graphql.ts',
292
- })) as Types.ComplexPluginOutput
293
-
294
- const usage = basicUsage
295
- const output = await validate(content, config, docs, schema, usage)
296
- expect(output).toContain(
297
- `export type ${typesPrefix}SWRInfiniteKeyLoader${typesSuffix}<Data = unknown, Variables = unknown>`
298
- )
299
- expect(output).toContain(
300
- `getKey: ${typesPrefix}SWRInfiniteKeyLoader${typesSuffix}<${typesPrefix}FeedQuery${typesSuffix}, ${typesPrefix}FeedQueryVariables${typesSuffix}>`
301
- )
302
- expect(output).toContain(
303
- `export type ${typesPrefix}SdkWithHooks${typesSuffix} =`
304
- )
305
- })
306
- })
@@ -1,19 +0,0 @@
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
- });
package/tsconfig.json DELETED
@@ -1,32 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "incremental": true,
4
- "target": "es2017",
5
- "rootDir": ".",
6
- "moduleResolution": "node",
7
- "module": "commonjs",
8
- "declaration": true,
9
- "inlineSourceMap": true,
10
- "esModuleInterop": true,
11
- "resolveJsonModule": true,
12
- "noEmit": true,
13
- "noUnusedLocals": true,
14
- "noUnusedParameters": true,
15
- "noImplicitReturns": true,
16
- "noFallthroughCasesInSwitch": true,
17
- "traceResolution": false,
18
- "listEmittedFiles": false,
19
- "listFiles": false,
20
- "pretty": true,
21
- "lib": ["es2017"],
22
- "types": ["node", "jest"]
23
- },
24
- "include": [
25
- "src/**/*.ts",
26
- "tests/**/*.ts",
27
- "dev-test/**/*.ts",
28
- "dev-test/**/*.tsx"
29
- ],
30
- "exclude": ["node_modules/**"],
31
- "compileOnSave": false
32
- }
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "./tsconfig",
3
- "compilerOptions": {
4
- "rootDir": "src",
5
- "noEmit": false,
6
- "outDir": "build/main",
7
- "types": ["node"]
8
- },
9
- "include": ["src/**/*.ts"],
10
- "exclude": ["node_modules/**"]
11
- }
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "./tsconfig",
3
- "compilerOptions": {
4
- "target": "esnext",
5
- "rootDir": "src",
6
- "noEmit": false,
7
- "outDir": "build/module",
8
- "module": "esnext",
9
- "types": ["node"]
10
- },
11
- "include": ["src/**/*.ts"],
12
- "exclude": ["node_modules/**"]
13
- }