graphql-codegen-plugin-typescript-swr 0.8.5 → 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 (113) hide show
  1. package/README.md +5 -0
  2. package/package.json +5 -2
  3. package/.editorconfig +0 -13
  4. package/.eslintrc.js +0 -63
  5. package/.github/CONTRIBUTING.md +0 -3
  6. package/.github/ISSUE_TEMPLATE.md +0 -9
  7. package/.github/PULL_REQUEST_TEMPLATE.md +0 -7
  8. package/.github/workflows/main.yml +0 -28
  9. package/.gitignore +0 -8
  10. package/.prettierignore +0 -3
  11. package/.prettierrc.json +0 -4
  12. package/.vscode/extensions.json +0 -8
  13. package/.vscode/launch.json +0 -29
  14. package/.vscode/settings.json +0 -41
  15. package/build/tsconfig.main.tsbuildinfo +0 -1
  16. package/build/tsconfig.module.tsbuildinfo +0 -1
  17. package/dev-test/.env +0 -1
  18. package/dev-test/codegen.yml +0 -357
  19. package/dev-test/githunt/__generated__/comment-added.subscription.stencil-component.tsx +0 -47
  20. package/dev-test/githunt/__generated__/comment.query.stencil-component.tsx +0 -68
  21. package/dev-test/githunt/__generated__/comments-page-comment.fragment.stencil-component.tsx +0 -20
  22. package/dev-test/githunt/__generated__/current-user.query.stencil-component.tsx +0 -34
  23. package/dev-test/githunt/__generated__/feed-entry.fragment.stencil-component.tsx +0 -30
  24. package/dev-test/githunt/__generated__/feed.query.stencil-component.tsx +0 -40
  25. package/dev-test/githunt/__generated__/new-entry.mutation.stencil-component.tsx +0 -35
  26. package/dev-test/githunt/__generated__/repo-info.fragment.stencil-component.tsx +0 -26
  27. package/dev-test/githunt/__generated__/submit-comment.mutation.stencil-component.tsx +0 -35
  28. package/dev-test/githunt/__generated__/vote-buttons.fragment.stencil-component.tsx +0 -16
  29. package/dev-test/githunt/__generated__/vote.mutation.stencil-component.tsx +0 -41
  30. package/dev-test/githunt/comment-added.subscription.graphql +0 -11
  31. package/dev-test/githunt/comment.query.graphql +0 -33
  32. package/dev-test/githunt/comments-page-comment.fragment.graphql +0 -9
  33. package/dev-test/githunt/current-user.query.graphql +0 -6
  34. package/dev-test/githunt/feed-entry.fragment.graphql +0 -13
  35. package/dev-test/githunt/feed.query.graphql +0 -8
  36. package/dev-test/githunt/flow.flow.js +0 -367
  37. package/dev-test/githunt/graphql-declared-modules.d.ts +0 -87
  38. package/dev-test/githunt/new-entry.mutation.graphql +0 -5
  39. package/dev-test/githunt/repo-info.fragment.graphql +0 -12
  40. package/dev-test/githunt/schema.js +0 -3
  41. package/dev-test/githunt/schema.json +0 -1750
  42. package/dev-test/githunt/submit-comment.mutation.graphql +0 -5
  43. package/dev-test/githunt/typed-document-nodes.ts +0 -892
  44. package/dev-test/githunt/types.apolloAngular.sdk.ts +0 -570
  45. package/dev-test/githunt/types.apolloAngular.ts +0 -491
  46. package/dev-test/githunt/types.avoidOptionals.ts +0 -266
  47. package/dev-test/githunt/types.d.ts +0 -261
  48. package/dev-test/githunt/types.enumsAsTypes.ts +0 -261
  49. package/dev-test/githunt/types.flatten.preResolveTypes.ts +0 -289
  50. package/dev-test/githunt/types.immutableTypes.ts +0 -267
  51. package/dev-test/githunt/types.preResolveTypes.compatibility.ts +0 -368
  52. package/dev-test/githunt/types.preResolveTypes.onlyOperationTypes.ts +0 -156
  53. package/dev-test/githunt/types.preResolveTypes.ts +0 -293
  54. package/dev-test/githunt/types.reactApollo.customSuffix.tsx +0 -634
  55. package/dev-test/githunt/types.reactApollo.hooks.tsx +0 -621
  56. package/dev-test/githunt/types.reactApollo.preResolveTypes.tsx +0 -648
  57. package/dev-test/githunt/types.reactApollo.tsx +0 -621
  58. package/dev-test/githunt/types.reactApollo.v2.tsx +0 -635
  59. package/dev-test/githunt/types.stencilApollo.tsx +0 -484
  60. package/dev-test/githunt/types.ts +0 -266
  61. package/dev-test/githunt/types.urql.tsx +0 -444
  62. package/dev-test/githunt/types.vueApollo.ts +0 -647
  63. package/dev-test/githunt/vote-buttons.fragment.graphql +0 -6
  64. package/dev-test/githunt/vote.mutation.graphql +0 -9
  65. package/dev-test/setup.js +0 -3
  66. package/dev-test/test-message/documents.ts +0 -46
  67. package/dev-test/test-message/schema.graphql +0 -23
  68. package/dev-test/test-message/types.tsx +0 -237
  69. package/dev-test/test-schema/env.types.ts +0 -35
  70. package/dev-test/test-schema/flow-types.flow.js +0 -139
  71. package/dev-test/test-schema/local/schema-ast.js +0 -2
  72. package/dev-test/test-schema/local/schema-formats.js +0 -20
  73. package/dev-test/test-schema/local/schema-object.js +0 -2
  74. package/dev-test/test-schema/local/schema-text.js +0 -2
  75. package/dev-test/test-schema/local/schema.graphql +0 -8
  76. package/dev-test/test-schema/resolvers-federation.ts +0 -233
  77. package/dev-test/test-schema/resolvers-root.ts +0 -178
  78. package/dev-test/test-schema/resolvers-types.ts +0 -168
  79. package/dev-test/test-schema/schema-ast.js +0 -2
  80. package/dev-test/test-schema/schema-federation.graphql +0 -30
  81. package/dev-test/test-schema/schema-formats.js +0 -38
  82. package/dev-test/test-schema/schema-json.js +0 -2
  83. package/dev-test/test-schema/schema-object.js +0 -2
  84. package/dev-test/test-schema/schema-text.js +0 -2
  85. package/dev-test/test-schema/schema-with-imports.graphql +0 -9
  86. package/dev-test/test-schema/schema-with-root.graphql +0 -22
  87. package/dev-test/test-schema/schema.graphql +0 -19
  88. package/dev-test/test-schema/schema.json +0 -1070
  89. package/dev-test/test-schema/types.preResolveTypes.onlyOperationTypes.ts +0 -19
  90. package/dev-test/test-schema/types.preResolveTypes.ts +0 -44
  91. package/dev-test/test-schema/typings.avoidOptionals.ts +0 -27
  92. package/dev-test/test-schema/typings.enum.ts +0 -19
  93. package/dev-test/test-schema/typings.immutableTypes.ts +0 -27
  94. package/dev-test/test-schema/typings.ts +0 -156
  95. package/dev-test/test-schema/typings.wrapped.ts +0 -29
  96. package/dev-test/tsconfig.json +0 -18
  97. package/jest.config.js +0 -30
  98. package/renovate.json +0 -2
  99. package/src/config.ts +0 -29
  100. package/src/index.ts +0 -54
  101. package/src/visitor.ts +0 -259
  102. package/tests/outputs/autogenSWRKey.ts +0 -46
  103. package/tests/outputs/excludeQueries.ts +0 -13
  104. package/tests/outputs/infinite.ts +0 -49
  105. package/tests/outputs/mutations.ts +0 -19
  106. package/tests/outputs/rawRequest.ts +0 -19
  107. package/tests/outputs/straight.ts +0 -19
  108. package/tests/swr.spec.ts +0 -306
  109. package/tests/visitor.spec.ts +0 -19
  110. package/tsconfig.json +0 -32
  111. package/tsconfig.main.json +0 -11
  112. package/tsconfig.module.json +0 -13
  113. 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
- }