...

/

Automatically Generated Query Function

Automatically Generated Query Function

Learn about functions generated using GraphQL Code Generator.

Now let’s look at automatically generated code that is not a type, but is instead a function. It is the gnarliest bit of automatically generated code that we have seen so far, so let’s go through it step-by-step.

The generated useAllBooksQuery function

Here is the generated useAllBooksQuery function.

export function useAllBooksQuery(
baseOptions?: Apollo.QueryHookOptions<AllBooksQuery, AllBooksQueryVariables>
) {
const options = { ...defaultOptions, ...baseOptions }
return Apollo.useQuery<AllBooksQuery, AllBooksQueryVariables>(
AllBooksDocument,
options
);
}
useAllBooksQuery function generated using GraphQL Code Generator

This function takes a set of baseOptions and combines them with the defaultOptions (an empty object). We could pass these options to useQuery, but at the moment we will not be passing any options through at all, so we can safely ignore this part.

...