So I'm new in this area, the thing is that I'm trying to compile a Typescript project with graphql files on it (with .graphql
extension).
It' based on the serverless framework, so to compile it I launch npm start
which launches a cd src/app && tsc
in the command line.
The .ts
file references the .graphql
file like this:
import SchemaDefinition from './schemaDefinition.graphql';
And the error is
data/schema/index.ts(2,30): error TS2307: Cannot find module './schemaDefinition.graphql'.
I think the issue here is in the tsc
compilation, as it creates the output directory (../../built) but it is not copying the .graphql
files. Here is my tsconfig.json
file:
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"lib": ["dom", "es6"],
"module": "commonjs",
"allowJs": true,
"moduleResolution": "node",
"noImplicitAny": false,
"removeComments": true,
"preserveConstEnums": true,
"rootDir": "./",
"outDir": "../../built",
"sourceMap": true,
"pretty": true,
"typeRoots": [
"node_modules/@types"
],
"types": [
"@types/node",
"@types/graphql"
],
"allowSyntheticDefaultImports": true
},
"include": [
"./*"
],
"exclude": [
"node_modules"
]
}
I'm not sure if I have to do some trick to copy these files or put a precompiler step to convert the .graphql
files in .ts
files, using something like this: GraphQL Code Generator
Any ideas out there? I'm stuck :S