Typescript error when using Apollo client to make SSR requests with NEXTJS #8282
-
Using the plugin For example, imagine I want to grab products at build. In export const getStaticProps = async () => {
const client = ApolloClient();
const { data }: GetProductsQueryResult = await client.query({
query: GetProductsDocument,
variables: {
limit: 10,
},
});
// ...
} However, the Type 'ApolloQueryResult' is missing the following properties from type 'QueryResult { limit?: InputMaybe | undefined; }>>': client, observable, called, variables, and 7 more. I can see the other variables that the error is referencing on The generated Apollo query looks like: export type GetProductsQueryResult = Apollo.QueryResult<GetProductsQuery, GetProductsQueryVariables>; Shouldn't this be |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @captDaylight, I would suggest you use a simpler setup that is well integrated with the Apollo client: the By using this plugin, you will get typed GraphQL documents (ex: |
Beta Was this translation helpful? Give feedback.
-
Hi @charlypoly, thanks for the advice. However, with my current setup I'm already generating the So for example this instead: // ...
import type { GetProductsQuery } from 'yadayada/generated/graphql';
import { GetProductsDocument } from 'yadayada/generated/graphql';
export const getStaticProps = async () => {
const client = ApolloClient();
const { data } = await client.query<GetProductsQuery>({
query: GetProductsDocument,
variables: {
limit: PRODUCTS_PAGE_LIMIT,
},
});
// ...
} Now there errors are gone 🎉 |
Beta Was this translation helpful? Give feedback.
Hi @charlypoly, thanks for the advice. However, with my current setup I'm already generating the
GetProductsDocument
. My issue was I was importing the wrong thing from the generated file, instead ofGetProductsQueryResult
it should have beenGetProductsQuery
So for example this instead:
Now there errors are gone 🎉