maticzav / graphql-middleware

Split up your GraphQL resolvers in middleware functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type generator exists in middleware but is missing in Schema.

Manubi opened this issue · comments

Hi,

since the graphql-middleware update to 6.1.2 I get the following error:
MiddlewareError: Type generator exists in middleware but is missing in Schema.
I do use graphql-shield v 7.5.0

CleanShot 2021-08-18 at 14 02 27@2x

Update: I think the error wars next.js experimental: { esmExternals: true },
At least for now it seems to work. For the latest version as well.

I'm running into the same error with anything above 6.0.10 Not using next.js, using webpack / babel (latest versions of both)

Update: I think the error wars next.js experimental: { esmExternals: true },
At least for now it seems to work. For the latest version as well.

I just tested a Next.js project using esmExternals: true and graphql-middleware and everything works fine, and I executed all the tests on ESM and nothing fails

I'm running into the same error with anything above 6.0.10 Not using next.js, using webpack / babel (latest versions of both)

We need a reproduction repo / instructions to be able to debug it, I really tried to find this issue by myself, I just tested a lot of things and nothing fails

Yeah sorry. I didn't dig deeper as I have things that I need to finish. If it shows up again I'll have a look as well.
Thanks for your work! 🤗

I'm encountering this same problem.

I'm new to this biome, so not sure what is important info to relay, but I'm using graphql-middleware 6.1.6, graphql-shield 7.5.0, apollo-server-express 2.25.2, and neo4j-graphql-js 2.19.4.

Screenshot 2021-09-16 133103

Relevant code bits (maybe). Note that makeAugmentedSchema comes from https://github.com/neo4j-graphql/neo4j-graphql-js (not sure if that's important):

const typeDefs = fs
  .readFileSync(
    //process.env.GRAPHQL_SCHEMA || path.join(__dirname, 'schema.graphql')
    process.env.GRAPHQL_SCHEMA || './schema.graphql'
  )
  .toString('utf-8');
  
const schema = makeAugmentedSchema({
      typeDefs: typeDefs
});

const isAuthenticated = rule({ cache: 'contextual' })(async (parent, args, ctx, info) => {
  return ctx.user !== null
});

const isAdmin = rule({ cache: 'contextual' })(async (parent, args, ctx, info) => {
  return ctx.user.roles.includes('admin');
});

const permissions = shield({
    Query: {
        "*": allow,
    },  
    Mutation: {
        "*":  and(isAuthenticated, isAdmin)
  },
})

const server = new ApolloServer({
  context:
    async ({ req }) => {
        console.log("setting up context");

		//get user from token
        const token = req.headers.authorization || '';
        const user = await getUser(driver, token);
		
        // Add the user to the context
        return { 
            user,
            driver,
            driverConfig: { database: process.env.NEO4J_DATABASE || 'neo4j' },
        };
    },   
  schema: applyMiddleware(schema, permissions),
  introspection: true,
  playground: true,
})

I've been trying different versions of graphql-middleware and am seeing the same as @todda00: the problem starts with 6.1.0.

as already mentioned, @NoisyFlowers can you create a minimal reproduction repo? I already tried a lot of stuff trying to reproduce it and I couldn't

"graphql-middleware": "^6.1.9",
"graphql-shield": "^7.5.0"

The same code works when ran in a standalone Apollo Server Micro, but when in Next.js (webpack, that is)...
image

Sadly, adding experimental: { esmExternals } to next.config.js did not help :/

However, downgrading to =6.0.9 solves it 👏

Same problem, i have a repo to reproduce: https://github.com/wangel13/prisma-next-auth-graphql-starter

error - node_modules/graphql-middleware/dist/validation.mjs (10:0) @ eval
Error: Type generator exists in middleware but is missing in Schema.
null

Me too, same error 🙋‍♂️

However, downgrading to =6.0.9 solves it 👏

downgrading works :)

Same problem, i have a repo to reproduce: https://github.com/wangel13/prisma-next-auth-graphql-starter

error - node_modules/graphql-middleware/dist/validation.mjs (10:0) @ eval
Error: Type generator exists in middleware but is missing in Schema.
null

Confirmed It's an issue with graphql-shield, since graphql-middleware ships an ESM version of the package and graphql-shield doesn't, it's just that graphql-middleware doesn't like duplicated versions of itself @maticzav

Same problem here, it worked fine with

  • graphql-middleware 6.1.9
  • graphql-shield 7.5.0
  • next 11.1.2

but after upgrading to next 12 we get the same above error.
Downgrading graphql-middleware to 6.0.9 fixed it.

I have this issue and the fix presented above.
OS: macOS 11.4
Node: 14.18.1
npm: 6.14.15
graphql-middleware: "^6.1.12"
graphql-shield: "^7.5.0"

changing the middleware loader to graphql-middleware: "6.0.9" fixed things

Facing same problem . Solved by downgrading middleware version 6.0.6.

Facing same problem . Solved by downgrading middleware version 6.0.6.
Are there any fix yet?

facing this problem tried downgrading, recently upgraded to nextjs 12

still same problem,
6.0.9 solves it

Reverting to version 6.0.9 and pinned it. Fixed my problem. Would love to see this fixed so I can update to the latest version.

To downgrade graphql-middleware package to 6.0.9, do command:

With npm: npm uninstall graphql-middleware then do npm install graphql-middleware@6.0.9
With yarn: yarn remove graphql-middleware then do yarn add graphql-middleware@6.0.9

commented

it seems downgrading is the only way to fix this issue right now. Can this be fixed on graphql-middleware side or is it because of interactions with libraries?

isMiddlewareGenerator is incorrectly returning false for graphql-shield permissions, which causes this error to occur in the validation.

If you replace applyMiddleware(schema, permissions) with applyMiddleware(schema, permissions.generate(schema)) then it will work correctly with the latest version of graphql-middleware, without needing to downgrade.

isMiddlewareGenerator is incorrectly returning false for graphql-shield permissions, which causes this error to occur in the validation.

If you replace applyMiddleware(schema, permissions) with applyMiddleware(schema, permissions.generate(schema)) then it will work correctly with the latest version of graphql-middleware, without needing to downgrade.

This worked for me!
Thanks!

Any updates on this issue?