davide-gheri / nestjs-mercurius Goto Github PK
View Code? Open in Web Editor NEWNestJs module to use Mercurius as GraphQL server
License: MIT License
NestJs module to use Mercurius as GraphQL server
License: MIT License
Requesting /playground
results in a 404
using nestjs-mercurius": "^0.10.1
.
The module begins registred.
MercuriusModule.forRoot({
autoSchemaFile: 'schema.graphql',
context: (_, reply) => ({
reply,
}),
}),
I created an upstream issue because I thought it might be a Nest.js issue. I'm not completely sure if it is or isn't.
and the reproduction... https://github.com/j/nestjs-middleware-bug
I'm uncertain and haven't dug too much into it, but it breaks my authentication when switching over to this library. I'm assuming it might be due to the duplicate "fastify" modules you get when installing @nestjs/platform-fastify
and (nestjs-)mercurius.
It's a pretty blocking issue though since a lot of people use modules that rely on nest application middleware.
MercuriusModule.forRoot({
autoSchemaFile: './src/schema.graphql',
graphiql: true,
ide: true,
path: '/graphql',
context: (request, reply) => ({ request, reply }),
subscription: {
context: (request, reply) => ({ request, reply }),
},
}),
{ "data": null, "errors": [ { "message": "request.is is not a function" } ] }
Hello,
while adding NODE_ENV: production
to docker container NestJS with Mercurius module causes an error, here a stacktrace
2021-08-19T09:33:10.167166200Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [NestFactory] Starting Nest application...
2021-08-19T09:33:10.290469700Z [Nest] 51 - 08/19/2021, 9:33:10 AM WARN [HttpService] DEPRECATED! "HttpModule" (from the "@nestjs/common" package) is deprecated and will be removed in the next major release. Please, use the "@nestjs/axios" package instead.
2021-08-19T09:33:10.308618100Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] TypeOrmModule dependencies initialized +18ms
2021-08-19T09:33:10.308947400Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] SentryModule dependencies initialized +1ms
2021-08-19T09:33:10.309330500Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] GeocoderModule dependencies initialized +0ms
2021-08-19T09:33:10.309753200Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] MailerModule dependencies initialized +1ms
2021-08-19T09:33:10.310271400Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] PaginatorModule dependencies initialized +0ms
2021-08-19T09:33:10.310588900Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] MailerModule dependencies initialized +0ms
2021-08-19T09:33:10.311131100Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] TimezoneModule dependencies initialized +1ms
2021-08-19T09:33:10.314556100Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] HttpModule dependencies initialized +3ms
2021-08-19T09:33:10.315266100Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] ConfigHostModule dependencies initialized +1ms
2021-08-19T09:33:10.315561700Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] AwsSdkModule dependencies initialized +0ms
2021-08-19T09:33:10.316444900Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] DiscoveryModule dependencies initialized +0ms
2021-08-19T09:33:10.316809200Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] MercuriusCoreModule dependencies initialized +1ms
2021-08-19T09:33:10.317670500Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] TerminusModule dependencies initialized +1ms
2021-08-19T09:33:10.318316800Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] ConfigModule dependencies initialized +0ms
2021-08-19T09:33:10.318778400Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] ConfigModule dependencies initialized +1ms
2021-08-19T09:33:10.319047500Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] S3ManagerModule dependencies initialized +0ms
2021-08-19T09:33:10.331650800Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] EventEmitterModule dependencies initialized +12ms
2021-08-19T09:33:10.364046700Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] SentryCoreModule dependencies initialized +33ms
2021-08-19T09:33:10.364356000Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] GeocoderCoreModule dependencies initialized +0ms
2021-08-19T09:33:10.364753100Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] MailerCoreModule dependencies initialized +1ms
2021-08-19T09:33:10.364937100Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] JwtModule dependencies initialized +0ms
2021-08-19T09:33:10.365598600Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] GraphQLSchemaBuilderModule dependencies initialized +1ms
2021-08-19T09:33:10.366691200Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] MercuriusModule dependencies initialized +1ms
2021-08-19T09:33:10.880305100Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] TypeOrmCoreModule dependencies initialized +513ms
2021-08-19T09:33:10.880968500Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] RelationLoaderModule dependencies initialized +1ms
2021-08-19T09:33:10.881226300Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms
2021-08-19T09:33:10.881711000Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] TypeOrmModule dependencies initialized +1ms
2021-08-19T09:33:10.881730600Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms
2021-08-19T09:33:10.881991300Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms
2021-08-19T09:33:10.882350300Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms
2021-08-19T09:33:10.882582100Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] TypeOrmModule dependencies initialized +1ms
2021-08-19T09:33:10.882789500Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms
2021-08-19T09:33:10.883074100Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms
2021-08-19T09:33:10.883345400Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] ExportModule dependencies initialized +0ms
2021-08-19T09:33:10.890401300Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] StateModule dependencies initialized +7ms
2021-08-19T09:33:10.890933600Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] AddressModule dependencies initialized +1ms
2021-08-19T09:33:10.892074100Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] ReferenceDataModule dependencies initialized +1ms
2021-08-19T09:33:10.892311200Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] AppModule dependencies initialized +0ms
2021-08-19T09:33:10.893340900Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] ReferralListModule dependencies initialized +1ms
2021-08-19T09:33:10.893563900Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] OrganizationModule dependencies initialized +1ms
2021-08-19T09:33:10.895690000Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] UserModule dependencies initialized +0ms
2021-08-19T09:33:10.895763900Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] AuthModule dependencies initialized +1ms
2021-08-19T09:33:10.895791200Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] ProviderModule dependencies initialized +0ms
2021-08-19T09:33:10.895816100Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] InvitationModule dependencies initialized +1ms
2021-08-19T09:33:10.938682900Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [RoutesResolver] AppController {/}: +42ms
2021-08-19T09:33:10.948952600Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [RouterExplorer] Mapped {/ping, GET} route +11ms
2021-08-19T09:33:10.951546300Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [RouterExplorer] Mapped {/info, GET} route +2ms
2021-08-19T09:33:10.954265700Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [RouterExplorer] Mapped {/healthcheck, GET} route +3ms
2021-08-19T09:33:10.954647600Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [RoutesResolver] ExportExcelController {/export/excel}: +0ms
2021-08-19T09:33:10.957700800Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [RouterExplorer] Mapped {/export/excel/:entity, GET} route +3ms
2021-08-19T09:33:10.958044800Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [RoutesResolver] SampleController {/}: +1ms
2021-08-19T09:33:10.960809700Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [RouterExplorer] Mapped {/sample/invitation, GET} route +3ms
2021-08-19T09:33:11.323526200Z (node:51) UnhandledPromiseRejectionWarning: FastifyError: Invalid options: Cannot find type User
2021-08-19T09:33:11.323568900Z at AsyncFunction.fastifyGraphQl.defineResolvers (/srv/api/node_modules/mercurius/index.js:344:15)
2021-08-19T09:33:11.323587600Z at AsyncFunction.fastifyGraphQl.defineLoaders (/srv/api/node_modules/mercurius/index.js:396:20)
2021-08-19T09:33:11.323611500Z at fp.name (/srv/api/node_modules/mercurius/index.js:414:20)
2021-08-19T09:33:11.323633300Z at Plugin.exec (/srv/api/node_modules/avvio/plugin.js:132:19)
2021-08-19T09:33:11.323655600Z at Boot.loadPlugin (/srv/api/node_modules/avvio/plugin.js:267:10)
2021-08-19T09:33:11.323677900Z at release (/srv/api/node_modules/fastq/queue.js:149:16)
2021-08-19T09:33:11.323701300Z at Object.resume (/srv/api/node_modules/fastq/queue.js:82:7)
2021-08-19T09:33:11.323724600Z at setup (/srv/api/node_modules/avvio/plugin.js:164:12)
2021-08-19T09:33:11.323747900Z at Plugin.loadedSoFar (/srv/api/node_modules/avvio/plugin.js:176:7)
2021-08-19T09:33:11.323771000Z at Boot._loadRegistered (/srv/api/node_modules/avvio/boot.js:227:17)
2021-08-19T09:33:11.323794100Z at Object.<anonymous> (/srv/api/node_modules/avvio/boot.js:390:20)
2021-08-19T09:33:11.323813300Z at processTicksAndRejections (internal/process/task_queues.js:95:5)
2021-08-19T09:33:11.323835000Z (Use `node --trace-warnings ...` to show where the warning was created)
2021-08-19T09:33:11.323856900Z (node:51) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
2021-08-19T09:33:11.323880400Z (node:51) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
and as you can see
2021-08-19T09:33:10.316809200Z [Nest] 51 - 08/19/2021, 9:33:10 AM LOG [InstanceLoader] MercuriusCoreModule dependencies initialized +1ms
loaded too, without NODE_ENV: production
everything is fine and the app starts as expected.
Thanks in advance.
Hi,
I've got nestjs-mercurius in use and everything is compiling and the server says it is listening, but connecting to the server isn't working or rather the server isn't available for connection. Is there a way to troubleshoot this in any way? Maybe a debug mode or something I'm not aware of by chance?
I also have to note, the issue has arisen after upgrading to NestJS v8. I can downgrade, but I'd also like to try and troubleshoot this further, if possible. Any tips would be greatly appreciated.
Scott
As discussed on #115 , to align with new Mercurius validationRule logic we need to avoid always returning validationRules as function. To do so, we need to remove ValidationRule as nestjs injectables
I have two services each with their federated graph. The first (main) publishes queries and mutations and a Message
type, the second (subscriptions) publishes one subscription that returns a Message
object. They are both connected through a redis pubsub.
For some reason, when subscribing (via apollo client in a react app) to that subscription through a mercurius gateway, the websocket receives a frame with payload {"type":"error","id":"1","payload":"service.createSubscription is not a function"}
and the subscription is never connected and thus never receives any messages;
I have a reproduction here: https://github.com/rhyek/graphql-federation-subscriptions-tests
federated Message
type: https://github.com/rhyek/graphql-federation-subscriptions-tests/blob/mercurius/apps/nest-apps/libs/types/src/message.type.ts
representative Message
class: https://github.com/rhyek/graphql-federation-subscriptions-tests/blob/mercurius/apps/nest-apps/apps/gql-subscriptions/src/message.resolver.ts#L13
gateway, main, and subscription nestjs apps at: https://github.com/rhyek/graphql-federation-subscriptions-tests/tree/mercurius/apps/nest-apps/apps
Btw, if I define another subscription that returns some new type owned by the subscriptions service, it works and the client can connect with no issues.
Hi,
it seems like that the @ResolveReference()
decorator is currently not supported. It is not picked up and added to the server.
I am trying to work on that, but if you have any idea where the problem is let me know! :)
I'm getting various issues installing the latest versions of Nest.js & Mercurius.
One being: https://github.com/nestjs/graphql/blob/master/package.json#L80
I'm not sure apollo-server-core
should even be a peerDependency. Perhaps this library needs to make all the optional dependencies optional using "peerDependenciesMeta"?
Hi,
With Mercurius, if you create two different Mercurius instances, it is possible to have two different paths (or more with more instances). For example, you could have most queries running over ./graphql
and have something like a refresh process (for jwt tokens) over a ./refresh
path (for tighter security).
Seems, if I try to do two different instances via forRoot
with nestjs-mercurius
the two instances both get the same schema defs causing a duplication error.
I'm wondering, would it be feasible to add, similar to what Nest does (which also doesn't work for code-first), to include and/ or exclude certain schema defs in the forRoot
config object?
For example, in the main instance you'd have:
@Module({
imports: [
// Work also with async configuration (MercuriusModule.forRootAsync)
MercuriusModule.forRoot({
path: './graphql`,
exclude: [RefreshResolver],
autoschemaFile: true,
context: (request, reply) => ({
user: request.user,
}),
subscription: {
context: (connection, request) => ({
user: request.user,
}),
},
}),
],
providers: [
CatResolver,
],
})
export class AppModule {}
and in the other instance:
@Module({
imports: [
// Work also with async configuration (MercuriusModule.forRootAsync)
MercuriusModule.forRoot({
path: './refresh`,
include: [RefreshResolver],
autoschemaFile: true,
context: (request, reply) => ({
user: request.user,
}),
}),
]
})
export class AppModule {}
Scott
I got error when building the project.
node_modules/nestjs-mercurius/node_modules/@apollo/gateway/src/make-fetch-happen.d.ts:58:18 - error TS2300: Duplicate identifier 'fetch'.
58 export default fetch;
~~~~~
node_modules/@apollo/gateway/src/make-fetch-happen.d.ts:58:18
58 export default fetch;
~~~~~
'fetch' was also declared here.
node_modules/@apollo/gateway/src/make-fetch-happen.d.ts:58:18 - error TS2300: Duplicate identifier 'fetch'.
58 export default fetch;
~~~~~
node_modules/nestjs-mercurius/node_modules/@apollo/gateway/src/make-fetch-happen.d.ts:58:18
58 export default fetch;
~~~~~
'fetch' was also declared here.
Found 9 errors.
Any idea how to fix the issue?
As per title, if you don't have this peer dependency, regardless of using federation or not, this module will not load.
Hey,
is it possible to add other plugins for Mercurius? I'm interested in the auth, cache and validation plugins. I see the upload and altair plugins are hardcoded. Maybe plugins could be made to be pluginable ๐?
Scott
Just starting a fresh project and installing dependencies as specified in the read me! but when trying to run i have this error and i don't understand why it is happening
I tried to search online for solution but nothin
i even include de apollo federation module but nothing
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.