当前位置: 首页 > 软件库 > 大数据 > 数据查询 >

graphql-api

Write type-safe GraphQL services in Haskell
授权协议 View license
开发语言 Java
所属分类 大数据、 数据查询
软件类型 开源软件
地区 不详
投 递 者 禹昊穹
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

graphql-api

graphql-api helps you implement a robust GraphQL API in Haskell. By the time a query makes it to your handler you are dealing with strong, static types that make sense for your problem domain. All your handlers are normal Haskell functions because we derive their type signature from the schema. If you have used servant, this will sound familiar.

The library provides type combinators to create a GraphQL schema, and functions to parse and evaluate queries against the schema.

You can find the latest release on hackage.

We implement the GraphQL specification as best as we can in Haskell. We figure they know what they're doing. Even if an alternative API or behaviour looks nicer, we will defer to the spec.

Tutorial

A simple graphql-api tutorial can be read at readthedocs.io.

To follow along and get your hands dirty, clone this repository, enter the graphql-api root directory, and run:

stack repl tutorial

Example

Say we have a simple GraphQL schema like:

type Hello {
  greeting(who: String!): String!
}

which defines a single top-level type Hello which contains a single field, greeting, that takes a single, required argument who.

We can define this schema in Haskell and implement a simple handler like so:

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}

import Data.Text (Text)
import Data.Monoid ((<>))

import GraphQL
import GraphQL.API
import GraphQL.Resolver (Handler, returns)

type Hello = Object "Hello" '[]
  '[ Argument "who" Text :> Field "greeting" Text ]

hello :: Handler IO Hello
hello = pure (\who -> returns ("Hello " <> who))

run :: Text -> IO Response
run = interpretAnonymousQuery @Hello hello

We require GHC 8.0.2 or later for features like the @Hello type application, and for certain bug fixes. We also support GHC 8.2.

With the code above we can now run a query:

run "{ greeting(who: \"mort\") }"

Which will produce the following GraphQL response:

{
  "data": {
    "greeting": "Hello mort"
  }
}

Status

Our current goal is to gather feedback. We have learned a lot about GraphQL in the course of making this library, but we don't know what a good GraphQL library looks like in Haskell. Please let us know what you think. We won't mind if you file a bug telling us how good the library is.

Because we're still learning, we make no guarantees about API stability, or anything at all really.

We are tracking open problems, missing features & wishlist items in GitHub's issue tracker.

Roadmap

  • Near future:
    • Better error messages (this is really important to us)
    • Full support for recursive data types
    • Close off loose ends in current implementation & gather feedback
  • Medium future:
    • Full schema validation
    • Schema introspection
    • Stabilize public API
  • Long term:
    • Derive client implementations from types
    • Allow users to implement their own type combinators

References

Copyright

All files Copyright (c) 2016-2017 Thomas E. Hunger & Jonathan M. Lange, except:

  • src/GraphQL/Internal/Syntax/AST.hs
  • src/GraphQL/Internal/Syntax/Encoder.hs
  • src/GraphQL/Internal/Syntax/Parser.hs

for which see LICENSE.BSD3 in this repository.

  •     最近一直使用graphQL开发接口,这个真的是很方便,再也不用给前端提供API文档啦。基础知识可以直接上官网https://graphql.cn/上学习一下即可。下面我记录一下,自己使用过程中觉得需要注意的细节。 1、每一个函数必须有输出,可以是对象、数组、字符、布尔值 2、输入参数中,若为必输参数,在参数后加! 3、GraphQL 支持的指令有两个:          @include(

  • GitHub API These days, we need to implement a tool to help our team get access to Github service so that we can analysis some data. When searching github API, we find something interesting and useful.

  • GraphQL 到底怎么用?看看这个例子就知道了 https://www.infoq.cn/article/i5JMm54_aWrRZcem1VgH

  • GQL是什么 graphQL是由Facebook开发的一种查询语言,用于替换REST Api。可以类比SQL也是一种查询语言。 GQL的好处 在客户端需求发生变更的时候,可以不需要通知服务端。理论上服务端可知的字段是大而全的,客户端只需要按照自己的需要去请求对应的字段。 多个客户端的请求可以合并为一个,减少网络请求次数 Overview翻译 http://facebook.github.io/gr

  • GraphQL是一个查询语言,由Facebook开发,用于替换RESTful API。服务端可以用任何的语言实现。具体的你可以查看Facebook关于GraphQL的文档和各种语言的实现 GraphQL的小历史 早在2012年,Facebook认为人们只有在离开PC的时候才会用智能手机,很快他们就发现这个认识是多么的错误!于是Facebook把注意力从Web移到了智能终端上。在那个时候,他们严重的

  • To query a GraphQL API, all you need to do is send an HTTP request that includes the query operation in the body of the request. In this lesson, we will use the browser’s fetch method to request the t

 相关资料
  • 快速开始 GraphQL 是一种用于 API 的查询语言。这是 GraphQL 和 REST 之间一个很好的比较 (译者注: GraphQL 替代 REST 是必然趋势)。在这组文章中, 我们不会解释什幺是 GraphQL, 而是演示如何使用 @nestjs/GraphQL 模块。 GraphQLModule 只不过是 Apollo 服务器的包装器。我们没有造轮子, 而是提供一个现成的模块, 这让

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

  • Graphql editor 是一款 Graphql 的可视化编辑器和 IDE,帮助用户更容易理解 GraphQL 模式,通过使用可视化块系统创建模式。GraphQL Editor 将把它们转化为代码。通过 GraphQL Editor,用户可以在不写任何代码的情况下创建可视化的图表,或者以一种很好的方式呈现其模式。 GraphQL View Code Editor View Hierarchy View

  • GraphQL CLI Help us to improve new GraphQL CLI. Check out the new structure and commands below!Feel free to contact us in Discord channel. We would love to hear your feedback. Features Helpful command

  • Fullstack GraphQL Simple Demo Application API built with Node + Express + GraphQL + Sequelize (supports MySQL, Postgres, Sqlite and MSSQL). WebApp built with React + Redux. Written in ES6 using Babel

  • Hasura GraphQL Engine Hasura is an open source product that accelerates API development by 10x by giving you GraphQL or REST APIs with built in authorization on your data, instantly. Read more at hasu

  • 这是利用Koa + GraphQL + Apollo-Server实现的,学生信息增、删、改、查的栗子 本栗子将搭配Koa实现一个GraphQL查询,逐步从简单Kao服务、到Mongodb的数据插入查询、再到GraphQL的使用,让大家快速看到: 搭建Koa搭建一个后台项目 后台路由简单处理方式 利用Mongoose简单操作Mongodb的增、删、改、查 掌握Apollo-Server简单操作数据

  • GraphQL Ruby 是 GraphQL 的一个 Ruby 实现。 Website API Documentation Newsletter 安装: # Gemfilegem 'graphql' $ bundle install 旨在: 实现 GraphQL 规范并支持一个 Relay 前端 在可能的情况下,提供与参考实现相似的习惯性的、简单的 Ruby API 支持 Ruby on Rails 和 Relay