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

Couldn't use typegraphql with mercurius #665

Closed
ghyath5 opened this issue Nov 23, 2021 · 11 comments
Closed

Couldn't use typegraphql with mercurius #665

ghyath5 opened this issue Nov 23, 2021 · 11 comments

Comments

@ghyath5
Copy link

ghyath5 commented Nov 23, 2021

I am trying to use typegraphql prisma generator, when I pass the built schema to mercurius plugin it shows this error

No overload matches this call. Overload 1 of 3, '(plugin: FastifyPluginCallback<MercuriusOptions, Server>, opts?: FastifyRegisterOptions | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error. Type 'GraphQLSchema' is not assignable to type 'string | string[] | GraphQLSchema | undefined'. Type 'GraphQLSchema' is missing the following properties from type 'GraphQLSchema': description, getImplementations, isSubType Overload 2 of 3, '(plugin: FastifyPluginAsync<MercuriusOptions, Server>, opts?: FastifyRegisterOptions | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error. Argument of type 'typeof mercurius' is not assignable to parameter of type 'FastifyPluginAsync<MercuriusOptions, Server>'. Type 'void' is not assignable to type 'Promise'. Overload 3 of 3, '(plugin: FastifyPluginCallback<MercuriusOptions, Server> | FastifyPluginAsync<MercuriusOptions, Server> | Promise<...> | Promise<...>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error. Type 'GraphQLSchema' is not assignable to type 'string | string[] | GraphQLSchema | undefined'.

q1
q2

@mcollina
Copy link
Collaborator

I don't have a clue, I'm sorry I can't help.

@ghyath5
Copy link
Author

ghyath5 commented Nov 23, 2021

@mcollina
I just deleted graphql from my dependinses it works perfectly, because mercurius doesn't support graphql 16 yet

@kansson
Copy link

kansson commented Jan 9, 2022

Facing the same problem using the latest versions of all packages, how can this be fixed?

@jonnydgreen
Copy link
Contributor

Facing the same problem using the latest versions of all packages, how can this be fixed?

Could you output the following or even better provide a reproducible example please?

npm why graphql
npm why fastify
npm why mercurius
npm why type-graphql

@kansson
Copy link

kansson commented Jan 10, 2022

Actually the problem seems to be that type-graphql doesn't support v16 yet (see MichalLytek/type-graphql#1100). Everything is working when using older versions so I guess that's the blocker.

@bmccorm2
Copy link

Sorry for being dense is there a resolution for this? I am getting the same errors as above and have downgraded my graphql package to 15.3.0.

image

  "dependencies": {
    "class-validator": "^0.13.2",
    "fastify": "^3.27.1",
    "mercurius": "^9.3.2",
    "reflect-metadata": "^0.1.13",
    "type-graphql": "^1.1.1",
    "graphql": "^15.3.0",
    "typeorm": "^0.2.42"
  },
venv) ➜  test ts-node src/index.ts
/home/bryan/.config/yarn/global/node_modules/ts-node/src/index.ts:828
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/index.ts:11:5 - error TS2322: Type 'GraphQLSchema' is not assignable to type 'string | string[] | GraphQLSchema | undefined'.
  Type 'GraphQLSchema' is missing the following properties from type 'GraphQLSchema': __validationErrors, _queryType, _mutationType, _subscriptionType, and 6 more.

11     schema: await buildSchema({
       ~~~~~~
src/index.ts:17:3 - error TS2769: No overload matches this call.

@smolinari
Copy link
Contributor

@bmccorm2 - The issue is with TypeGraphQL. Not Mercurius.

If you are looking for the TypeGraphQL experience, where it also works with v16 of GraphQL (and also gives you a modules/DI system which you have to add with TypeGraphQL), you could try NestJS' code-first approach. Nest now supports Mercurius out of the box.

Scott

@bmccorm2
Copy link

Thanks @smolinari. So if i understand correctly, the stack of fastify/mercurius/typegraphql is not compatible at this time correct? I tried to get it to work on Nest to no avail and i also tried the vanilla example from the site below. Same error as above - all with graphql 15.3.0.

https://mercurius.dev/#/docs/integrations/type-graphql?id=integrating-typegraphql-with-mercurius

@smolinari
Copy link
Contributor

@bmccorm2 - Mercurius and TypeGraphQL should work together with v15 of GraphQL. And, when you say "tried to get it to work with Nest" are you speaking of TypeGraphQL? If yes, you don't need it. Nest has it's own TypeGraphQL-like module. In fact, Nest used to use TypeGraphQL in the past, but went away from it, for reasons I don't know. But, their new GraphQL module is just as good as TypeGraphQL.

Scott

@mcollina
Copy link
Collaborator

You will have to use v8 of Mercurius because that's the one that supports GraphQL v15.

I'm not sure what is blocking the upgrade of TypeGraphql but it seems there is some activity there, so hopefully it will be resolved soon.

@bmccorm2
Copy link

@smolinari - sorry i didn't know that nest had its own graphql module similar to typeGraphQL. I'll give that a try.

@smolinari / @mcollina - I copied the two files from the recipe below. They won't run because of typing errors. V8 of mercurius and v15 of graphql. Are you saying you are able to get those to run?
https://mercurius.dev/#/docs/integrations/type-graphql?id=integrating-typegraphql-with-mercurius

{
  "dependencies": {
    "apollo-server-core": "^3.6.3",
    "apollo-server-fastify": "^3.6.3",
    "fastify": "^3.27.2",
    "graphql": "15.3.0",
    "mercurius": "8.12.0",
    "reflect-metadata": "^0.1.13",
    "type-graphql": "^1.1.1",
    "typeorm": "^0.2.43"
  },
  "devDependencies": {
    "@types/node": "^17.0.18",
    "nodemon": "^2.0.15",
    "sqlite3": "^5.0.2",
    "typescript": "^4.5.5"
  },
  "scripts": {
    "dev": "nodemon --exec ts-node src/mercurius.ts"
  }
}
venv) ➜  test ts-node src/index.ts
/home/bryan/.config/yarn/global/node_modules/ts-node/src/index.ts:828
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/index.ts:11:5 - error TS2322: Type 'GraphQLSchema' is not assignable to type 'string | string[] | GraphQLSchema | undefined'.
  Type 'GraphQLSchema' is missing the following properties from type 'GraphQLSchema': __validationErrors, _queryType, _mutationType, _subscriptionType, and 6 more.

11     schema: await buildSchema({
       ~~~~~~
src/index.ts:17:3 - error TS2769: No overload matches this call.

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

6 participants