Skip to content

Commit e4b8a12

Browse files
committed
Sync 20201112
1 parent 782a79c commit e4b8a12

File tree

3 files changed

+85
-4
lines changed

3 files changed

+85
-4
lines changed

src/content/code/code.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ GraphQL 已有多种编程语言支持。下表包含一些流行的服务端框
1212

1313
- [C# / .NET](#c#-/-.net)
1414
- [Clojure](#clojure)
15+
- [D](#d)
1516
- [Elixir](#elixir)
1617
- [Erlang](#erlang)
1718
- [Go](#go)
1819
- [Groovy](#groovy)
20+
- [Haskell](#haskell)
1921
- [Java](#java)
2022
- [JavaScript](#javascript)
2123
- [Kotlin](#kotlin)
@@ -60,6 +62,7 @@ public class Program
6062
- [Entity GraphQL](https://github.com/lukemurray/EntityGraphQL):针对 .NET Core 的 GraphQL 库。编译为 IQueryable 以轻松地从现有的数据模型(例如从 Entity Framework 数据模型)中暴露出 schema
6163
- [DotNetGraphQLQueryGen](https://github.com/lukemurray/DotNetGraphQLQueryGen):从 GraphQL schema 生成类,以在 dotnet 中进行类型安全的查询的 .NET Core 库
6264
- [Hot Chocolate](https://github.com/ChilliCream/hotchocolate):针对 .NET core 和 .NET classic 的 GraphQL 服务器
65+
- [NGraphQL](https://github.com/rivantsov/starwars):用于 .NET Core 和完整框架的 GraphQL 服务器
6366

6467
### Clojure
6568

@@ -128,6 +131,10 @@ $ curl -XPOST "http://0:3000" -H'Content-Type: application/json' -d'{
128131

129132
一套 GraphQL 规范的完整实现,致力于维护对规范的外部兼容。
130133

134+
### D
135+
136+
- [graphqld](https://github.com/burner/graphqld):D 编程语言的 GraphQL 实现。
137+
131138
### Elixir
132139

133140
- [absinthe](https://github.com/absinthe-graphql/absinthe):Elixir 的 GraphQL 实现。
@@ -165,6 +172,66 @@ $ curl -XPOST "http://0:3000" -H'Content-Type: application/json' -d'{
165172
#### [GQL](https://grooviter.github.io/gql/)
166173

167174
GQL 是一个在 Groovy 中使用 GraphQL 的库。
175+
176+
### Haskell
177+
178+
#### [Morpheus GraphQL](https://github.com/morpheusgraphql/morpheus-graphql)
179+
180+
用于构建 GraphQL API 的 Haskell 库。
181+
182+
一个使用 `morpheus-graphql` 的 hello world 示例:
183+
184+
```graphql
185+
# schema.gql
186+
"""
187+
A supernatural being considered divine and sacred
188+
"""
189+
type Deity {
190+
name: String!
191+
power: String @deprecated(reason: "no more supported")
192+
}
193+
type Query {
194+
deity(name: String! = "Morpheus"): Deity!
195+
}
196+
```
197+
198+
```haskell
199+
{-# LANGUAGE DeriveGeneric #-}
200+
{-# LANGUAGE DuplicateRecordFields #-}
201+
{-# LANGUAGE FlexibleContexts #-}
202+
{-# LANGUAGE FlexibleInstances #-}
203+
{-# LANGUAGE MultiParamTypeClasses #-}
204+
{-# LANGUAGE NamedFieldPuns #-}
205+
{-# LANGUAGE OverloadedStrings #-}
206+
{-# LANGUAGE ScopedTypeVariables #-}
207+
{-# LANGUAGE TemplateHaskell #-}
208+
{-# LANGUAGE TypeFamilies #-}
209+
module API (api) where
210+
import Data.ByteString.Lazy.Char8 (ByteString)
211+
import Data.Morpheus (interpreter)
212+
import Data.Morpheus.Document (importGQLDocument)
213+
import Data.Morpheus.Types (RootResolver (..), Undefined (..))
214+
import Data.Text (Text)
215+
importGQLDocument "schema.gql"
216+
rootResolver :: RootResolver IO () Query Undefined Undefined
217+
rootResolver =
218+
RootResolver
219+
{ queryResolver = Query {deity},
220+
mutationResolver = Undefined,
221+
subscriptionResolver = Undefined
222+
}
223+
where
224+
deity DeityArgs {name} =
225+
pure
226+
Deity
227+
{ name = pure name,
228+
power = pure (Just "Shapeshifting")
229+
}
230+
api :: ByteString -> IO ByteString
231+
api = interpreter rootResolver
232+
```
233+
234+
查看 [morpheus-graphql-examples](https://github.com/morpheusgraphql/morpheus-graphql) 了解更复杂的 API
168235

169236
### Java
170237

@@ -316,6 +383,7 @@ Apollo Server 也支持所有的 Node.js HTTP 服务器框架:Express、Connec
316383
### Kotlin
317384

318385
- [graphql-kotlin](https://github.com/ExpediaGroup/graphql-kotlin/):一组用于在 Kotlin 中运行 GraphQL 服务器的库。
386+
- [KGraphQL](https://github.com/aPureBase/KGraphQL):设置 GraphQL 服务器的一个纯 Kotlin 实现。
319387

320388
### Perl
321389

@@ -333,6 +401,8 @@ Apollo Server 也支持所有的 Node.js HTTP 服务器框架:Express、Connec
333401
- [Lighthouse](https://github.com/nuwave/lighthouse):一个用于 LaravelGraphQL 服务器
334402
- [GraphQLBundle](https://github.com/overblog/GraphQLBundle):一个用于 SymfonyGraphQL 服务器
335403
- [WPGraphQL](https://github.com/wp-graphql/wp-graphql):一个免费的开源 WordPress 插件,可为任何 WordPress 网站提供可扩展的 GraphQL schemaAPI
404+
- [GraphQL API for WordPress](https://github.com/GraphQLAPI/graphql-api-for-wp):WordPressGraphQL 服务器
405+
- [GraPHPinator](https://github.com/infinityloop-dev/graphpinator):现代 PHP 的一个 GraphQL 实现
336406

337407
#### [API Platform](https://api-platform.com) ([github](https://github.com/api-platform/api-platform))
338408

@@ -586,9 +656,11 @@ Executor.execute(schema, query) map println
586656

587657
- [C# / .NET](#c#-/-.net-1)
588658
- [Clojurescript](#clojurescript-1)
659+
- [Elixir](#elixir-1)
589660
- [Elm](#elm)
590661
- [Flutter](#flutter)
591662
- [Go](#go-1)
663+
- [Haskell](#haskell-1)
592664
- [Java / Android](#java-android)
593665
- [JavaScript](#javascript-1)
594666
- [Julia](#julia)
@@ -607,6 +679,11 @@ Executor.execute(schema, query) map println
607679

608680
- [re-graph](https://github.com/oliyh/re-graph/):一个在 Clojurescript 中实现的 GraphQL 客户端,支持 websockets
609681

682+
### Elixir
683+
684+
- [Neuron](https://github.com/uesteibar/neuron):ElixirGraphQL 客户端
685+
- [common_graphql_client](https://github.com/annkissam/common_graphql_client):支持 HTTPWebSocketElixir GraphQL 客户端
686+
610687
### Elm
611688

612689
- [dillonkearns/elm-graphql](https://github.com/dillonkearns/elm-graphql):一个库和命令行代码生成器,用于为 GraphQL 入口端点创建类型安全的 Elm 代码。
@@ -620,6 +697,10 @@ Executor.execute(schema, query) map println
620697
- [graphql](https://github.com/shurcooL/graphql#readme):一个使用 Go 编写的 GraphQL 客户端实现。
621698
- [machinebox/graphql](https://github.com/machinebox/graphql):用于 GraphQL 的一个优雅的底层 HTTP 客户端。
622699

700+
### Haskell
701+
702+
- [morpheus-graphql-client](https://github.com/morpheusgraphql/morpheus-graphql):使用 Haskell 的一个强类型 GraphQL 客户端实现。
703+
623704
### Java / Android
624705

625706
- [Apollo Android](https://github.com/apollographql/apollo-android):一个用于 JVMAndroidKotlin nativeGraphQL 客户端,强类型、带缓存功能。

src/content/learn/BestPractice-ThinkingInGraphs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ fragment previewInfo on Email {
6262
### 使用旧有的数据
6363
> 希望构建一个描述客户端如何使用数据的 GraphQL schema,而不是镜像旧有的数据库 schema。
6464
65-
有时候,你会发现自己正在使用不能完全反映客户端消费数据的旧有的数据源。在这种情况下,更倾向于构建一个描述客户端如何使用数据的 GraphQL schema,而不是镜像旧有的数据库 schema。
65+
有时候,你会发现自己正在使用不能完全反映客户端消费数据的旧有的数据源。在这种情况下,更倾向于构建一个描述客户端如何使用数据的 GraphQL schema,而不是镜像旧有的数据库 schema。
6666

67-
构建一个表达“是什么”而不是“怎么做”的 GraphQL schema。然后,您可以改进执行的具体细节,而不会破坏与旧客户端的接口。
67+
构建一个表达“怎么做”而不是“是什么”的 GraphQL schema。然后,您可以改进执行的具体细节,而不会破坏与旧客户端的接口。
6868

6969
## 一次一步
7070
> 更频繁地进行验证和获得反馈
7171
72-
不要试图一次就做一个模型来构建整个业务域而是一次只构建一个场景所需的部分 schema。渐渐地拓展 schema,你要更频繁地进行验证和获得反馈,以便寻找到构建的正确解决方案。
72+
不要试图一次就做一个模型来构建整个业务域而是一次只构建一个场景所需的部分 schema。渐渐地拓展 schema,你要更频繁地进行验证和获得反馈,以便寻找到构建的正确解决方案。

src/content/learn/Learn-Schema.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ union SearchResult = Human | Droid | Starship
305305

306306
在我们的schema中,任何返回一个 `SearchResult` 类型的地方,都可能得到一个 `Human`、`Droid` 或者 `Starship`。注意,联合类型的成员需要是具体对象类型;你不能使用接口或者其他联合类型来创造一个联合类型。
307307

308-
这时候,如果你需要查询一个返回 `SearchResult` 联合类型的字段,那么你得使用条件片段才能查询任意字段
308+
这时候,如果你需要查询一个返回 `SearchResult` 联合类型的字段,那么你得使用内联片段才能查询任意字段
309309

310310
```graphql
311311
# { "graphiql": true}

0 commit comments

Comments
 (0)