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

MiddlewareError: Type generator exists in middleware but is missing in Schema. #1350

Closed
1 task done
talentlessguy opened this issue Oct 30, 2021 · 4 comments
Closed
1 task done

Comments

@talentlessguy
Copy link

talentlessguy commented Oct 30, 2021

Bug report

  • I have checked other issues to make sure this is not a duplicate.

there are a few similar issues but they were closed without any solution:

Describe the bug

file:///home/v1rtl/Coding/x/api/node_modules/.pnpm/[email protected][email protected]/node_modules/graphql-middleware/dist/validation.mjs:10
      throw new MiddlewareError(`Type ${type} exists in middleware but is missing in Schema.`);
            ^

MiddlewareError: Type generator exists in middleware but is missing in Schema.
    at file:///home/v1rtl/Coding/x/api/node_modules/.pnpm/[email protected][email protected]/node_modules/graphql-middleware/dist/validation.mjs:10:13
    at Array.forEach (<anonymous>)
    at validateMiddleware (file:///home/v1rtl/Coding/x/api/node_modules/.pnpm/[email protected][email protected]/node_modules/graphql-middleware/dist/validation.mjs:8:27)
    at addMiddlewareToSchema (file:///home/v1rtl/Coding/x/api/node_modules/.pnpm/[email protected][email protected]/node_modules/graphql-middleware/dist/middleware.mjs:8:27)
    at normalisedMiddlewares.reduceRight.schema.schema (file:///home/v1rtl/Coding/x/api/node_modules/.pnpm/[email protected][email protected]/node_modules/graphql-middleware/dist/middleware.mjs:36:9)
    at Array.reduceRight (<anonymous>)
    at applyMiddlewareWithOptions (file:///home/v1rtl/Coding/x/api/node_modules/.pnpm/[email protected][email protected]/node_modules/graphql-middleware/dist/middleware.mjs:29:77)
    at applyMiddleware (file:///home/v1rtl/Coding/x/api/node_modules/.pnpm/[email protected][email protected]/node_modules/graphql-middleware/dist/middleware.mjs:51:10)
    at file:///home/v1rtl/Coding/x/api/graphql/schema.ts:23:17
    at ModuleJob.run (node:internal/modules/esm/module_job:183:25)

To Reproduce

import { makeExecutableSchema } from '@graphql-tools/schema'
import { applyMiddleware } from 'graphql-middleware'
import { shield, rule } from 'graphql-shield'
import { gql } from 'graphql-tag'

// Construct a schema, using GraphQL schema language.
let typeDefs = gql`
  type Query {
    hello: String
  }
`

const resolvers = {
  Query: {
    hello: () => 'Hello world!'
  }
}

const permissions = shield({
  Query: {
    hello: rule()(async () => {
      return false
    })
  }
})

const _schema = applyMiddleware(
  makeExecutableSchema({
    typeDefs,
    resolvers
  }),
  permissions
)

export const schema = applyMiddleware(_schema, permissions)
{
  "name": "api",
  "type": "module",
  "dependencies": {
    "@graphql-tools/schema": "^8.3.1",
    "graphql": "15.0.0",
    "graphql-middleware": "^6.1.11",
    "graphql-shield": "^7.5.0",
    "graphql-tag": "^2.12.5"
  },
  "devDependencies": {
    "@types/node": "^16.11.6",
    "tsm": "^2.1.4"
  }
}
$ tsm index.ts

Environment

  • Node.js 16.11
  • Linux x64
  • pnpm 6.17.2
@open-collective-bot
Copy link

Hey @talentlessguy 👋,

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 add priority label once you become one! 😄

@wangel13
Copy link

wangel13 commented Nov 4, 2021

I think it's connected with maticzav/graphql-middleware#433 and you can downgrade graphql-middleware to =6.0.9 to make it work.

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 16, 2022
@labelsync-manager labelsync-manager bot removed the stale label Apr 16, 2022
@XTVB
Copy link

XTVB commented Jun 29, 2022

isMiddlewareGenerator in graphql-middleware 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.

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

3 participants