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

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

Closed
sebastiangug opened this issue Aug 8, 2022 · 1 comment

Comments

@sebastiangug
Copy link

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 sebastiangug changed the title graphql code-first approach vite seems to be adding to the schema on every req -- repository provided with graphql + nestjs, vite seems to be adding to the schema on every request causing "Schema must contain uniquely named types" -- repository provided Aug 8, 2022
@axe-me
Copy link
Owner

axe-me commented Jan 12, 2023

it works fine for me with vite 4 and latest version of this plugin:
image

@axe-me axe-me closed this as completed Jan 12, 2023
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

2 participants