-
Notifications
You must be signed in to change notification settings - Fork 183
Description
Which packages are impacted by your issue?
@graphql-codegen/typescript-react-apollo
Describe the bug
Issue
- In a ReactRouter V7 (as a framework) with vite and apollo:
- Once query hooks have been generated with @graphql-codegen/typescript-react-apollo
- the import of Apollo inside the generated file breaks the app with this error:
TypeError: __vite_ssr_import_[importNb]__.useQuery is not a function
Your Example Website or App
https://stackblitz.com/edit/github-kocgurap-ascqncjf
Steps to Reproduce the Bug or Issue
- on the reproduction, run
npm install && npm run dev
- the app fails with error "vite_ssr_import_2.useQuery is not a function"
Expected behavior
The npx create-react-router@latest app should run.
Screenshots or Videos
Platform
- OS: macOS
- NodeJS: tested on v18.20.3 && v20.16.0
graphqlversion:
"graphql": "^16.10.0",
"graphql-tag": "^2.12.6",@graphql-codegen/*version(s):
"@graphql-codegen/cli": "^5.0.4",
"@graphql-codegen/near-operation-file-preset": "^3.0.0",
"@graphql-codegen/typescript": "^4.1.3",
"@graphql-codegen/typescript-operations": "^4.4.1",
"@graphql-codegen/typescript-react-apollo": "^4.3.2",
Codegen Config File
import { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
schema: 'schema.graphql',
documents: 'document.graphql',
config: {
gqlImport: 'graphql-tag#gql',
},
generates: {
'types.ts': {
plugins: [
'typescript',
'typescript-operations',
'typescript-react-apollo',
],
},
},
};
export default config;
Additional context
I thought the solution would be to import like this:
import Apollo from '@apollo/client';
instead of the current:
import * as Apollo from '@apollo/client';
but it doesn't seem to work either ('@apollo/client/index has no default export')
Failing test / Solution:
I've looked into this, but I don't know how to solve this
Unrelated issue:
I couldn't use the CodeSandbox link to create a reproduciton repo:
