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

Cannot import .graphql files #188

Closed
jbroadice opened this issue Nov 17, 2018 · 6 comments
Closed

Cannot import .graphql files #188

jbroadice opened this issue Nov 17, 2018 · 6 comments

Comments

@jbroadice
Copy link

jbroadice commented Nov 17, 2018

Hello!

I have been trying to use TypeScript to import .graphql files, by using the method mentioned here, however, I consistently receive the error:

src/modules/auth/index.ts(2,27): error TS2307: Cannot find module './schema.graphql'.``

I have tried placing the typings.d.ts file within the same directory as the .graphql file, at the src level, at the project root. None have altered a single thing. It's as if TS isn't even seeing the .d.ts file.

Here is the tsconfig:

  "compilerOptions": {
    "lib": ["es2017", "esnext.asynciterable", "dom"],
    "target": "es2017",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "outDir": "dist",
    "typeRoots": ["node_modules/@types"],
    "paths": {
      "@lib/*": ["./lib/*"],
      "@models/*": ["./models/*"],
      "@modules/*": ["./modules/*"]
    },
    "baseUrl": "./src/",
    "allowSyntheticDefaultImports": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

I have found this related issue, but despite trying all listed solutions, I have not been able to resolve the error.

Any help would be greatly appreciated.

@ardatan
Copy link
Collaborator

ardatan commented Nov 17, 2018

GraphQL-Modules doesn’t have a feature like this. You have to use other libraries to handle graphql files like this
https://github.com/ardatan/graphql-import-node

@dotansimha
Copy link
Collaborator

@jbroadice
Copy link
Author

Brilliant! That's working well. Thank you very much.

@yalamber
Copy link

Hello, I followed the documentation to import files from .graphql files, this works well in development but when building it seems to not build .graphql files and when I run npm start there is this error:
Error: Cannot find module './schema.graphql'

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "module": "commonjs",
    "target": "es6",
    "lib": ["es6", "esnext", "es2015"],
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "sourceMap": true,
    "declaration": true,
    "outDir": "./dist",
    "rootDir": "./src"
  },
  "files": ["src/main.ts"],
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}

My scripts

"scripts": {
    "dev": "nodemon --exec ts-node src/main.ts",
    "debug": "nodemon --exec node -r ts-node/register --inspect src/main.ts",
    "build": "tsc",
    "start": "node dist/main.js"
  },

@ardatan
Copy link
Collaborator

ardatan commented May 30, 2020

@yalamber Because your graphql files are still in the source file directory, you need to copy them to the output folder.

@yaldram
Copy link

yaldram commented Jan 1, 2023

For anyone who came across this issue of not finding .graphql files in your build please check this - https://github.com/a7ul/esbuild-node-tsc#optional-configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants