Open fforres opened 10 months ago
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
@fforres
Will keep the WIP here -> https://github.com/dotansimha/graphql-code-generator-community/compare/main...fforres:graphql-code-generator-community:fforres/use_background_query?expand=1
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}>;`,
);
Since this issue has been stale, I've created a PR for this.
https://github.com/dotansimha/graphql-code-generator-community/pull/815
@saihaj Do you mind reviewing the PR?
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