数据查询语言:GraphQL.js
                 jopen
                 10年前
            
                    GraphQL.js (GraphQLJS)是 JavaScript 参考实现 GraphQL 的一个技术预览,非死book 开发的一种查询语言,用于在复杂的应用程序的数据模型中,描述数据要求。
使用示例:
从 npm 安装 GraphQL.js
npm install graphql
首先,建立GraphQL 型架构映射到你的代码库。
import {    graphql,    GraphQLSchema,    GraphQLObjectType,    GraphQLString  } from 'graphql';var schema = new GraphQLSchema({    query: new GraphQLObjectType({      name: 'RootQueryType',      fields: {        hello: {          type: GraphQLString,          resolve: () => 'world'        }      }    })  }); 然后,服务针对该类型架构的查询结果。
var query = '{ hello }';    graphql(schema, query).then(result => {  // Prints    // {    //   data: { hello: "world" }    // }    console.log(result);    }); 这将运行一个查询获取定义一个字段。graphql功能将首先确保查询语法和语义有效执行,否则报告错误。
var query = '{ boyhowdy }';    graphql(schema, query).then(result => {  // Prints    // {    //   errors: [    //     { message: 'Cannot query field boyhowdy on RootQueryType',    //       locations: [ { line: 1, column: 3 } ] }    //   ]    // }    console.log(result);    });