-
Notifications
You must be signed in to change notification settings - Fork 538
use with ES6 modules triggers assertion in graphql #425
Comments
I've been investigating this and I don't have a solution, but I'll share what I found. The core of the problem is that there are two different ways to get a
When passing a schema created with I think that the solution would be to have a |
Ideally two things should happen:
|
- Test and example updates: - Use fake-tag for GraphQL template literals due to prettier/prettier#4360. - Use express instead of Koa packages. - Use express-graphql instead of Apollo packages. - Example updates: - Stop using esm due to graphql/express-graphql#425. - Enabled GraphiQL and added a link to it on the homepage.
- Test and example updates: - Use fake-tag for GraphQL template literals due to prettier/prettier#4360. - Use express instead of Koa packages. - Use express-graphql instead of Apollo packages. - Test updates: - Removed apollo-upload-server as there are no upload tests yet. - Example updates: - Stop using esm due to graphql/express-graphql#425. - Enabled GraphiQL and added a link to it on the homepage.
Relates to graphql#425. - Swapped deprecated babel-preset-es2015 for babel-preset-env. - Added package.json engines field. - Configured babel-preset-env to target the Node.js version defined in package.json engines field. - Kept Babel at v6, but moved config into a v7 ready .babelrc.js file for dynamic config via env. - Tidied the package.json scripts, added an ESM build step that generates .mjs dist files. Follow the lead of graphql/graphql-js#1244, although I do things quite different for my own projects with Babel v7. - Updated package.json main field for ESM/CJS cross compatibility. - Added a package.json module field for tree-shaking bundlers.
Until the smart people figure this out, I managed to work around this issue by using custom module loader: export function resolve(specifier, parentModuleURL, defaultResolver) {
const resolvedModule = defaultResolver(specifier, parentModuleURL);
if (specifier === 'graphql') {
resolvedModule.url = resolvedModule.url.replace('index.mjs', 'index.js');
resolvedModule.format = 'cjs';
}
return resolvedModule;
} This will force the cjs version of grahql. (see https://nodejs.org/api/esm.html#esm_loader_hooks on how to use it). You can actually extend the module loader further to force esm in your project. This will allow you to use |
- Test and example updates: - Use fake-tag for GraphQL template literals due to prettier/prettier#4360. - Use express instead of Koa packages. - Use express-graphql instead of Apollo packages. - Test updates: - Removed apollo-upload-server as there are no upload tests yet. - Example updates: - Stop using esm due to graphql/express-graphql#425. - Enabled GraphiQL and added a link to it on the homepage.
This library has been deprecated and this repo will be archived soon. It has been superseded by Furthermore, if you seek a fully-featured, well-maintained and performant server - I heavily recommend GraphQL Yoga! |
The following does not work, though it seems to me it should (node@9.8.0):
Creating a wrapper to
require
buildSchema instead:req.js
And changing the initial example:
works as expected:
The text was updated successfully, but these errors were encountered: