You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered an error with the codegenMercurius function that seems to be causing a problem with fastify-swagger.
When I include the codegenMercurius function in my code, it triggers an error in swagger-ui.
However, upon removing the codegenMercurius function, the fastify-swagger functionality resumes working as expected.
This issue is affecting my workflow, and I would appreciate any insights or solutions to resolve it. Thank you.
Errors:
ERROR (37310): .swagger() must be called after .ready()
My Code (app.ts):
import{join}from'path';importFastifyEnvfrom'@fastify/env';importFastifyCorsfrom'@fastify/cors';importFastifyAutoLoad,{AutoloadPluginOptions}from'@fastify/autoload';importFastifySwaggerfrom'@fastify/swagger';importFastifySwaggerUIfrom'@fastify/swagger-ui';import{FastifyPluginAsync,FastifyReply,FastifyRequest,FastifyServerOptions}from'fastify';importMercuriusfrom'mercurius';import{codegenMercurius}from'mercurius-codegen'import{resolvers}from'./graphql/resolvers';import{schema}from'./graphql/schema';exportinterfaceAppOptionsextendsFastifyServerOptions,Partial<AutoloadPluginOptions>{}// Pass --options via CLI arguments in command to enable these options.constoptions: AppOptions={}constbuildContext=async(req: FastifyRequest,_reply: FastifyReply)=>{return{authorization: req.headers.authorization}}typePromiseType<T>=TextendsPromiseLike<infer U> ? U : Tdeclare module 'mercurius'{interfaceMercuriusContextextendsPromiseType<ReturnType<typeofbuildContext>>{}}constapp: FastifyPluginAsync<AppOptions>=async(fastify,opts): Promise<void>=>{// This loads the .env file in the root directory.voidfastify.register(FastifyEnv,{dotenv: true,schema: {type: 'object',required: ['NODE_ENV','OPENSEARCH_NODE','OPENSEARCH_USER','OPENSEARCH_PASSWORD','MYSQL_HOST','MYSQL_PORT','MYSQL_USER','MYSQL_PASSWORD','MYSQL_DATABASE','MYSQL_CONNECTION_LIMIT',],}})// This loads the CORS plugin.voidfastify.register(FastifyCors,{origin: '*',methods: ['GET','PUT','POST','DELETE','OPTIONS','PATCH'],})// This loads fastify-swagger plugin.voidfastify.register(FastifySwagger,{swagger: {info: {title: 'HH Search API',description: 'API for HH Search using OpenSearch',version: '0.1.0'},externalDocs: {url: 'https://swagger.io',description: 'Find more info here'},host: 'localhost:3003',schemes: ['http','https'],consumes: ['application/json'],produces: ['application/json'],tags: [{name: 'client',description: 'Client related end-points'},{name: 'server',description: 'Server related end-points'}],definitions: {User: {type: 'object',required: ['id','email'],properties: {id: {type: 'string',format: 'uuid'},firstName: {type: 'string'},lastName: {type: 'string'},email: {type: 'string',format: 'email'}}}},securityDefinitions: {apiKey: {type: 'apiKey',name: 'apiKey',in: 'header'}}}})// This loads fastify-swagger-ui plugin.voidfastify.register(FastifySwaggerUI,{routePrefix: '/docs',uiConfig: {docExpansion: 'full',deepLinking: false},uiHooks: {onRequest: function(request: any,reply: any,next: any){next()},preHandler: function(request: any,reply: any,next: any){next()}},staticCSP: true,transformStaticCSP: (header: any)=>header,transformSpecification: (swaggerObject: any,request: any,reply: any)=>{returnswaggerObject},transformSpecificationClone: true})// This loads the mercurius plugin (GraphQL).voidfastify.register(Mercurius,{
schema,
resolvers,jit: 1,graphiql: 'graphiql',context: buildContext})// This code causing fastify-swagger ErrrorcodegenMercurius(fastify,{targetPath: './src/graphql/generated.ts',operationsGlob: './src/graphql/operations/*.gql',codegenConfig: {loadersCustomParentTypes: {Human: 'never',},},}).catch(console.error)// Do not touch the following lines// This loads all plugins defined in plugins// those should be support plugins that are reused// through your applicationvoidfastify.register(FastifyAutoLoad,{dir: join(__dirname,'plugins'),options: opts})// This loads all plugins defined in routes// define your routes in one of thesevoidfastify.register(FastifyAutoLoad,{dir: join(__dirname,'routes'),options: opts})};exportdefaultapp;export{app,options}
The text was updated successfully, but these errors were encountered:
I encountered an error with the codegenMercurius function that seems to be causing a problem with fastify-swagger.
When I include the codegenMercurius function in my code, it triggers an error in swagger-ui.
However, upon removing the codegenMercurius function, the fastify-swagger functionality resumes working as expected.
This issue is affecting my workflow, and I would appreciate any insights or solutions to resolve it. Thank you.
Errors:
My Code (app.ts):
The text was updated successfully, but these errors were encountered: