graphql-nexus / nexus-plugin-prisma

Deprecated
MIT License
829 stars 118 forks source link

typegen error: has no exported member 'QueryMode' or 'SortOrder' #1056

Open 0xsven opened 3 years ago

0xsven commented 3 years ago

Since I have upgraded my dependencies to...

"@prisma/client": "^2.17.0",
"nexus-plugin-prisma": "^0.31.0"
"prisma": "^2.17.0"

... I am getting the following error when transpiling my app:

Generated Artifacts:
          TypeScript Types  ==> /api/nexus-typegen.ts
          GraphQL Schema    ==> /api/schema.graphql
nexus-typegen.ts:626:21 - error TS2694: Namespace '"/api/node_modules/.prisma/client/index"' has no exported member 'QueryMode'.

626   QueryMode: prisma.QueryMode
                        ~~~~~~~~~

nexus-typegen.ts:628:21 - error TS2694: Namespace '"/api/node_modules/.prisma/client/index"' has no exported member 'SortOrder'.

628   SortOrder: prisma.SortOrder
                        ~~~~~~~~~

My workaround is to downgrade prisma client like so:

"@prisma/client": "^2.14.0",
"nexus-plugin-prisma": "^0.31.0"
"prisma": "^2.17.0"

Somehow prisma client 2.15.0 introduced a change that breaks my build. Any ideas what I am missing?

pudgereyem commented 3 years ago

I ran into the same issue after upgrading from 2.13 to 2.17, but for me it was only SortOrder.

Possible underlying issue? (not sure)

The underlying issue seems to be that in the latest version of Prisma, SortOrder is no longer exported at the top level. It is exported under the namespace Prisma. Comparing 2.17 v.s 2.13 below.

2.17 - node_modules/.prisma/client/index.d.ts

export namespace Prisma {

  // ... a lot of stuff here

  export const SortOrder: {
    asc: 'asc',
    desc: 'desc'
  };

  export type SortOrder = (typeof SortOrder)[keyof typeof SortOrder]
}

2.13 - node_modules/.prisma/client/index.d.ts

// ..same as above, but also exports type SortOrder, mentioning that it is deprecated

/**
 * @deprecated Renamed to `Prisma.SortOrder`
 */
export type SortOrder = Prisma.SortOrder

Manual workaround

I can fix this by manually changing the generated file like below

export interface NexusGenEnums {
  SortOrder: Prisma.Prisma.SortOrder // <-- this fixes it
}

But that is not ideal.

Akxe commented 3 years ago

This workaround is what was recommended to me too by maintainers of Prisma. Also, I would like to point out, that the error is type-check error only and the code will still output working code, as such it can be safely ignored as long as builds outputs files.

0xsven commented 3 years ago

This file is generated by the system. How would you permanently change it?

Akxe commented 3 years ago

@0xsven You don't... You have to edit it after every generation... We can only hope this will get fixed...

lvauvillier commented 3 years ago

Another workaround is to set "skipLibCheck": true in your typescript compilerOptions.

Akxe commented 3 years ago

@jasonkuhrt Would you mind looking into this? It is currently breaking every server build (I had to create bash utility to replace prisma.SortOrder to prisma.Prisma.SortOrder...)

I know that you (as prisma) are working on a new plugin, but this will help in the meantime. it should be a simple fix :)

ltnscp9028 commented 3 years ago

@0xsven @Akxe

You can solve this problem by changing the output of makeSchema.

typegen: path.join(__dirname.'/api/nexus-typegen.ts') -> typegen: path.join(__dirname.'/api/nexus-typegen.d.ts')

0xsven commented 3 years ago
Generated Artifacts:
          TypeScript Types  ==> /api/nexus-typegen.d.ts
          GraphQL Schema    ==> /api/schema.graphql
nexus-typegen.ts:605:21 - error TS2694: Namespace '"/api/node_modules/.prisma/client/index"' has no exported member 'QueryMode'.

605   QueryMode: prisma.QueryMode
                        ~~~~~~~~~

nexus-typegen.ts:607:21 - error TS2694: Namespace '"/api/node_modules/.prisma/client/index"' has no exported member 'SortOrder'.

607   SortOrder: prisma.SortOrder
                        ~~~~~~~~~

Found 2 errors.

@ltnscp9028 doesnt work for me

Akxe commented 3 years ago

This package is basically archivated for now, use this workaround:

ts-node -r tsconfig-paths/register --transpile-only ./schema.ts && npx replace-in-file prisma.SortOrder prisma.Prisma.SortOrder **/nexus.generated.ts

Rename the file to your file and if multiple replacements must be made, copy the command twice... not great, but it will do the job for now.

0xsven commented 3 years ago

This worked fine. Thank you!

"build:replace": "replace-in-file prisma.SortOrder prisma.Prisma.SortOrder **/nexus-typegen.ts && replace-in-file prisma.QueryMode prisma.Prisma.QueryMode **/nexus-typegen.ts",
iki commented 2 years ago

@Akxe @0xsven nice hack with replace-in-file, but it doesn't trigger when nexus is generated by the dev server on model/api change.

To use nexus-plugin-prisma with prisma above 2.14, we can override .prisma/client typescript module resolution and inject both QueryMode and SortOrder properties:

  "compilerOptions": {
    "paths": {
      ".prisma/client": ["utils/fix-prisma-client-for-nexus.ts"]
    }
  }
/* eslint-disable import/no-relative-packages */
import { Prisma } from '../../node_modules/.prisma/client';

export * from '../../node_modules/.prisma/client';

// Fix nexus-plugin-prisma using QueryMode/SortOrder moved in prisma 2.15
// See https://github.com/graphql-nexus/nexus-plugin-prisma/issues/1056

export type SortOrder = Prisma.SortOrder;
export type QueryMode = Prisma.QueryMode;

export const { SortOrder, QueryMode } = Prisma;
chrishoermann commented 2 years ago

I replaced the types in makeSchemas mapping property - works perfectly:

export const schema = makeSchema({
    // ... rest of makeSchema config

    mapping: {
      //...all custom scalars
      SortOrder: 'prisma.Prisma.SortOrder',
      QueryMode: 'prisma.Prisma.QueryMode',
    },
  },
seanemmer commented 1 year ago

Amazing fix @chrishoermann thank you!