Closed kieusonlam closed 5 years ago
You need to install graphql-middleware
as a dependency yourself.
Ya, I tried. It lead to another issue
C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\validation.js:24
throw new MiddlewareError("Type " + type + " exists in middleware but is missing in Schema.");
^
Error: Type generator exists in middleware but is missing in Schema.
at new MiddlewareError (C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\validation.js:49:23)
at C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\validation.js:24:19
at Array.forEach (<anonymous>)
at Object.validateMiddleware (C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\validation.js:22:29)
at addMiddlewareToSchema (C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\middleware.js:19:40)
at normalisedMiddlewares.reduceRight.schema (C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\middleware.js:57:18)
at Array.reduceRight (<anonymous>)
at applyMiddlewareWithOptions (C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\middleware.js:55:77)
at applyMiddleware (C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\middleware.js:84:39)
at new GraphQLServer (C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\dist\index.js:116:59)
It did not work like this on 1.16.2
Seems like you should read the docs / changelog.
Same thing for me, definitely some form of dependency bug. Switching back to graphql-yoga@1.16.2
helps.
@kieusonlam @impowski I had problems lately inside a lerna monorepo with create-react-app
v2. Somehow between that, yarn workspaces, etc the dependancy graph got messed and I hit the same errors. After messing with it a bit and refreshing everything it now seems to work fine with the following:
"graphql": "14.0.2",
"graphql-shield": "4.1.0",
"graphql-yoga": "1.16.7",
Should be no need to install graphql-middleware
as it's listed as a dependancy. I included graphql-shield
because i was having issues with that as well. So if you're using lerna/yarn workspaces I suspect your dependancy graph is messed up and/or you have conflicting versions of graphql
.
`
`
@bmirkalami Usually an "Unexpected token import" points to a problem in the transpile. Are you using babel to transpile ES6/7 code? If not, you'll need to use const { GraphQLServer } = require("graphql-yoga");
@danielmahon I uncommented that line of code that you specified in index.js and attempted to reinstall npm graphql-yoga, but encountered identical issues.
@bmirkalami Please correct me if I'm wrong but it seems like you might be unfamiliar with how to properly use "technically" experimental javascript syntax, like import
. You cannot run node index.js
on a file with an import statement. That syntax is not supported in node...yet. You need to compile that code to something node can understand. The most common way to do that is by using https://babeljs.io/. I would suggest looking at babel's site and on Stack Overflow for more information about how to do this: https://stackoverflow.com/questions/45854169/how-can-i-use-an-es6-import-in-node, but this issue is not the place for that discussion. IMHO It's defintely worth knowing the babel ecosystem and how to use it properly, a bit confusing at first but makes life MUCH easier in the long run when working in the browser and in node. Good luck! 😉
@danielmahon You are right; I am a complete newbie. But this is just a simple installation of the GraphQL Yoga playground for the first time ever on a fresh Ubuntu 18.04 machine. It has nothing to do with a transpile issue. I have followed the instructions in the following video: www.youtube.com/watch?v=rpJO0T08Bnc while replacing the Ubuntu specific differences from these guys: https://www.youtube.com/watch?v=b8v8SxCrPTo
@bmirkalami You said you "uncommented" the require syntax. Did you then remove the "import" line in all required files?
const { GraphQLServer } = require('graphql-yoga')
const typeDefs = `
type Query {
hello(name: String): String!
}
`
const resolvers = {
Query: {
hello: (_, { name }) => `Hello ${name || 'World'}`,
},
}
const server = new GraphQLServer({ typeDefs, resolvers })
server.start(() => console.log('Server is running on localhost:4000'))
Also, are you having the same error as the original issue? Or still have the "Unexpected token import"
error? If youre still getting the import error then you are missing an import line somewhere. If its the original issue then YAY, we're back to the original issue but Im not exactly sure how to help as dependancies can be tricky if they get out of whack, when in doubt delete the node_modules
folder and package-lock.json/yarn.lock
files. Then try reinstalling the latest graphql-yoga
. Outside of that Im not sure I can help at the moment.
@danielmahon The error is the same as far as I can see.
@bmirkalami remove line 1 completely. Node cannot understand that.
@danielmahon I did that, but still getting the identical set of errors. Should I, "delete the node_modules folder and package-lock.json/yarn.lock files. Then try reinstalling the latest graphql-yoga?" Or is there something else I should do? Sorry for being such a persistent questioner, but I don't want to have this attempt at learning to be a failure like the previous attempts.
@danielmahon I tried deleting the node_modules folder and reinstalling graphql-yoga but no luck (exact same errors).
@bmirkalami I understand completely, we've all been there 😕. But this conversation no longer belongs on this issue. I would recommend posting the same question on stack overflow or for more "potentially" quicker responses try Node's Discord channel https://discordapp.com/invite/vUsrbjd and more at https://nodejs.org/en/get-involved/#learning
Thanks @danielmahon it's working for me.
@kieusonlam Was your issue the same as mine?
@bmirkalami no, I didn't get that issue. As @danielmahon said, I think you not using webpack + babel + ES5/6/7, you won't have the "import" systax.
Replace
import { GraphQLServer } from 'graphql-yoga'
with
const { GraphQLServer } = require('graphql-yoga')
should make it work.
I had the same issue and I fixed it just now. The problem was not in any transpiling error as mentioned here, I solved it by running npm install
rather than yarn install
. I just wanted to offer my fix to any other person running into the same problem in the future.
What worked for me was deleting yarn.lock
and installing again.
I get
Error: Cannot find module 'graphql-middleware'
after update graphql-yoga 1.16.2 to higher version any idea?