美文网首页
GraphQL初探

GraphQL初探

作者: ridox | 来源:发表于2018-02-05 19:27 被阅读57次

    简介

    GraphQL 既是一种用于 API 的查询语言也是一个满足你数据查询的运行时。 GraphQL 对你的 API 中的数据提供了一套易于理解的完整描述,使得客户端能够准确地获得它需要的数据,而且没有任何冗余,也让 API 更容易地随着时间推移而演进,还能用于构建强大的开发者工具。

    磨刀霍霍

    参考该文Grapph QL JS版Hello World,快速在Node平台上体验一把。

    • 安装Node.js
    • 安装GraphQL库 npm install graphql1
    • 添加hello.js文件 touch hello.js
    var { graphql, buildSchema } = require('graphql');
    
    var schema = buildSchema(`
      type Query {
        hello: String
      }
    `);
    
    var root = { hello: () => 'Hello world!' };
    
    graphql(schema, '{ hello }', root).then((response) => {
      console.log(response);
    });
    
    • 运行node hello.js
    • 效果如下:
      { data: { hello: 'Hello world!' } }

    相关文章

      网友评论

          本文标题:GraphQL初探

          本文链接:https://www.haomeiwen.com/subject/mlyizxtx.html