Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphql fragment imports do not work #784

Closed
6 tasks done
maxsalven opened this issue Feb 18, 2022 · 0 comments · Fixed by #786
Closed
6 tasks done

Graphql fragment imports do not work #784

maxsalven opened this issue Feb 18, 2022 · 0 comments · Fixed by #786

Comments

@maxsalven
Copy link

Describe the bug

If your application code imports a graphql query which itself imports a fragment, then vitest will crash:

App.tsx:

import QUERY from "./Query.gql"
console.log(QUERY)

Query.gql

#import "./Fragment.gql"

query Foo {
  currentUser {
    ...CurrentUserFields
  }
}

Fragment.gql:

fragment CurrentUserFields on User {
  id
}

yarn test:

 FAIL  src/App.test.tsx [ src/App.test.tsx ]
Error: Parse failure: Unexpected token (1:9)
Contents of line 1: fragment CurrentUserFields on User {

However, the code works correctly in the vite dev environment:

yarn dev:
Screen Shot 2022-02-18 at 10 53 48 AM

Reproduction

Reproduction here:
maxsalven/vitest-gql-bug@9b0ee6e

(Based off of https://github.com/vitest-dev/vitest/tree/main/examples/react-storybook-testing but it's not Storybook specific)

System Info

System:
    OS: macOS 12.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 107.22 MB / 64.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.1 - /var/folders/0c/63_dh8t91pg75b9w6sktbpw80000gn/T/fnm_multishells/90199_1645152149094/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 8.1.2 - /var/folders/0c/63_dh8t91pg75b9w6sktbpw80000gn/T/fnm_multishells/90199_1645152149094/bin/npm
  Browsers:
    Chrome: 98.0.4758.102
    Safari: 15.2
  npmPackages:
    @vitejs/plugin-react: ^1.2.0 => 1.2.0
    vite: latest => 2.8.3
    vitest: latest => 0.3.6

Used Package Manager

yarn

Validations

@github-actions github-actions bot locked and limited conversation to collaborators Jun 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant