GraphQL 简介

  • 介绍

    • GraphQL 查询时结构化的,信息是类树结构展示的。值类型可以理解为叶子,对象类型可以理解为树干
    • GraphQL 是一种描述如何请求数据的语法,通常用于客户端向服务器请求数据。
    • GraphQL 层位于客户端和一个或多个数据源之间,按照你的指示接收客户端请求,然后获取必要的数据。
    • GraphQL API 围绕三个主要构建块组织:模式(schema)、查询(query)、解析器(resolver)。
    • GraphQL 只是一个规范
  • 特点

    • 允许客户端精确指定所需数据。
    • 可以更容易地从多个数据源聚合数据。
    • 使用类型系统描述数据。
  • 解决的问题

    • 无需加载冗余信息
  • 解决方案

    • 不再使用多个“愚蠢”端点,而是使用可以处理复杂查询、根据客户端需求拼合数据的单个“智能”端点。
  • 构建模块

    • 查询(query)

      • 介绍
        • 通过query关键字声明新查询
        • 支持嵌套
        • 查询字段可以执行数组
        • 查询字段支持参数
        • 参数支持动态化
      • demo
          普通查询
          **query** {
            stuff {
              eggs
              shirt
              pizza
            }
          }
          查询字段包含数组
          **query** {
            posts { _# this is an array_
              title
              body
              author { _# we can go deeper!_
                name
                avatarUrl
                profileUrl
              }
            }
          }
          查询字段包含参数
          **query** {
            post(id: "123foo"){
              title
              body
              author{
                name
               avatarUrl
                profileUrl
              }
            }
          }
          参数动态化
          **query** getMyPost($id: String) {
            post(id: $id){
              title
              body
              author{
                name
                avatarUrl
                profileUrl
              }
            }
          }
      
    * 解析器(resolver)
    * 模式(schema)
    
    
  • 相关资料

    • http://www.zcfy.cc/article/so-what-s-this-graphql-thing-i-keep-hearing-about-freecodecamp-2719.html
    • https://developer.github.com/v4/explorer/ GraphQL API Explorer
    • https://github.com/apollographql/apollo-ios apollo-ios
    • http://dev.apollodata.com/ios/ apollo-ios 文档
    • https://github.com/apollographql/frontpage-server node server
    • https://github.com/apollographql/graphql-tools graphql-toolsx
    • https://www.youtube.com/watch?v=7a5b4M9Bjd4 视频 apollo-ios

你可能感兴趣的:(GraphQL 简介)