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.
- package/README.md +5 -0
- package/build/main/config.d.ts +27 -0
- package/build/main/config.js +3 -0
- package/build/main/index.d.ts +6 -0
- package/build/main/index.js +35 -0
- package/build/main/visitor.d.ts +30 -0
- package/build/main/visitor.js +160 -0
- package/build/module/config.d.ts +27 -0
- package/build/module/config.js +2 -0
- package/build/module/index.d.ts +6 -0
- package/build/module/index.js +30 -0
- package/build/module/visitor.d.ts +30 -0
- package/build/module/visitor.js +153 -0
- package/package.json +5 -2
- package/.editorconfig +0 -13
- package/.eslintrc.js +0 -63
- package/.github/CONTRIBUTING.md +0 -3
- package/.github/ISSUE_TEMPLATE.md +0 -9
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -7
- package/.github/workflows/main.yml +0 -28
- package/.gitignore +0 -8
- package/.prettierignore +0 -3
- package/.prettierrc.json +0 -4
- package/.vscode/extensions.json +0 -8
- package/.vscode/launch.json +0 -29
- package/.vscode/settings.json +0 -41
- package/dev-test/.env +0 -1
- package/dev-test/codegen.yml +0 -357
- package/dev-test/githunt/__generated__/comment-added.subscription.stencil-component.tsx +0 -47
- package/dev-test/githunt/__generated__/comment.query.stencil-component.tsx +0 -68
- package/dev-test/githunt/__generated__/comments-page-comment.fragment.stencil-component.tsx +0 -20
- package/dev-test/githunt/__generated__/current-user.query.stencil-component.tsx +0 -34
- package/dev-test/githunt/__generated__/feed-entry.fragment.stencil-component.tsx +0 -30
- package/dev-test/githunt/__generated__/feed.query.stencil-component.tsx +0 -40
- package/dev-test/githunt/__generated__/new-entry.mutation.stencil-component.tsx +0 -35
- package/dev-test/githunt/__generated__/repo-info.fragment.stencil-component.tsx +0 -26
- package/dev-test/githunt/__generated__/submit-comment.mutation.stencil-component.tsx +0 -35
- package/dev-test/githunt/__generated__/vote-buttons.fragment.stencil-component.tsx +0 -16
- package/dev-test/githunt/__generated__/vote.mutation.stencil-component.tsx +0 -41
- package/dev-test/githunt/comment-added.subscription.graphql +0 -11
- package/dev-test/githunt/comment.query.graphql +0 -33
- package/dev-test/githunt/comments-page-comment.fragment.graphql +0 -9
- package/dev-test/githunt/current-user.query.graphql +0 -6
- package/dev-test/githunt/feed-entry.fragment.graphql +0 -13
- package/dev-test/githunt/feed.query.graphql +0 -8
- package/dev-test/githunt/flow.flow.js +0 -367
- package/dev-test/githunt/graphql-declared-modules.d.ts +0 -87
- package/dev-test/githunt/new-entry.mutation.graphql +0 -5
- package/dev-test/githunt/repo-info.fragment.graphql +0 -12
- package/dev-test/githunt/schema.js +0 -3
- package/dev-test/githunt/schema.json +0 -1750
- package/dev-test/githunt/submit-comment.mutation.graphql +0 -5
- package/dev-test/githunt/typed-document-nodes.ts +0 -892
- package/dev-test/githunt/types.apolloAngular.sdk.ts +0 -570
- package/dev-test/githunt/types.apolloAngular.ts +0 -491
- package/dev-test/githunt/types.avoidOptionals.ts +0 -266
- package/dev-test/githunt/types.d.ts +0 -261
- package/dev-test/githunt/types.enumsAsTypes.ts +0 -261
- package/dev-test/githunt/types.flatten.preResolveTypes.ts +0 -289
- package/dev-test/githunt/types.immutableTypes.ts +0 -267
- package/dev-test/githunt/types.preResolveTypes.compatibility.ts +0 -368
- package/dev-test/githunt/types.preResolveTypes.onlyOperationTypes.ts +0 -156
- package/dev-test/githunt/types.preResolveTypes.ts +0 -293
- package/dev-test/githunt/types.reactApollo.customSuffix.tsx +0 -634
- package/dev-test/githunt/types.reactApollo.hooks.tsx +0 -621
- package/dev-test/githunt/types.reactApollo.preResolveTypes.tsx +0 -648
- package/dev-test/githunt/types.reactApollo.tsx +0 -621
- package/dev-test/githunt/types.reactApollo.v2.tsx +0 -635
- package/dev-test/githunt/types.stencilApollo.tsx +0 -484
- package/dev-test/githunt/types.ts +0 -266
- package/dev-test/githunt/types.urql.tsx +0 -444
- package/dev-test/githunt/types.vueApollo.ts +0 -647
- package/dev-test/githunt/vote-buttons.fragment.graphql +0 -6
- package/dev-test/githunt/vote.mutation.graphql +0 -9
- package/dev-test/setup.js +0 -3
- package/dev-test/test-message/documents.ts +0 -46
- package/dev-test/test-message/schema.graphql +0 -23
- package/dev-test/test-message/types.tsx +0 -237
- package/dev-test/test-schema/env.types.ts +0 -35
- package/dev-test/test-schema/flow-types.flow.js +0 -139
- package/dev-test/test-schema/local/schema-ast.js +0 -2
- package/dev-test/test-schema/local/schema-formats.js +0 -20
- package/dev-test/test-schema/local/schema-object.js +0 -2
- package/dev-test/test-schema/local/schema-text.js +0 -2
- package/dev-test/test-schema/local/schema.graphql +0 -8
- package/dev-test/test-schema/resolvers-federation.ts +0 -233
- package/dev-test/test-schema/resolvers-root.ts +0 -178
- package/dev-test/test-schema/resolvers-types.ts +0 -168
- package/dev-test/test-schema/schema-ast.js +0 -2
- package/dev-test/test-schema/schema-federation.graphql +0 -30
- package/dev-test/test-schema/schema-formats.js +0 -38
- package/dev-test/test-schema/schema-json.js +0 -2
- package/dev-test/test-schema/schema-object.js +0 -2
- package/dev-test/test-schema/schema-text.js +0 -2
- package/dev-test/test-schema/schema-with-imports.graphql +0 -9
- package/dev-test/test-schema/schema-with-root.graphql +0 -22
- package/dev-test/test-schema/schema.graphql +0 -19
- package/dev-test/test-schema/schema.json +0 -1070
- package/dev-test/test-schema/types.preResolveTypes.onlyOperationTypes.ts +0 -19
- package/dev-test/test-schema/types.preResolveTypes.ts +0 -44
- package/dev-test/test-schema/typings.avoidOptionals.ts +0 -27
- package/dev-test/test-schema/typings.enum.ts +0 -19
- package/dev-test/test-schema/typings.immutableTypes.ts +0 -27
- package/dev-test/test-schema/typings.ts +0 -156
- package/dev-test/test-schema/typings.wrapped.ts +0 -29
- package/dev-test/tsconfig.json +0 -18
- package/jest.config.js +0 -30
- package/renovate.json +0 -2
- package/src/config.ts +0 -29
- package/src/index.ts +0 -54
- package/src/visitor.ts +0 -259
- package/tests/outputs/autogenSWRKey.ts +0 -46
- package/tests/outputs/excludeQueries.ts +0 -13
- package/tests/outputs/infinite.ts +0 -49
- package/tests/outputs/mutations.ts +0 -19
- package/tests/outputs/rawRequest.ts +0 -19
- package/tests/outputs/straight.ts +0 -19
- package/tests/swr.spec.ts +0 -306
- package/tests/visitor.spec.ts +0 -19
- package/tsconfig.json +0 -32
- package/tsconfig.main.json +0 -11
- package/tsconfig.module.json +0 -13
- package/yarn-error.log +0 -5477
- package/yarn.lock +0 -5359
package/src/visitor.ts
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClientSideBasePluginConfig,
|
|
3
|
-
ClientSideBaseVisitor,
|
|
4
|
-
indentMultiline,
|
|
5
|
-
LoadedFragment,
|
|
6
|
-
ParsedConfig,
|
|
7
|
-
} from '@graphql-codegen/visitor-plugin-common'
|
|
8
|
-
import { GraphQLSchema, Kind, OperationDefinitionNode } from 'graphql'
|
|
9
|
-
import glob from 'micromatch'
|
|
10
|
-
import { pascalCase } from 'pascal-case'
|
|
11
|
-
|
|
12
|
-
import { RawSWRPluginConfig } from './config'
|
|
13
|
-
|
|
14
|
-
export interface SWRPluginConfig extends ClientSideBasePluginConfig {
|
|
15
|
-
rawRequest: boolean
|
|
16
|
-
excludeQueries: string | string[]
|
|
17
|
-
useSWRInfinite: string | string[]
|
|
18
|
-
autogenSWRKey: boolean
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface Operation {
|
|
22
|
-
node: OperationDefinitionNode
|
|
23
|
-
documentVariableName: string
|
|
24
|
-
operationType: string
|
|
25
|
-
operationResultType: string
|
|
26
|
-
operationVariablesTypes: string
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface ComposeQueryHandlerConfig {
|
|
30
|
-
autogenKey: SWRPluginConfig['autogenSWRKey']
|
|
31
|
-
infinite: boolean
|
|
32
|
-
rawRequest: SWRPluginConfig['rawRequest']
|
|
33
|
-
typesPrefix: ParsedConfig['typesPrefix']
|
|
34
|
-
typesSuffix: ParsedConfig['typesSuffix']
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const composeQueryHandler = (
|
|
38
|
-
operation: Operation,
|
|
39
|
-
config: ComposeQueryHandlerConfig
|
|
40
|
-
): string[] => {
|
|
41
|
-
const codes: string[] = []
|
|
42
|
-
const { node } = operation
|
|
43
|
-
const optionalVariables =
|
|
44
|
-
!node.variableDefinitions ||
|
|
45
|
-
node.variableDefinitions.length === 0 ||
|
|
46
|
-
node.variableDefinitions.every(
|
|
47
|
-
(v) => v.type.kind !== Kind.NON_NULL_TYPE || v.defaultValue
|
|
48
|
-
)
|
|
49
|
-
? '?'
|
|
50
|
-
: ''
|
|
51
|
-
const name = node.name.value
|
|
52
|
-
const pascalName = pascalCase(node.name.value)
|
|
53
|
-
const responseType = config.rawRequest
|
|
54
|
-
? `SWRRawResponse<${operation.operationResultType}>`
|
|
55
|
-
: operation.operationResultType
|
|
56
|
-
const variablesType = operation.operationVariablesTypes
|
|
57
|
-
|
|
58
|
-
codes.push(`use${pascalName}(${
|
|
59
|
-
config.autogenKey ? '' : 'key: SWRKeyInterface, '
|
|
60
|
-
}variables${optionalVariables}: ${variablesType}, config?: SWRConfigInterface<${responseType}, ClientError>) {
|
|
61
|
-
return useSWR<${responseType}, ClientError>(${
|
|
62
|
-
config.autogenKey
|
|
63
|
-
? `genKey<${variablesType}>('${pascalName}', variables)`
|
|
64
|
-
: 'key'
|
|
65
|
-
}, () => sdk.${name}(variables), config);
|
|
66
|
-
}`)
|
|
67
|
-
|
|
68
|
-
if (config.infinite) {
|
|
69
|
-
codes.push(`use${pascalName}Infinite(${
|
|
70
|
-
config.autogenKey ? '' : 'id: string, '
|
|
71
|
-
}getKey: ${config.typesPrefix}SWRInfiniteKeyLoader${
|
|
72
|
-
config.typesSuffix
|
|
73
|
-
}<${responseType}, ${variablesType}>, variables${optionalVariables}: ${variablesType}, config?: SWRInfiniteConfiguration<${responseType}, ClientError>) {
|
|
74
|
-
return useSWRInfinite<${responseType}, ClientError>(
|
|
75
|
-
utilsForInfinite.generateGetKey<${responseType}, ${variablesType}>(${
|
|
76
|
-
config.autogenKey
|
|
77
|
-
? `genKey<${variablesType}>('${pascalName}', variables)`
|
|
78
|
-
: 'id'
|
|
79
|
-
}, getKey),
|
|
80
|
-
utilsForInfinite.generateFetcher<${responseType}, ${variablesType}>(sdk.${name}, variables),
|
|
81
|
-
config);
|
|
82
|
-
}`)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return codes
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export class SWRVisitor extends ClientSideBaseVisitor<
|
|
89
|
-
RawSWRPluginConfig,
|
|
90
|
-
SWRPluginConfig
|
|
91
|
-
> {
|
|
92
|
-
private _operationsToInclude: Operation[] = []
|
|
93
|
-
|
|
94
|
-
private _enabledInfinite = false
|
|
95
|
-
|
|
96
|
-
constructor(
|
|
97
|
-
schema: GraphQLSchema,
|
|
98
|
-
fragments: LoadedFragment[],
|
|
99
|
-
rawConfig: RawSWRPluginConfig
|
|
100
|
-
) {
|
|
101
|
-
super(schema, fragments, rawConfig, {
|
|
102
|
-
excludeQueries: rawConfig.excludeQueries || null,
|
|
103
|
-
useSWRInfinite: rawConfig.useSWRInfinite || null,
|
|
104
|
-
autogenSWRKey: rawConfig.autogenSWRKey || false,
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
this._enabledInfinite =
|
|
108
|
-
(this.config.useSWRInfinite &&
|
|
109
|
-
typeof this.config.useSWRInfinite === 'string') ||
|
|
110
|
-
(Array.isArray(this.config.useSWRInfinite) &&
|
|
111
|
-
this.config.useSWRInfinite.length > 0)
|
|
112
|
-
|
|
113
|
-
const typeImport = this.config.useTypeImports ? 'import type' : 'import'
|
|
114
|
-
|
|
115
|
-
this._additionalImports.push(
|
|
116
|
-
`${typeImport} { ClientError } from 'graphql-request/dist/types';`
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
if (this.config.useTypeImports) {
|
|
120
|
-
if (this._enabledInfinite) {
|
|
121
|
-
this._additionalImports.push(
|
|
122
|
-
`import type { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';`
|
|
123
|
-
)
|
|
124
|
-
this._additionalImports.push(
|
|
125
|
-
`import type { SWRInfiniteConfiguration } from 'swr/infinite';`
|
|
126
|
-
)
|
|
127
|
-
this._additionalImports.push(`import useSWR from 'swr';`)
|
|
128
|
-
this._additionalImports.push(
|
|
129
|
-
`import useSWRInfinite from 'swr/infinite';`
|
|
130
|
-
)
|
|
131
|
-
} else {
|
|
132
|
-
this._additionalImports.push(
|
|
133
|
-
`import type { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';`
|
|
134
|
-
)
|
|
135
|
-
this._additionalImports.push(`import useSWR from 'swr';`)
|
|
136
|
-
}
|
|
137
|
-
} else if (this._enabledInfinite) {
|
|
138
|
-
this._additionalImports.push(
|
|
139
|
-
`import useSWR, { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';`
|
|
140
|
-
)
|
|
141
|
-
this._additionalImports.push(
|
|
142
|
-
`import useSWRInfinite, { SWRInfiniteConfiguration } from 'swr/infinite';`
|
|
143
|
-
)
|
|
144
|
-
} else {
|
|
145
|
-
this._additionalImports.push(
|
|
146
|
-
`import useSWR, { SWRConfiguration as SWRConfigInterface, Key as SWRKeyInterface } from 'swr';`
|
|
147
|
-
)
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
protected buildOperation(
|
|
152
|
-
node: OperationDefinitionNode,
|
|
153
|
-
documentVariableName: string,
|
|
154
|
-
operationType: string,
|
|
155
|
-
operationResultType: string,
|
|
156
|
-
operationVariablesTypes: string
|
|
157
|
-
): string {
|
|
158
|
-
this._operationsToInclude.push({
|
|
159
|
-
node,
|
|
160
|
-
documentVariableName,
|
|
161
|
-
operationType,
|
|
162
|
-
operationResultType,
|
|
163
|
-
operationVariablesTypes,
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
return null
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
public get sdkContent(): string {
|
|
170
|
-
const codes: string[] = []
|
|
171
|
-
const { config } = this
|
|
172
|
-
const disabledexcludeQueries =
|
|
173
|
-
!config.excludeQueries ||
|
|
174
|
-
(Array.isArray(config.excludeQueries) && !config.excludeQueries.length)
|
|
175
|
-
const allPossibleActions = this._operationsToInclude
|
|
176
|
-
.filter((o) => {
|
|
177
|
-
if (o.operationType !== 'Query') {
|
|
178
|
-
return false
|
|
179
|
-
}
|
|
180
|
-
if (disabledexcludeQueries) {
|
|
181
|
-
return true
|
|
182
|
-
}
|
|
183
|
-
return !glob.isMatch(o.node.name.value, config.excludeQueries)
|
|
184
|
-
})
|
|
185
|
-
.map((o) =>
|
|
186
|
-
composeQueryHandler(o, {
|
|
187
|
-
autogenKey: config.autogenSWRKey,
|
|
188
|
-
infinite:
|
|
189
|
-
this._enabledInfinite &&
|
|
190
|
-
glob.isMatch(o.node.name.value, config.useSWRInfinite),
|
|
191
|
-
rawRequest: config.rawRequest,
|
|
192
|
-
typesPrefix: config.typesPrefix,
|
|
193
|
-
typesSuffix: config.typesSuffix,
|
|
194
|
-
})
|
|
195
|
-
)
|
|
196
|
-
.reduce((p, c) => p.concat(c), [])
|
|
197
|
-
.map((s) => indentMultiline(s, 2))
|
|
198
|
-
|
|
199
|
-
// Add type of SWRRawResponse
|
|
200
|
-
if (config.rawRequest) {
|
|
201
|
-
codes.push(
|
|
202
|
-
`type SWRRawResponse<Data = any> = { data?: Data | undefined; extensions?: any; headers: Headers; status: number; errors?: GraphQLError[] | undefined; };`
|
|
203
|
-
)
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Add type of SWRInfiniteKeyLoader
|
|
207
|
-
if (this._enabledInfinite) {
|
|
208
|
-
codes.push(`export type ${config.typesPrefix}SWRInfiniteKeyLoader${config.typesSuffix}<Data = unknown, Variables = unknown> = (
|
|
209
|
-
index: number,
|
|
210
|
-
previousPageData: Data | null
|
|
211
|
-
) => [keyof Variables, Variables[keyof Variables] | null] | null;`)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Add getSdkWithHooks function
|
|
215
|
-
codes.push(`export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
|
|
216
|
-
const sdk = getSdk(client, withWrapper);`)
|
|
217
|
-
|
|
218
|
-
// Add the utility for useSWRInfinite
|
|
219
|
-
if (this._enabledInfinite) {
|
|
220
|
-
codes.push(` const utilsForInfinite = {
|
|
221
|
-
generateGetKey: <Data = unknown, Variables = unknown>(
|
|
222
|
-
id: ${config.autogenSWRKey ? 'SWRKeyInterface' : 'string'},
|
|
223
|
-
getKey: ${config.typesPrefix}SWRInfiniteKeyLoader${
|
|
224
|
-
config.typesSuffix
|
|
225
|
-
}<Data, Variables>
|
|
226
|
-
) => (pageIndex: number, previousData: Data | null) => {
|
|
227
|
-
const key = getKey(pageIndex, previousData)
|
|
228
|
-
return key ? [id, ...key] : null
|
|
229
|
-
},
|
|
230
|
-
generateFetcher: <Query = unknown, Variables = unknown>(query: (variables: Variables) => Promise<Query>, variables?: Variables) => (
|
|
231
|
-
id: string,
|
|
232
|
-
fieldName: keyof Variables,
|
|
233
|
-
fieldValue: Variables[typeof fieldName]
|
|
234
|
-
) => query({ ...variables, [fieldName]: fieldValue } as Variables)
|
|
235
|
-
}`)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Add the function for auto-generation key for SWR
|
|
239
|
-
if (config.autogenSWRKey) {
|
|
240
|
-
codes.push(
|
|
241
|
-
` const genKey = <V extends Record<string, unknown> = Record<string, unknown>>(name: string, object: V = {} as V): SWRKeyInterface => [name, ...Object.keys(object).sort().map(key => object[key])];`
|
|
242
|
-
)
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Add return statement for getSdkWithHooks function and close the function
|
|
246
|
-
codes.push(` return {
|
|
247
|
-
...sdk,
|
|
248
|
-
${allPossibleActions.join(',\n')}
|
|
249
|
-
};
|
|
250
|
-
}`)
|
|
251
|
-
|
|
252
|
-
// Add type of Sdk
|
|
253
|
-
codes.push(
|
|
254
|
-
`export type ${config.typesPrefix}SdkWithHooks${config.typesSuffix} = ReturnType<typeof getSdkWithHooks>;`
|
|
255
|
-
)
|
|
256
|
-
|
|
257
|
-
return codes.join('\n')
|
|
258
|
-
}
|
|
259
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
|
|
2
|
-
const sdk = getSdk(client, withWrapper);
|
|
3
|
-
const utilsForInfinite = {
|
|
4
|
-
generateGetKey: <Data = unknown, Variables = unknown>(
|
|
5
|
-
id: SWRKeyInterface,
|
|
6
|
-
getKey: SWRInfiniteKeyLoader<Data, Variables>
|
|
7
|
-
) => (pageIndex: number, previousData: Data | null) => {
|
|
8
|
-
const key = getKey(pageIndex, previousData)
|
|
9
|
-
return key ? [id, ...key] : null
|
|
10
|
-
},
|
|
11
|
-
generateFetcher: <Query = unknown, Variables = unknown>(query: (variables: Variables) => Promise<Query>, variables?: Variables) => (
|
|
12
|
-
id: string,
|
|
13
|
-
fieldName: keyof Variables,
|
|
14
|
-
fieldValue: Variables[typeof fieldName]
|
|
15
|
-
) => query({ ...variables, [fieldName]: fieldValue } as Variables)
|
|
16
|
-
}
|
|
17
|
-
const genKey = <V extends Record<string, unknown> = Record<string, unknown>>(name: string, object: V = {} as V): SWRKeyInterface => [name, ...Object.keys(object).sort().map(key => object[key])];
|
|
18
|
-
return {
|
|
19
|
-
...sdk,
|
|
20
|
-
useFeed(variables?: FeedQueryVariables, config?: SWRConfigInterface<FeedQuery, ClientError>) {
|
|
21
|
-
return useSWR<FeedQuery, ClientError>(genKey<FeedQueryVariables>('Feed', variables), () => sdk.feed(variables), config);
|
|
22
|
-
},
|
|
23
|
-
useFeed2(variables: Feed2QueryVariables, config?: SWRConfigInterface<Feed2Query, ClientError>) {
|
|
24
|
-
return useSWR<Feed2Query, ClientError>(genKey<Feed2QueryVariables>('Feed2', variables), () => sdk.feed2(variables), config);
|
|
25
|
-
},
|
|
26
|
-
useFeed2Infinite(getKey: SWRInfiniteKeyLoader<Feed2Query, Feed2QueryVariables>, variables: Feed2QueryVariables, config?: SWRInfiniteConfiguration<Feed2Query, ClientError>) {
|
|
27
|
-
return useSWRInfinite<Feed2Query, ClientError>(
|
|
28
|
-
utilsForInfinite.generateGetKey<Feed2Query, Feed2QueryVariables>(genKey<Feed2QueryVariables>('Feed2', variables), getKey),
|
|
29
|
-
utilsForInfinite.generateFetcher<Feed2Query, Feed2QueryVariables>(sdk.feed2, variables),
|
|
30
|
-
config);
|
|
31
|
-
},
|
|
32
|
-
useFeed3(variables?: Feed3QueryVariables, config?: SWRConfigInterface<Feed3Query, ClientError>) {
|
|
33
|
-
return useSWR<Feed3Query, ClientError>(genKey<Feed3QueryVariables>('Feed3', variables), () => sdk.feed3(variables), config);
|
|
34
|
-
},
|
|
35
|
-
useFeed4(variables?: Feed4QueryVariables, config?: SWRConfigInterface<Feed4Query, ClientError>) {
|
|
36
|
-
return useSWR<Feed4Query, ClientError>(genKey<Feed4QueryVariables>('Feed4', variables), () => sdk.feed4(variables), config);
|
|
37
|
-
},
|
|
38
|
-
useFeed4Infinite(getKey: SWRInfiniteKeyLoader<Feed4Query, Feed4QueryVariables>, variables?: Feed4QueryVariables, config?: SWRInfiniteConfiguration<Feed4Query, ClientError>) {
|
|
39
|
-
return useSWRInfinite<Feed4Query, ClientError>(
|
|
40
|
-
utilsForInfinite.generateGetKey<Feed4Query, Feed4QueryVariables>(genKey<Feed4QueryVariables>('Feed4', variables), getKey),
|
|
41
|
-
utilsForInfinite.generateFetcher<Feed4Query, Feed4QueryVariables>(sdk.feed4, variables),
|
|
42
|
-
config);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
|
|
2
|
-
const sdk = getSdk(client, withWrapper);
|
|
3
|
-
return {
|
|
4
|
-
...sdk,
|
|
5
|
-
useFeed(key: SWRKeyInterface, variables?: FeedQueryVariables, config?: SWRConfigInterface<FeedQuery, ClientError>) {
|
|
6
|
-
return useSWR<FeedQuery, ClientError>(key, () => sdk.feed(variables), config);
|
|
7
|
-
},
|
|
8
|
-
useFeed4(key: SWRKeyInterface, variables?: Feed4QueryVariables, config?: SWRConfigInterface<Feed4Query, ClientError>) {
|
|
9
|
-
return useSWR<Feed4Query, ClientError>(key, () => sdk.feed4(variables), config);
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export type SWRInfiniteKeyLoader<Data = unknown, Variables = unknown> = (
|
|
2
|
-
index: number,
|
|
3
|
-
previousPageData: Data | null
|
|
4
|
-
) => [keyof Variables, Variables[keyof Variables] | null] | null;
|
|
5
|
-
export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
|
|
6
|
-
const sdk = getSdk(client, withWrapper);
|
|
7
|
-
const utilsForInfinite = {
|
|
8
|
-
generateGetKey: <Data = unknown, Variables = unknown>(
|
|
9
|
-
id: string,
|
|
10
|
-
getKey: SWRInfiniteKeyLoader<Data, Variables>
|
|
11
|
-
) => (pageIndex: number, previousData: Data | null) => {
|
|
12
|
-
const key = getKey(pageIndex, previousData)
|
|
13
|
-
return key ? [id, ...key] : null
|
|
14
|
-
},
|
|
15
|
-
generateFetcher: <Query = unknown, Variables = unknown>(query: (variables: Variables) => Promise<Query>, variables?: Variables) => (
|
|
16
|
-
id: string,
|
|
17
|
-
fieldName: keyof Variables,
|
|
18
|
-
fieldValue: Variables[typeof fieldName]
|
|
19
|
-
) => query({ ...variables, [fieldName]: fieldValue } as Variables)
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
...sdk,
|
|
23
|
-
useFeed(key: SWRKeyInterface, variables?: FeedQueryVariables, config?: SWRConfigInterface<FeedQuery, ClientError>) {
|
|
24
|
-
return useSWR<FeedQuery, ClientError>(key, () => sdk.feed(variables), config);
|
|
25
|
-
},
|
|
26
|
-
useFeed2(key: SWRKeyInterface, variables: Feed2QueryVariables, config?: SWRConfigInterface<Feed2Query, ClientError>) {
|
|
27
|
-
return useSWR<Feed2Query, ClientError>(key, () => sdk.feed2(variables), config);
|
|
28
|
-
},
|
|
29
|
-
useFeed2Infinite(id: string, getKey: SWRInfiniteKeyLoader<Feed2Query, Feed2QueryVariables>, variables: Feed2QueryVariables, config?: SWRInfiniteConfiguration<Feed2Query, ClientError>) {
|
|
30
|
-
return useSWRInfinite<Feed2Query, ClientError>(
|
|
31
|
-
utilsForInfinite.generateGetKey<Feed2Query, Feed2QueryVariables>(id, getKey),
|
|
32
|
-
utilsForInfinite.generateFetcher<Feed2Query, Feed2QueryVariables>(sdk.feed2, variables),
|
|
33
|
-
config);
|
|
34
|
-
},
|
|
35
|
-
useFeed3(key: SWRKeyInterface, variables?: Feed3QueryVariables, config?: SWRConfigInterface<Feed3Query, ClientError>) {
|
|
36
|
-
return useSWR<Feed3Query, ClientError>(key, () => sdk.feed3(variables), config);
|
|
37
|
-
},
|
|
38
|
-
useFeed4(key: SWRKeyInterface, variables?: Feed4QueryVariables, config?: SWRConfigInterface<Feed4Query, ClientError>) {
|
|
39
|
-
return useSWR<Feed4Query, ClientError>(key, () => sdk.feed4(variables), config);
|
|
40
|
-
},
|
|
41
|
-
useFeed4Infinite(id: string, getKey: SWRInfiniteKeyLoader<Feed4Query, Feed4QueryVariables>, variables?: Feed4QueryVariables, config?: SWRInfiniteConfiguration<Feed4Query, ClientError>) {
|
|
42
|
-
return useSWRInfinite<Feed4Query, ClientError>(
|
|
43
|
-
utilsForInfinite.generateGetKey<Feed4Query, Feed4QueryVariables>(id, getKey),
|
|
44
|
-
utilsForInfinite.generateFetcher<Feed4Query, Feed4QueryVariables>(sdk.feed4, variables),
|
|
45
|
-
config);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
|
|
2
|
-
const sdk = getSdk(client, withWrapper);
|
|
3
|
-
return {
|
|
4
|
-
...sdk,
|
|
5
|
-
useFeed(key: SWRKeyInterface, variables?: FeedQueryVariables, config?: SWRConfigInterface<FeedQuery, ClientError>) {
|
|
6
|
-
return useSWR<FeedQuery, ClientError>(key, () => sdk.feed(variables), config);
|
|
7
|
-
},
|
|
8
|
-
useFeed2(key: SWRKeyInterface, variables: Feed2QueryVariables, config?: SWRConfigInterface<Feed2Query, ClientError>) {
|
|
9
|
-
return useSWR<Feed2Query, ClientError>(key, () => sdk.feed2(variables), config);
|
|
10
|
-
},
|
|
11
|
-
useFeed3(key: SWRKeyInterface, variables?: Feed3QueryVariables, config?: SWRConfigInterface<Feed3Query, ClientError>) {
|
|
12
|
-
return useSWR<Feed3Query, ClientError>(key, () => sdk.feed3(variables), config);
|
|
13
|
-
},
|
|
14
|
-
useFeed4(key: SWRKeyInterface, variables?: Feed4QueryVariables, config?: SWRConfigInterface<Feed4Query, ClientError>) {
|
|
15
|
-
return useSWR<Feed4Query, ClientError>(key, () => sdk.feed4(variables), config);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
|
|
2
|
-
const sdk = getSdk(client, withWrapper);
|
|
3
|
-
return {
|
|
4
|
-
...sdk,
|
|
5
|
-
useFeed(key: SWRKeyInterface, variables?: FeedQueryVariables, config?: SWRConfigInterface<FeedQuery, ClientError>) {
|
|
6
|
-
return useSWR<FeedQuery, ClientError>(key, () => sdk.feed(variables), config);
|
|
7
|
-
},
|
|
8
|
-
useFeed2(key: SWRKeyInterface, variables: Feed2QueryVariables, config?: SWRConfigInterface<Feed2Query, ClientError>) {
|
|
9
|
-
return useSWR<Feed2Query, ClientError>(key, () => sdk.feed2(variables), config);
|
|
10
|
-
},
|
|
11
|
-
useFeed3(key: SWRKeyInterface, variables?: Feed3QueryVariables, config?: SWRConfigInterface<Feed3Query, ClientError>) {
|
|
12
|
-
return useSWR<Feed3Query, ClientError>(key, () => sdk.feed3(variables), config);
|
|
13
|
-
},
|
|
14
|
-
useFeed4(key: SWRKeyInterface, variables?: Feed4QueryVariables, config?: SWRConfigInterface<Feed4Query, ClientError>) {
|
|
15
|
-
return useSWR<Feed4Query, ClientError>(key, () => sdk.feed4(variables), config);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
|
|
2
|
-
const sdk = getSdk(client, withWrapper);
|
|
3
|
-
return {
|
|
4
|
-
...sdk,
|
|
5
|
-
useFeed(key: SWRKeyInterface, variables?: FeedQueryVariables, config?: SWRConfigInterface<FeedQuery, ClientError>) {
|
|
6
|
-
return useSWR<FeedQuery, ClientError>(key, () => sdk.feed(variables), config);
|
|
7
|
-
},
|
|
8
|
-
useFeed2(key: SWRKeyInterface, variables: Feed2QueryVariables, config?: SWRConfigInterface<Feed2Query, ClientError>) {
|
|
9
|
-
return useSWR<Feed2Query, ClientError>(key, () => sdk.feed2(variables), config);
|
|
10
|
-
},
|
|
11
|
-
useFeed3(key: SWRKeyInterface, variables?: Feed3QueryVariables, config?: SWRConfigInterface<Feed3Query, ClientError>) {
|
|
12
|
-
return useSWR<Feed3Query, ClientError>(key, () => sdk.feed3(variables), config);
|
|
13
|
-
},
|
|
14
|
-
useFeed4(key: SWRKeyInterface, variables?: Feed4QueryVariables, config?: SWRConfigInterface<Feed4Query, ClientError>) {
|
|
15
|
-
return useSWR<Feed4Query, ClientError>(key, () => sdk.feed4(variables), config);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;
|