Skip to content

Commit 4480aae

Browse files
authored
Improve caliban (scala) examples (graphql#1494)
1 parent 310e3d9 commit 4480aae

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
---
22
name: Caliban
3-
description: Functional GraphQL library for Scala, with client code generation and type-safe queries.
3+
description: Caliban is a functional library for building GraphQL servers and clients in Scala. It offers with client code generation and type-safe queries.
44
url: https://ghostdogpr.github.io/caliban/
55
github: ghostdogpr/caliban
66
---
7+
8+
An example of defining a GraphQL query and running it with `caliban`:
9+
10+
```scala
11+
// define your query using Scala
12+
val query: SelectionBuilder[RootQuery, List[CharacterView]] =
13+
Query.characters {
14+
(Character.name ~ Character.nicknames ~ Character.origin)
15+
.mapN(CharacterView)
16+
}
17+
18+
import sttp.client3._
19+
// run the query and get the result already parsed into a case class
20+
val result = query.toRequest(uri"http://someUrl").send(HttpClientSyncBackend()).body
21+
```
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
---
22
name: Caliban
3-
description: Caliban is a purely functional library for building GraphQL servers and clients in Scala
3+
description: Caliban is a functional library for building GraphQL servers and clients in Scala. It offers minimal boilerplate and excellent interoperability.
44
url: https://ghostdogpr.github.io/caliban/
55
github: ghostdogpr/caliban
66
---
77

8-
An example of a GraphQL schema and query with `caliban`:
8+
An example of a simple GraphQL schema and query with `caliban`:
99

1010
```scala
11-
import caliban.GraphQL.graphQL
12-
import caliban.RootResolver
13-
14-
case class Character(name: String, age: Int)
15-
16-
def getCharacters(): List[Character] = ???
11+
import caliban._
12+
import caliban.schema.Schema.auto._
1713

1814
// schema
19-
case class Queries(characters: List[Character])
15+
case class Query(hello: String)
2016

2117
// resolver
22-
val queries = Queries(getCharacters)
18+
val resolver = RootResolver(Query("Hello world!"))
2319

24-
val api = graphQL(RootResolver(queries))
20+
val api = graphQL(resolver)
2521

2622
for {
2723
interpreter <- api.interpreter
28-
result <- interpreter.execute("{ characters { name } }")
24+
result <- interpreter.execute("{ hello }")
2925
} yield result
3026
```

0 commit comments

Comments
 (0)