Open
Description
I am using @mercuriusjs/federation and mercurius-codegen to build a subgraph. I follow implementation directed by the doc. But always get the following errors
src/__generated-types__.ts:209:33 - error TS2304: Cannot find name '_Service'.
209 _Service: ResolverTypeWrapper<_Service>;
~~~~~~~~
src/__generated-types__.ts:223:13 - error TS2304: Cannot find name '_Service'.
223 _Service: _Service;
~~~~~~~~
src/__generated-types__.ts:277:19 - error TS2304: Cannot find name 'Query_entitiesArgs'.
277 RequireFields<Query_entitiesArgs, "representations">
~~~~~~~~~~~~~~~~~~
src/__generated-types__.ts:356:52 - error TS2304: Cannot find name '_Service'.
356 sdl?: LoaderResolver<Maybe<Scalars["String"]>, _Service, {}, TContext>;
In my code typescript is not angry anywhere.
Here is my server.ts file
import Fastify, { FastifyRequest, FastifyReply } from "fastify";
import mercurius from "mercurius";
import mercuriusCodegen from "mercurius-codegen";
import { buildFederationSchema } from "@mercuriusjs/federation";
//
import { userTypeDefs } from "./user/user.schema";
import { userResolvers } from "./user/user.resolvers";
//###########################################################################
const app = Fastify();
const PORT = 4001;
const buildContext = async (req: FastifyRequest, _reply: FastifyReply) => {
return {
authorization: req.headers.authorization,
};
};
type PromiseType<T> = T extends PromiseLike<infer U> ? U : T;
declare module "mercurius" {
interface MercuriusContext
extends PromiseType<ReturnType<typeof buildContext>> {}
}
app.register(mercurius, {
schema: buildFederationSchema(userTypeDefs, {
isGateway: false,
}),
resolvers: userResolvers,
context: buildContext,
});
mercuriusCodegen(app, {
// Commonly relative to your root package.json
targetPath: "./src/__generated-types__.ts",
// operationsGlob: "./src/graphql/operations/*.gql",
// codegenConfig: {
// loadersCustomParentTypes: {
// Human: "never",
// },
// },
}).catch(console.error);
// Start server
app.get("/", async function (req, reply) {
const query = "{ _service { sdl } }";
return app.graphql(query);
});
app.listen({ port: PORT });
I don't know what is going wrong there. I cannot modify generated-types.ts file since it is generated automatically when I start the server.
Metadata
Metadata
Assignees
Labels
No labels