Open odm275 opened 2 years ago
Hey @odm275 :wave:,
Thank you for opening an issue. We will get back to you as soon as we can. Have you seen our Open Collective page? Please consider contributing financially to our project. This will help us involve more contributors and get to issues like yours faster.
https://opencollective.com/graphql-shield
We offer
priority
support for all financial contributors. Don't forget to addpriority
label once you become one! :smile:
Bug report
Describe the bug
Getting error
ReferenceError: Cannot access 'nexusSchema' before initialization
on start up when running my app locally. When I removepermissions
fromexport const nexusSchema = applyMiddleware(baseSchema, permissions);
the server runs fine. Hence, it seems like the error is coming from graphql-shield.To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Repo: https://github.com/odm275/ayurveda-pom
export const baseSchema = makeSchema({ types: [types], outputs: { typegen: join( process.cwd(), "node_modules", "@types", "nexus-typegen", "index.d.ts" ), schema: join(process.cwd(), "apollo", "schema.graphql") }, contextType: { export: "Context", module: join(process.cwd(), "apollo", "createContext.ts") }, sourceTypes: { modules: [ { module: path.join(process.cwd(), "/database/types.ts"), alias: "db" } ] } });
export const permissions = shield({ Query: {}, Mutation: {} });
export const nexusSchema = applyMiddleware(baseSchema, permissions);
import { ApolloServer } from "apollo-server-micro"; import { PageConfig } from "next"; import { nexusSchema } from "../../apollo/schema"; import { createContext } from "../../apollo/createContext";
const apolloServer = new ApolloServer({ context: createContext, schema: nexusSchema });
const startServer = apolloServer.start(); export default async (req, res) => { res.setHeader("Access-Control-Allow-Credentials", "true"); res.setHeader( "Access-Control-Allow-Origin", "https://studio.apollographql.com" ); res.setHeader( "Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept" ); if (req.method === "OPTIONS") { res.end(); return false; } await startServer;
await apolloServer.createHandler({ path: "/api/graphql" })(req, res); };
// // Apollo Server Micro takes care of body parsing export const config: PageConfig = { api: { bodyParser: false } };
Expected behavior
I'm expecting my GraphQL server to be able to run and execute its mutations and queries as normal.
Actual behaviour
Any request to the server will return in the error
error - ReferenceError: Cannot access 'nexusSchema' before initialization
. The errorerror - unhandledRejection: Error: Type generator exists in middleware but is missing in Schema.
pops up sometimes too.Additional context