vite-plugin-node icon indicating copy to clipboard operation
vite-plugin-node copied to clipboard

with graphql + nestjs, vite seems to be adding to the schema on every request causing "Schema must contain uniquely named types" -- repository provided

Open sebastiangug opened this issue 3 years ago • 0 comments

Related SO thread: https://stackoverflow.com/questions/73284703

I've been trying to get this combination working for a while and fiddled with versions & compatibilities issue until I've hit this brick wall.

I've created a minium repository where the issue is reproducible: https://github.com/sebastiangug/nest-graphql-vite

The graphql configuration:

        const config: ApolloDriverConfig = {
          debug: true,
          playground: true,
          autoSchemaFile: 'schema.gql',
          sortSchema: true,
          path: join(process.cwd(), 'src/graphql.ts'),
          cors: {
            origin: ['*'],
          },
        };

Versions:

  "dependencies": {
    "@nestjs/common": "9.0.8",
    "@nestjs/core": "9.0.8",
    "@nestjs/platform-express": "9.0.8",
    "@nestjs/graphql": "10.0.9",
    "@nestjs/apollo": "10.0.9",
    "graphql": "15.8.0",
    "apollo-server-express": "3.6.7",
    "reflect-metadata": "0.1.13",
    "rimraf": "3.0.2",
    "rxjs": "7.5.5"
  },
  "devDependencies": {
    "@nestjs/cli": "8.2.8",
    "@nestjs/schematics": "8.0.11",
    "@types/express": "4.17.13",
    "@types/node": "16.0.0",
    "@types/supertest": "2.0.12",
    "prettier": "2.7.1",
    "source-map-support": "0.5.21",
    "ts-node": "10.8.1",
    "tsconfig-paths": "3.10.1",
    "typescript": "4.7.4",
    "vite-plugin-node": "1.0.0",
    "vite": "2.9.13",
    "@swc/core": "1.2.207",
    "vite-tsconfig-paths": "3.5.0"
  }

on nodejs 16

Vite config:

import { ConfigEnv, defineConfig } from 'vite';
import { VitePluginNode } from 'vite-plugin-node';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig(({ command, mode }: ConfigEnv) => {
  return {
    build: {
      target: 'es2020',
    },
    define: {
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
    },
    server: {
      port: 3100,
    },
    optimizeDeps: {
      exclude: [
        '@nestjs/platform-socket.io',
        '@nestjs/express',
        '@nestjs/websockets',
        '@nestjs/microservices',
        '@nestjs/graphql',
        '@nestjs/apollo',
        '@nestjs/core',
        'cache-manager',
        'class-transformer',
        'class-validator',
        'graphql',
      ],
    },
    plugins: [
      tsconfigPaths(),
      ...VitePluginNode({
        adapter: 'nest',
        appPath: './src/main.ts',
        tsCompiler: 'swc',
        swcOptions: {
          jsc: {
            parser: {
              decorators: true,
              syntax: 'typescript',
              dynamicImport: true,
            },
            transform: {
              decoratorMetadata: true,
            },
          },
        },
        appName: 'graphql-server',
      }),
    ],
  };
});

sebastiangug avatar Aug 08 '22 22:08 sebastiangug