graphql-shield: Types of property 'middlewares' are incompatible.

Bug report

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

Describe the bug

When using the most current versions of the graphql-yoga and graphl-shield libraries, trying to add shield({ ... }) to the middlewares option of the server creates this error:

image

(it keeps going for quite a while, just didn’t want to copy and paste five dozen lines)

To Reproduce

Copy and paste the Graphql Yoga example file. No changes are necessary for the error to pop up.

Additional context

graphql-yoga version: 1.16.2 graphql-shield version: 3.2.2

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 18 (8 by maintainers)

Most upvoted comments

As you say i updated graphql-yoga and now i’m getting:

Error: Cannot find module 'graphql-middleware'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/mnt/share/Git/aerobic-backend/node_modules/graphql-shield/src/shield.ts:1:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
[nodemon] app crashed - waiting for file changes before starting...

my updated package.json

"dependencies": {
  "apollo-errors": "^1.9.0",
  "bcryptjs": "^2.4.3",
  "graphql": "^14.0.2",
  "graphql-cli": "^2.16.7",
  "graphql-middleware-forward-binding": "^1.3.2",
  "graphql-shield": "^3.2.4",
  "graphql-yoga": "^1.16.2",
  "jsonwebtoken": "^8.3.0",
  "nodemailer": "^4.6.7",
  "npm-run-all": "^4.1.3",
  "prisma": "^1.17.1",
  "prisma-binding": "^2.1.6"
},

if i install it i get

Error: Type generator exists in middleware but is missing in Schema.

If i remove graphql-shield from middlewares all is working. Looks like some packages is conflict. But which. Removing ‘graphql-middleware-forward-binding’ from middlewares it is don’t cause any effect

Also then i yarn install i get some warnings:

warning " > graphql-middleware-forward-binding@1.3.2" has unmet peer dependency "graphql-middleware@^1.3.2".
warning "graphql-middleware-forward-binding > graphql-binding@2.2.5" has incorrect peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0".
warning "graphql-middleware-forward-binding > graphql-binding > graphql-import@0.5.3" has incorrect peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0".
warning "prisma-binding > graphql-tools@3.1.0" has incorrect peer dependency "graphql@^0.13.0".
warning " > graphql-shield@3.2.5" has unmet peer dependency "graphql-middleware@^1.6.4".
warning "prisma > prisma-cli-core@1.17.1" has incorrect peer dependency "graphql@^0.12.0 || ^0.13.0".
warning " > prisma-binding@2.1.6" has incorrect peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0".
warning "prisma-binding > apollo-link@1.2.2" has incorrect peer dependency "graphql@^0.11.3 || ^0.12.3 || ^0.13.0".
warning "prisma-binding > graphql-import@0.5.2" has incorrect peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0".
warning "prisma-binding > subscriptions-transport-ws@0.9.8" has incorrect peer dependency "graphql@^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.1".
warning " > prettier-tslint@0.4.0" has incorrect peer dependency "typescript@^2.5.3".

GOTCHA! Using graphql": "^0.13.2 don’t cause any error. And looks like i don’t need this package, so i remove that and everything work. Don’t know why i installed it, but it is he who conflicts.

That totally did the trick, @maticzav 💛 Thanks a bunches!! Can’t wait to try and test it out ✨

Hey @heymartinadams 👋,

No, having rules in a separate folder is completely fine. Peeking at your package.json again, however, I spotted you have a separate instance of graphql-middleware alongside graphql-yoga. Try removing that as well.

@kevrat perfect! I think we should add this to the README. graphql-middleware and graphql-yoga still haven’t been updated to the latest GraphQL which might cause the issue that you are describing.

I am so glad it’s working now 🎉