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

Mercurius-codegen throw error: error TS2304: Cannot find name '_Service'. #82

Open
bkjp opened this issue Aug 14, 2023 · 1 comment
Open

Comments

@bkjp
Copy link

bkjp commented Aug 14, 2023

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.

@jonnydgreen
Copy link
Collaborator

@bkjp I think you may have opened this in the wrong repo :) Could you close this issue and reopen in the mercurius-codegen repo?

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

2 participants