graphql-nexus / nexus-prisma

Prisma plugin for Nexus
https://graphql-nexus.github.io/nexus-prisma
MIT License
561 stars 45 forks source link

Cannot find module 'nexus-prisma/scalars' when testing with jest #182

Open zaniluca opened 2 years ago

zaniluca commented 2 years ago

Screenshot

Screenshot

Description

Trying to test my schema i get this error from the nexus-prisma/scalars module. I'm using nexus nexus-prisma and apollo-server-express and I'm testing with jest and ts-jest

Versions:
"dependencies": {
    "@prisma/client": "^3.7.0",
    "apollo-server-express": "^3.6.1"
    "express": "^4.17.2"
    "graphql": "^14.5.0",
    "nexus": "^1.1.0",
    "nexus-prisma": "^0.35.0"
  },
  "devDependencies": {
    "@types/express": "^4.17.13",
    "@types/graphql": "^14.5.0",
    "@types/jest": "^27.4.0",
    "@types/node": "^17.0.8",
    "@types/supertest": "^2.0.11",
    "jest": "^27.4.7",
    "nodemon": "^2.0.15",
    "prisma": "^3.7.0",
    "supertest": "^6.2.1",
    "ts-jest": "^27.1.3",
    "ts-node": "^10.4.0"
    "typescript": "^4.5.4"
  }

Here is my schema.ts file

import { join } from "path";
import * as types from "./definitions";
import { makeSchema } from "nexus";
import { DateTime } from "nexus-prisma/scalars";

export const schema = makeSchema({
  // `NexusPrismaScalars` is for supporting the `DateTime` type
  types: [types, DateTime],
  // Where the generated files are placed
  outputs: {
    typegen: join(__dirname, "node_modules/@types/nexus-typegen/index.d.ts"),
    schema: join(__dirname, "./schema.graphql"),
  },
  sourceTypes: {
    modules: [{ module: ".prisma/client", alias: "PrismaClient" }],
  },
  contextType: {
    module: join(__dirname, "context.ts"),
    export: "Context",
  },
});

And this is my jest.config.js

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
  preset: "ts-jest",
  testEnvironment: "node",
  moduleDirectories: ["node_modules", "src"],
};

Repro Steps/Link

-Make any nexus-prisma project that has NexusPrismaScalars in types array. -run tests with jest

HaKePlan commented 2 years ago

Is there any solution to that?