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

Type generator exists in middleware but is missing in Schema. #433

Open
Manubi opened this issue Aug 18, 2021 · 23 comments
Open

Type generator exists in middleware but is missing in Schema. #433

Manubi opened this issue Aug 18, 2021 · 23 comments

Comments

@Manubi
Copy link

Manubi commented Aug 18, 2021

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

@Manubi
Copy link
Author

Manubi commented Aug 18, 2021

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.

@todda00
Copy link

todda00 commented Aug 24, 2021

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

@PabloSzx
Copy link
Contributor

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

@Manubi
Copy link
Author

Manubi commented Aug 31, 2021

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! 🤗

@NoisyFlowers
Copy link

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,
})

@NoisyFlowers
Copy link

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

NoisyFlowers added a commit to paleobot/pbot-api that referenced this issue Sep 17, 2021
@PabloSzx
Copy link
Contributor

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

@balgamat
Copy link

"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 👏

@wangel13
Copy link

wangel13 commented Oct 26, 2021

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

@deadcoder0904
Copy link

deadcoder0904 commented Oct 27, 2021

Me too, same error 🙋‍♂️

However, downgrading to =6.0.9 solves it 👏

downgrading works :)

@PabloSzx
Copy link
Contributor

PabloSzx commented Oct 27, 2021

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

@martinnabhan
Copy link

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.

@paulmikulskis
Copy link

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

@harsh3977
Copy link

Facing same problem . Solved by downgrading middleware version 6.0.6.

@calboru
Copy link

calboru commented Nov 20, 2021

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

wangel13 added a commit to wangel13/prisma-next-auth-graphql-starter that referenced this issue Nov 22, 2021
@brandoniumNutrien
Copy link

facing this problem tried downgrading, recently upgraded to nextjs 12

@jgwiazdowski
Copy link

jgwiazdowski commented Jan 12, 2022

still same problem,
6.0.9 solves it

@Jl14Salvador
Copy link

Jl14Salvador commented Feb 16, 2022

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.

@nuronbeck
Copy link

nuronbeck commented Feb 20, 2022

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

With npm: npm uninstall graphql-middleware then do npm install [email protected]
With yarn: yarn remove graphql-middleware then do yarn add [email protected]

@hyusetiawan
Copy link

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?

@XTVB
Copy link

XTVB commented Jun 29, 2022

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.

@Janushan
Copy link

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!

@adhamsalama
Copy link

Any updates on this issue?

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