-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useBackgroundQuery
and useReadQuery
support (typescript-react-apollo)
#477
Comments
Happy to work on the PR for this, though it might take me a bit 🙏 |
great let me know once you are ready for review @fforres assigned you this issue. Thank you |
I corrected your generator code and it works. // BackgroundQuery Hook
const backgroundOperationName: string =
this.convertName(nodeName, {
suffix: pascalCase('BackgroundQuery'),
useTypesPrefix: false,
}) + this.config.hooksSuffix;
hookFns.push(
`export function use${backgroundOperationName}(baseOptions?: ${this.getApolloReactHooksIdentifier()}.BackgroundQueryHookOptions<${operationResultType}, ${operationVariablesTypes}>) {
const options = {...defaultOptions, ...baseOptions}
return ${this.getApolloReactHooksIdentifier()}.useBackgroundQuery<${operationResultType}, ${operationVariablesTypes}>(${this.getDocumentNodeVariable(
node,
documentVariableName,
)}, options);
}`,
);
hookResults.push(
`export type ${backgroundOperationName}HookResult = ReturnType<typeof use${backgroundOperationName}>;`,
);
// ReadQuery Hook
const readOperationName: string =
this.convertName(nodeName, {
suffix: pascalCase('ReadQuery'),
useTypesPrefix: false,
}) + this.config.hooksSuffix;
hookFns.push(
`export function use${readOperationName}(backgroundQueryRef: ${this.getApolloReactHooksIdentifier()}.QueryReference<${operationResultType}>) {
return ${this.getApolloReactHooksIdentifier()}.useReadQuery<${operationResultType}>(backgroundQueryRef);
}`,
);
hookResults.push(
`export type ${readOperationName}HookResult = ReturnType<typeof use${readOperationName}>;`,
); |
…ableQuery Implement `useBackgroundQuery` and `useLoadableQuery` hooks for React Apollo. These APIs are added in 3.8.0 and 3.9.0 respectively. Suspense support in Apollo Client provides 5 new hooks as described in https://www.apollographql.com/docs/react/data/suspense/. `useSuspenseQuery` support was added in dotansimha#434. Among other 4 hooks, `useBackgroundQuery` and `useLoadableQuery` are the ones that take a GraphQL document as an argument like other existing hooks. The support for these hooks are added in this change. Other hooks, `useQueryRefHanders` and `useReadQuery` do not take a GraphQL document as an argument, so they do not need to be added as the generated code. Both take the return values of other hooks as an argument, and the types are inferred from it. Follow up to dotansimha#388. Fixes dotansimha#477.
Any updates on this? There is a PR ready for review. |
Is your feature request related to a problem? Please describe.
Add support for
useBackgroundQuery
anduseReadQuery
released in apollo-client 3.8Describe the solution you'd like
Allow
typescript-react-apollo
to generateuseBackgroundQuery
anduseReadQuery
hooks with the currentwithHooks: true
optionDescribe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered: