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

Nullable typescript issue on prisma plugin #1277

Open
emroot opened this issue Aug 12, 2024 · 8 comments
Open

Nullable typescript issue on prisma plugin #1277

emroot opened this issue Aug 12, 2024 · 8 comments

Comments

@emroot
Copy link

emroot commented Aug 12, 2024

Hey,

I just upgraded to 4.x and I'm getting a bunch of ts errors on my prisma fields that are not null in my DB schema.

image image

am I missing something?

I thought it was related to this (https://pothos-graphql.dev/docs/guide/changing-default-nullability), but changing to false didn't do much.

Thanks

@hayes
Copy link
Owner

hayes commented Aug 12, 2024

That doesn't seem expected, can you share more about your setup (eg what options/types are passed to your builder) or a reproduction? I don't see anything wrong with your setup, but I also haven't seen this in any of the other APIs I've worked on, so there is probably some combination of settings or something that is off

@emroot
Copy link
Author

emroot commented Aug 12, 2024

yeah for sure.
it only happens in VS code, when I run my pnpm type-check no ts errors there.

// builder.ts
import SchemaBuilder from '@pothos/core';
import WithInputPlugin from '@pothos/plugin-with-input';
import { DateTimeResolver, JSONResolver } from 'graphql-scalars';
import PrismaPlugin from '@pothos/plugin-prisma';
import PrismaUtilsPlugin from '@pothos/plugin-prisma-utils';
import RelayPlugin from '@pothos/plugin-relay';
import ScopeAuthPlugin from '@pothos/plugin-scope-auth';
import TracingPlugin, { isRootField } from '@pothos/plugin-tracing';
import ValidationPlugin from '@pothos/plugin-validation';
import { createSentryWrapper } from '@pothos/tracing-sentry';
import { Prisma } from '@prisma/client';
import { GraphqlContext } from '../pothos/context';
import type PrismaTypes from '../prisma/pothos-types';
import db from '../services/prisma';

const traceResolver = createSentryWrapper({
  includeArgs: true,
  includeSource: true,
});

const builder = new SchemaBuilder<{
  AuthScopes: {
    ...
  };
  Context: GraphqlContext;
  Objects: {
    ...
  };
  PrismaTypes: PrismaTypes;
  Scalars: {
    ID: {
      Output: number | string;
      Input: string;
    };
    DateTime: {
      Output: Date;
      Input: Date;
    };
    JSONObject: {
      Input: any;
      Output: any;
    };
  };
  Tracing: boolean | { formatMessage: (duration: number) => string };
}>({
  plugins: [
    TracingPlugin,
    WithInputPlugin,
    RelayPlugin,
    ScopeAuthPlugin,
    PrismaPlugin,
    PrismaUtilsPlugin,
    ValidationPlugin,
  ],
  relay: {
    cursorType: 'ID',
  },
  scopeAuth: {
    cacheKey: (value) => JSON.stringify(value),
    authScopes: async (context) => ({
      ...
    }),
  },
  prisma: {
    client: db,
    dmmf: Prisma.dmmf,
  },
  tracing: {
    default: (config) => isRootField?.(config),
    wrap: (resolver, options) => traceResolver(resolver, options),
  },
});

builder.queryType();
builder.mutationType();

builder.addScalarType('DateTime', DateTimeResolver, {});
builder.addScalarType('JSONObject', JSONResolver, {});

export { builder };
// schema.prisma
generator pothos {
  clientOutput = "@prisma/client"
  provider     = "prisma-pothos-types"
  output       = "./pothos-types.ts"
  prismaUtils  = true
}

Just tried upgrading my typescript from "typescript": "5.4.5" to "typescript": "5.5.4" and not I'm seeing this error when running pnpm type-check

@hayes
Copy link
Owner

hayes commented Aug 12, 2024

Id recommend clearing out any tsbuildinfo files, and remove and reinstall node modules, and then restart vs code. If it's not showing up when you rub type checking via the cli, it might be a caching issue

@emroot
Copy link
Author

emroot commented Aug 12, 2024

Updated vs code to use my workspace version of typescript, instead of the default vs code (latest typescript) and it worked.

But looks like the issue is definitely with typescript 5.5.x

What version of ts are you using? Curious if this is just me or if other are having the same problem with ts 5.5.x

@hayes
Copy link
Owner

hayes commented Aug 12, 2024

I've been using 5.5.4 without issues

@emroot
Copy link
Author

emroot commented Aug 12, 2024

ok thanks. I'll dig a little more on my end and see if I find anything.

@emroot emroot closed this as completed Aug 12, 2024
@hayes hayes reopened this Aug 12, 2024
@hayes
Copy link
Owner

hayes commented Aug 12, 2024

We can leave this open for until we figure out whats going on. I just noticed you are using the validation plugin, which doesn't have a 4.0 version (its been renamed to plugin-zod)

@hayes
Copy link
Owner

hayes commented Aug 12, 2024

Pushed up a repo with most of the code you provided on a branch of an old bug reproduction repo I had: https://github.com/hayes/pothos-prisma-alias-bug/tree/mh--expose-nullable-bug.

I wasn't able to reproduce the issue, but I am curious if this presents the same issue, or if you can expand it with whatever is missing that causes the issue

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