graphql-codegen-plugin-typescript-swr
Version:
A GraphQL code generator plug-in that automatically generates utility functions for SWR.
14 lines (13 loc) • 673 B
text/typescript
export function getSdkWithHooks(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
const sdk = getSdk(client, withWrapper);
return {
...sdk,
useFeed(key: SWRKeyInterface, variables?: FeedQueryVariables, config?: SWRConfigInterface<FeedQuery, ClientError>) {
return useSWR<FeedQuery, ClientError>(key, () => sdk.feed(variables), config);
},
useFeed4(key: SWRKeyInterface, variables?: Feed4QueryVariables, config?: SWRConfigInterface<Feed4Query, ClientError>) {
return useSWR<Feed4Query, ClientError>(key, () => sdk.feed4(variables), config);
}
};
}
export type SdkWithHooks = ReturnType<typeof getSdkWithHooks>;