graphql-codegen-plugin-typescript-swr-ramiel
WARNING
This is a fork of graphql-codegen-plugin-typescript-swr to enable some features, waiting
for these features to be available in the original package in any form. This is not proposed as PR because the code is not mature enough.
Install
npm install graphql-codegen-plugin-typescript-swr-ramiel
What can you do?
Skip queries
You can skip a request
const result = sdk.useMyQuery(
{
eventId: eventId as string,
},
{
skip: isConditionToSkipMet,
}
)
Customize auto generated key
Even if the key is autogenerated, it can be overwritten)
import type { Key } from 'swr'
const customKey = useCallback(
(key: Key) => {
if (admin) return [...key, 'admin']
return key
},
[admin]
)
const result = sdk.useMyQuery(
{
eventId: eventId as string,
},
{
customKey: customKey,
}
)
Loading status
Loading state is now part of the result.
note that loading is always false if the query is skipped
const { loading, data, error } = sdk.useMyQuery({
eventId: eventId as string,
})