Building GraphQL, TypeScript, and Node project with tsc

Building GraphQL, TypeScript, and Node project with tsc


0

I am trying to build a GraphQL project with tsc but am unable to solve an issue

I have referenced this issue. However, when I run npm run build and npm run start the error states that

Error: Cannot find module ‘./DomainOne/schema.graphql’

This is because in the dist folder, the dist/GraphQL/index.js still has imports like so:

var schema_graphql_1 = __importDefault(require("./DomainOne/schema.graphql"));

for all the .graphql files but none exist in the dist folder.

Additionally, I have tried doing a copy of all .graphql files from src to dist in their respective folders but TS complains that type Query is not a type in typescript.

I have a GraphQL project with Node, Express, and TypeScript. Currently the folder structure is like this:

src
├── Erros - holds errors
├── Graphql
│   ├── index.ts - imports ALL `.graphql` files
│   ├── schema.graphql
│   ├── DomainOne
│   │   ├── resolvers.ts
│   │   ├── schema.graphql
│   │   └── types.ts
│   └── DomainTwo
│       ├── resolvers.ts
│       ├── schema.graphql
│       └── types.ts
├── Routes - configures routes
├── Services - for backend api calls
├── Utils - holds utilities
├── global.d.ts
├── index.ts - sets up the server w/ Node, Express
└── ...
...
package.json
tsconfig.json

Where the package.json file is like

{
  ...
  "scripts": {
    "build": "rimraf dist && tsc",
    "start": "node dist/index.js",
  ...
  },
  ...
}

My tsconfig.json is like:

{
    "compilerOptions": {
        "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
        "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
        "lib": [
            "dom",
            "es6",
            "ES2020"
        ] /* Specify library files to be included in the compilation. */,
        "allowJs": true /* Allow javascript files to be compiled. */,
        "sourceMap": true /* Generates corresponding '.map' file. */,
        "outDir": "dist" /* Redirect output structure to the directory. */,
        "removeComments": true /* Do not emit comments to output. */,
        "strict": true /* Enable all strict type-checking options. */,
        "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
        "allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
        "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
        "forceConsistentCasingInFileNames": false,
        "resolveJsonModule": true
    },
    "exclude": ["./tests/**/*.ts"],
    "include": ["./src/**/*.ts", "./**/*.graphql"]
}

My global.d.ts is like:

// src/global.d.ts
declare module '*.graphql' {
    import { DocumentNode } from 'graphql';

    /* eslint-disable-next-line */
    const value: DocumentNode;
    export = value;
}

declare module 'configuration-master'

// see open issue here: https://github.com/confuser/graphql-constraint-directive/issues/156
declare module 'apollo-server-core' {
    interface PluginDefinition {
        _: unknown
    }
}


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *