简单图形ql客户端

sgqlc的Python项目详细描述


简介

此软件包提供易于使用的graphql 客户端。它由以下模块组成:

  • sgqlc.types :在python中声明graphql,以生成和 解释查询。子模块 sgqlc.types.datetime 将 提供 datetime 和iso 8601的绑定,同时 sgqlc.types.relay 将公开 节点 页面信息 连接
  • sgqlc.operation :使用声明的类型生成和 解释查询。
  • sgqlc.endpoint :提供对graphql端点的访问,特别是 sgqlc.endpoint.http提供了使用 urllib.request.urlopen()

什么是graphql?

直接从http://graphql.org < Buff行情>

API的查询语言

graphql是一种api的查询语言,是实现 使用现有数据的查询。graphql提供了一个完整的 以及对api中的数据的可理解的描述,给出了 客户有权要求他们所需要的东西 更进一步,使随着时间的推移开发api变得更容易,并且 强大的开发工具。

它是Facebook根据他们的问题和解决方案创建的 休息 开发应用程序以使用它们的api。是公开的 宣布在 react.js conf 2015 从那以后就开始有吸引力了。现在有大牌 从rest转换到graphql: yelp 购物化 以及 github 杰出的 帖子 以解释它们为什么会改变。

与其他产品相比的优势列表:

  • 内置模式,带有文档、强类型和 反省。不用了 招摇过市 或任何其他要播放的外部工具 有了它。实际上,graphql为 探索graphql端点: https://github.com/graphql/graphiql
  • 只有你想要的字段。查询必须显式选择 字段是必需的,这就是您所得到的全部。如果有更多字段 添加到类型时,它们不会中断api,因为 字段不会返回给老客户,因为他们没有要求这样做 领域。这样可以更容易地保持api的稳定性,并避免 版本控制。标准rest通常在 结果,以及当要包含新字段时,一个新的api 添加版本(反映在url路径中);
  • 一个请求中的所有数据。而不是导航超媒体驱动 restful服务,比如发现新的链接: {"ref"… 和 执行新的http请求,使用graphql指定嵌套 查询并让服务器完成整个导航。这个 大大减少延迟;
  • 如果 您请求 {parent{child{info}} ,您将 接收json对象 {"parent":{"child":{"info":value}}

来自Github's 从rest迁移到graphql 人们可以在现实生活中看到这些:

$ curl -v https://api.github.com/orgs/github/members
[
  {
    "login": "...",
    "id": 1234,
    "avatar_url": "https://avatars3.githubusercontent.com/u/...",
    "gravatar_id": "",
    "url": "https://api.github.com/users/...",
    "html_url": "https://github.com/...",
    "followers_url": "https://api.github.com/users/.../followers",
    "following_url": "https://api.github.com/users/.../following{/other_user}",
    "gists_url": "https://api.github.com/users/.../gists{/gist_id}",
    "starred_url": "https://api.github.com/users/.../starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/.../subscriptions",
    "organizations_url": "https://api.github.com/users/.../orgs",
    "repos_url": "https://api.github.com/users/.../repos",
    "events_url": "https://api.github.com/users/.../events{/privacy}",
    "received_events_url": "https://api.github.com/users/.../received_events",
    "type": "User",
    "site_admin": true
  },
  ...
]

带来整套会员信息但是你只想知道名字 和虚拟形象的网址:

query {
  organization(login:"github") { # select the organization
    members(first: 100) {        # then select the organization's members
      edges {  # edges + node: convention for paginated queries
        node {
          name
          avatarUrl
        }
      }
    }
  }
}

同样,不要4个http请求:

curl -v https://api.github.com/repos/profusion/sgqlc/pulls/9
curl -v https://api.github.com/repos/profusion/sgqlc/pulls/9/commits
curl -v https://api.github.com/repos/profusion/sgqlc/issues/9/comments
curl -v https://api.github.com/repos/profusion/sgqlc/pulls/9/reviews

一个graphql查询会带来所有需要的信息,而 所需信息:

query {
  repository(owner: "profusion", name: "sgqlc") {
    pullRequest(number: 9) {
      commits(first: 10) { # commits of profusion/sgqlc PR #9
        edges {
          node { commit { oid, message } }
        }
      }
      comments(first: 10) { # comments of profusion/sgqlc PR #9
        edges {
          node {
            body
            author { login }
          }
        }
      }
      reviews(first: 10) { # reviews of profusion/sgqlc/ PR #9
        edges { node { state } }
      }
    }
  }
}

创建sgqlc的动机

如上所述,编写graphql查询非常简单 为了解释结果, 创建sgqlc的基本原理是什么?

未来的计划包括从graphql生成python类 架构,可以使用 自省查询。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java出现编译错误,我不理解   java在gnu-trove库中是否有任何有序映射?   java Servlet应该有映射,但找不到Servlet   java时间和第二期显示1:10,而不是13:10   java Play Framework 1.2.7 Heroku更新崩溃   线程“main”java中的opencsv异常。lang.NoClassDefFoundError:org/apache/commons/lang3/ObjectUtils   selenium在java中隐藏警告消息   java使用ID引用将JSON实体反序列化为POJO   java无法在JRE 8中加载字体   一个线程中的异常/错误会使整个应用程序停止吗?   java访问重复子规则的元素标签;e、 g.用ANTLR解析(1,2,3)中的a   java如何从平移旋转中找到新坐标   使用HTML Java小程序托管jar文件存在安全问题   java如何按频率而不是字母顺序排列字符串数组   java清除bufferedReader和块以获得更多输入   java解密SAML2断言