nestjs / graphql

GraphQL (TypeScript) module for Nest framework (node.js) 🍷
https://docs.nestjs.com/graphql/quick-start
MIT License
1.46k stars 396 forks source link

Mercurius Federation Gateway not working #2299

Closed all2pie closed 1 year ago

all2pie commented 2 years ago

Did you read the migration guide?

Is there an existing issue that is already proposing this?

Potential Commit/PR that introduced the regression

No response

Versions

8.0.0 -> 9.0.3

Describe the regression

After upgrading the Nestjs to V9 the Federation Gateway stopped working and is giving this error:

mercurius-fedration-gateway-bug-nestjs\node_modules\graphql\error\syntaxError.js:15
  return new _GraphQLError.GraphQLError(`Syntax Error: ${description}`, {
         ^
GraphQLError: Syntax Error: Unexpected Name "on".
    at syntaxError (C:\Work\Bugs\mercurius-fedration-gateway-bug-nestjs\node_modules\graphql\error\syntaxError.js:15:10)
    at Parser.unexpected (C:\Work\Bugs\mercurius-fedration-gateway-bug-nestjs\node_modules\graphql\language\parser.js:1476:41)
    at Parser.parseDefinition (C:\Work\Bugs\mercurius-fedration-gateway-bug-nestjs\node_modules\graphql\language\parser.js:211:16)
    at Parser.many (C:\Work\Bugs\mercurius-fedration-gateway-bug-nestjs\node_modules\graphql\language\parser.js:1529:26)
    at Parser.parseDocument (C:\Work\Bugs\mercurius-fedration-gateway-bug-nestjs\node_modules\graphql\language\parser.js:121:25)
    at parse (C:\Work\Bugs\mercurius-fedration-gateway-bug-nestjs\node_modules\graphql\language\parser.js:32:17)
    at buildFederationSchema (C:\Work\Bugs\mercurius-fedration-gateway-bug-nestjs\node_modules\mercurius\lib\federation.js:279:32)
    at buildGateway (C:\Work\Bugs\mercurius-fedration-gateway-bug-nestjs\node_modules\mercurius\lib\gateway.js:316:18)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at fp.name (C:\Work\Bugs\mercurius-fedration-gateway-bug-nestjs\node_modules\mercurius\index.js:233:15)

It works fine if there is only single service in the services array in gateway.module.ts, but its giving the above error with multiple services

Minimum reproduction code

https://github.com/all2pie/nestjs-mercurius-fedration-gateway-issue

Expected behavior

The gateway should work fine

Other

No response

begninix commented 2 years ago

You can fix this problem by setting the version of @apollo/subgraph in your services package.json to 2.0.2.

"dependencies": { "@apollo/subgraph": "2.0.2", ... },

AmineYagoub commented 2 years ago

Will there be any real fix for this? Because @begninix solution not work.

sushilkjaiswar commented 2 years ago

Will there be any real fix for this? Because @begninix solution not work.

Do you have any solution for this issue ? I am facing same issue and where federation with more than one service throws syntax error "Syntax Error: Unexpected "@". Single service works fine with federation when using Mercurius with Nestjs

alexandre-dev29 commented 2 years ago

is there any solution for this?? I am facing the same issue 😩

sushilkjaiswar commented 2 years ago

is there any solution for this?? I am facing the same issue 😩

I did manage to pass all issues and was able to run the server successfully. I had to fix the schema(I use schema first approach) and updated Mercurius federation lib to fix the issue. Still not sure if the solution will be accepted by Mercurius author.

kamilmysliwiec commented 1 year ago

This doesn't seem to be related to NestJS integration packages