Closed jontonsoup closed 8 years ago
I am pretty sure it's not a problem with graffiti. It's published as transpiled ES5.
@tothandras I think theres a runtime dependency if you use any generators
You need to include the regenerator runtime or the 6to5 polyfill. It's not possible to implement generators without a runtime as the code to manage execution flow is quite lengthy.
From: https://github.com/babel/babel/issues/303
It could be something graffiti depends on?
koa, maybe?
I'm not running any of the koa code, so I'm not sure.
co-body? I am really not sure.
Yea, it could be. I just wanted to log the error in case anyone else ran into it.
:+1:
Could be koa, but I've got a feeling I've seen this with one of the facebook modules before. Could you get a stack trace?
@burkhardr I've checked it since, koa is only a dev dependency.
Its funny -- it bubbles up through the response so its not a transpile - time error -- its caught somewhere during runtime.
Yeah, I think one of the fb modules is using a generator (don't ask me why). Could you put
var gm = require('@risingstack/graffiti-mongoose');
var schema = gm.getSchema([/* your models */]);
into a file and run it?
@burkhardr I added those lines to a new file and I did not get an error. I was getting this error at runtime during the graphql query.
Try to run that query in your test file:
graphql(schema, query).then(function (result) {
console.log(result);
});
var gm = require('@risingstack/graffiti-mongoose')
var user = require('./build/models/user');
var schema = gm.getSchema([user]);
var graphql = require('graphql');
var query = "{users{email}}";
graphql.graphql(schema, query)
.then(result => { console.log(result); })
.catch((result) => { console.log(result);});
Strangely not getting any output now on a valid query. On an invalid query, it throws an error. Might be something is wrong with my testfile, but its hard to tell.
As an aside, I'm using babel 6 with the 2015 package but running my code with normal node. I've been having sporadic issues between packages that depend on babel 5 and how they interact with my code-- not sure if this is related or not really, though.
Make sure you connect to mongodb!
@burkhardr whoops good catch!
Here's the error I was expecting, now that mongo is connected.
{ data: { users: [ [Object] ] },
errors: [ { [Error: regeneratorRuntime is not defined] message: 'regeneratorRuntime is not defined' } ] }
Still pretty sure this is coming from one of the fb modules. Have you tried adding import babelPolyfill from 'babel-core/polyfill';
to the top of your entry script?
My .babelrc
:
{
"stage": 0,
"optional": [
"es7.objectRestSpread",
"es7.decorators",
"es7.classProperties",
"es7.asyncFunctions",
"runtime",
],
}
haha -- I thought you were trying to debug the problem on your end with graffiti. Yes, that actually is the solution that fixed my problem. I created an issue because I didn't need the polyfil before I started using griffiti, even though I was using graphql before that with no problem. It seemed strange to me that installing a library would require me to use the polyfil / break other libraries.
I retract everything I might've said about that mysterious fb module and claim the opposite :grin:
Looks like it's coming from babel generated code that transpiles async await
and expects regeneratorRuntime
to be in the global namespace. Looks like there's no way around the polyfill.
https://babeljs.io/repl/#?experimental=false&evaluate=true&loose=false&spec=false&code=async%20function%20blah()%20%7B%0A%20%20await%20blub()%3B%0A%7D%0A
@tothandras Something for the docs perhaps?
hahaha no worries :)
Running on this very same issue, sample code here: https://gist.github.com/cilindrox/dae6fdc21da902613aa9
@cilindrox babel-polyfill
is required at this point. I am still migrating to babel 6 (having problem with some mocks in tests), I don't know if it has the same requirements.
Gotcha. That seemed to do the trick. Thanks!
babel-polyfill
has been added to the peer dependencies of graffiti-mongoose
in version 5.x.x
.
Hi! I'm getting the same error, but I'm not using babel.
The thing is that I'm using Node 4, so this functions should be already integrated.
The only workaround that I found for this was adding "regenerator" like this
global.regeneratorRuntime = require('regenerator/runtime');
Do you thing that there's a better way to fix this?
Thanks!
@LucianoGanga Hi! babel-polyfill
has been added to the peer dependencies of graffiti-mongoose
, so it's not a fix, but necessary to require the babel-polyfill
at the top of the entry point in your application.
Thanks @tothandras ! Just calling require('babel-polyfill');
did the work, as you said.
Have a nice day! :D
I have add import 'babel-polyfill';
I'm using babel 6 with the normal 2015 presets.
When I try to make any queries on my schema,
I get this result:
I fixed this using by adding the babel polyfill to my code.
http://babeljs.io/docs/usage/polyfill/
This seems like it should be a dependency of graffiti-- not my application?
Thanks! Jon