Skip to content

ReactRouterV7 with @graphql-codegen/typescript-react-apollo yields error: __vite_ssr_import_3__.useQuery is not a function #975

@alicerocheman

Description

@alicerocheman

Which packages are impacted by your issue?

@graphql-codegen/typescript-react-apollo

Describe the bug

Issue

  1. In a ReactRouter V7 (as a framework) with vite and apollo:
  2. Once query hooks have been generated with @graphql-codegen/typescript-react-apollo
  3. 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

  1. on the reproduction, run
npm install && npm run dev
  1. 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

Image

Platform

  • OS: macOS
  • NodeJS: tested on v18.20.3 && v20.16.0
  • graphql version:
    "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:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions