0

Here's what my returned GQL data looks like:

{
  "data": {
    "Orders": [
      ...
    ]
  },
  "extensions": {
    "unlimitedTotal": {
      "Orders": 3534
    }
  }
}

My issue is that the types generated by graphql-codegen only include the fields inside data. Is there any way to access extensions? As you can see, it contains the number of all results, which is needed for pagination (so I'll use it inside getNextPageParam like below)

const {data} = useInfiniteGetOrdersQuery(
        'offset',
        { limit: 20 },
        { getNextPageParam: (lastPage, pages) => lastPage.extensions.unlimitedTotal ... }
    );

Here's my config:

const config: CodegenConfig = {
    schema: '...',
    documents: ['./src/**/*.graphql'],
    generates: {
        './src/gql/index.ts': {
            plugins: ['typescript', 'typescript-operations', 'typescript-react-query'],
            config: {
                fetcher: { endpoint: '...' },
                addInfiniteQuery: true,
            },
        },
    },
};

export default config;

I tried making a custom fetch function which returns

return { ...json.data, ...json.extensions, };

but I don't know how to get the type for extensions now.

Any help is appreciated!

byoda
  • 132
  • 2
  • 4

0 Answers0