@@ -136,8 +136,8 @@ async function test() {
136136
137137 const usage = basicUsage
138138 const output = await validate ( content , config , docs , schema , usage )
139- expect ( output )
140- . toContain ( `export type Sdk = ReturnType<typeof getSdk>; export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
139+ expect ( output ) . toContain (
140+ ` export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
141141 const sdk = getSdk(client, withWrapper);
142142 return {
143143 ...sdk,
@@ -155,7 +155,8 @@ async function test() {
155155 }
156156 };
157157}
158- export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;` )
158+ export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;`
159+ )
159160 } )
160161
161162 it ( 'Should generate the output from which mutation operation has been removed' , async ( ) => {
@@ -216,8 +217,8 @@ export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;`)
216217
217218 const usage = basicUsage
218219 const output = await validate ( content , config , docs , schema , usage )
219- expect ( output )
220- . toContain ( `export type Sdk = ReturnType<typeof getSdk>; export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
220+ expect ( output ) . toContain (
221+ ` export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
221222 const sdk = getSdk(client, withWrapper);
222223 return {
223224 ...sdk,
@@ -235,7 +236,8 @@ export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;`)
235236 }
236237 };
237238}
238- export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;` )
239+ export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;`
240+ )
239241 } )
240242
241243 it ( 'Should work `exclude` option correctly' , async ( ) => {
@@ -250,8 +252,8 @@ export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;`)
250252
251253 const usage = basicUsage
252254 const output = await validate ( content , config , docs , schema , usage )
253- expect ( output )
254- . toContain ( `export type Sdk = ReturnType<typeof getSdk>; export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
255+ expect ( output ) . toContain (
256+ ` export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
255257 const sdk = getSdk(client, withWrapper);
256258 return {
257259 ...sdk,
@@ -263,7 +265,56 @@ export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;`)
263265 }
264266 };
265267}
266- export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;` )
268+ export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;`
269+ )
270+ } )
271+
272+ it ( 'Should work `useSWRInfinite` option correctly' , async ( ) => {
273+ const config : PluginsConfig = {
274+ useSWRInfinite : [ 'feed[24]' ] ,
275+ }
276+ const docs = [ { location : '' , document : basicDoc } ]
277+
278+ const content = ( await plugin ( schema , docs , config , {
279+ outputFile : 'graphql.ts' ,
280+ } ) ) as Types . ComplexPluginOutput
281+
282+ const usage = basicUsage
283+ const output = await validate ( content , config , docs , schema , usage )
284+ expect ( content . prepend ) . toContain (
285+ `import useSWR, { useSWRInfinite, ConfigInterface as SWRConfigInterface, keyInterface as SWRKeyInterface, SWRInfiniteConfigInterface } from 'swr';`
286+ )
287+ expect ( output ) . toContain (
288+ `export type SWRInfiniteKeyLoader<Data = any> = (
289+ index: number,
290+ previousPageData: Data | null
291+ ) => string | any[] | null;
292+ export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
293+ const sdk = getSdk(client, withWrapper);
294+ return {
295+ ...sdk,
296+ useFeed(key: SWRKeyInterface, variables?: FeedQueryVariables, config?: SWRConfigInterface<FeedQuery>) {
297+ return useSWR<FeedQuery>(key, () => sdk.feed(variables), config);
298+ },
299+ useFeed2(key: SWRKeyInterface, variables: Feed2QueryVariables, config?: SWRConfigInterface<Feed2Query>) {
300+ return useSWR<Feed2Query>(key, () => sdk.feed2(variables), config);
301+ },
302+ useFeed2Infinite(getKey: SWRInfiniteKeyLoader<Feed2Query>, variables: Feed2QueryVariables, config?: SWRInfiniteConfigInterface<Feed2Query>) {
303+ return useSWRInfinite<Feed2Query>(getKey, () => sdk.feed2(variables), config);
304+ },
305+ useFeed3(key: SWRKeyInterface, variables?: Feed3QueryVariables, config?: SWRConfigInterface<Feed3Query>) {
306+ return useSWR<Feed3Query>(key, () => sdk.feed3(variables), config);
307+ },
308+ useFeed4(key: SWRKeyInterface, variables?: Feed4QueryVariables, config?: SWRConfigInterface<Feed4Query>) {
309+ return useSWR<Feed4Query>(key, () => sdk.feed4(variables), config);
310+ },
311+ useFeed4Infinite(getKey: SWRInfiniteKeyLoader<Feed4Query>, variables?: Feed4QueryVariables, config?: SWRInfiniteConfigInterface<Feed4Query>) {
312+ return useSWRInfinite<Feed4Query>(getKey, () => sdk.feed4(variables), config);
313+ }
314+ };
315+ }
316+ export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;`
317+ )
267318 } )
268319 } )
269320} )
0 commit comments