GraphQL 所需的最低节点版本?

Minimum Required Node Version for GraphQL?

我正在尝试获取在 Node.js 环境中作为服务器工作的 GraphQL.js 的参考实现。请注意,我对 Node.js 的经验有限。现在,我正在使用 node v4.2.6,它是 Ubuntu 为 Ubuntu 16.04.

提供的最新软件包

The official documentation 说这个脚本应该可以工作:

var express = require('express');
var graphqlHTTP = require('express-graphql');
var { buildSchema } = require('graphql');

// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
  type Query {
    hello: String
  }
`);

// The root provides a resolver function for each API endpoint
var root = {
  hello: () => {
    return 'Hello world!';
  },
};

var app = express();
app.use('/graphql', graphqlHTTP({
  schema: schema,
  rootValue: root,
  graphiql: true,
}));
app.listen(4000);
console.log('Running a GraphQL API server at localhost:4000/graphql');

因语法错误而失败:

server.js:3
var { buildSchema } = require('graphql');
    ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3

The express-graphql project site shows a significantly different script, but one where I have to assemble a schema separately. The GraphQL.js project site 有这个用于组装模式的脚本:

import {
  graphql,
  GraphQLSchema,
  GraphQLObjectType,
  GraphQLString
} from 'graphql';

var schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'RootQueryType',
    fields: {
      hello: {
        type: GraphQLString,
        resolve() {
          return 'world';
        }
      }
    }
  })
});

这也因语法错误而失败:

server.js:1
(function (exports, require, module, __filename, __dirname) { import {
                                                              ^^^^^^

SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3

我猜 Node.js 的 v4.2.6 可能太旧了。那是对的吗?如果是这样,使用 GraphQL.js 和 express-graphql 所需的 Node.js 的最低版本是多少?而且,如果那不是我的问题...知道是什么吗?

t那个教程的 prerequisites 说:

Before getting started, you should have Node v6 installed [...]

虽然公平地说它继续:

[...] , although the examples should mostly work in previous versions of Node as well.

Node v4 不支持解构,这是它让你窒息的部分。您可以查看 node.green 以获取有关哪些 Node 版本支持哪些功能的参考。

That too fails with a syntax error:

import|export 在任何版本的 Node.js 中均不受支持。你必须转换它。或者你可以只使用 Node 的模块系统。为此,它应该类似于:

var graphqlModule = require("graphql");
var graphql = graphqlModule.graphql;
var GraphQLSchema = graphqlModule.GraphQLSchema;
// ...