Skip to content

Commit f4e16a0

Browse files
ghostdogprUrigo
authored andcommitted
Simplify Caliban example and make it more readable
1 parent a400ac7 commit f4e16a0

File tree

1 file changed

+11
-15
lines changed
  • src/content/code/language-support/scala/server

1 file changed

+11
-15
lines changed

src/content/code/language-support/scala/server/caliban.md

+11-15
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,23 @@ github: ghostdogpr/caliban
77

88
An example of a GraphQL schema and query with `caliban`:
99
```scala
10+
import caliban.GraphQL.graphQL
11+
import caliban.RootResolver
12+
1013
case class Character(name: String, age: Int)
14+
1115
def getCharacters(): List[Character] = ???
16+
1217
// schema
1318
case class Queries(characters: List[Character])
19+
1420
// resolver
1521
val queries = Queries(getCharacters)
16-
import caliban.GraphQL.graphQL
17-
import caliban.RootResolver
18-
val api = graphQL(RootResolver(queries))
22+
23+
val query = "{ characters { name } }"
1924
for {
25+
api = graphQL(RootResolver(queries))
2026
interpreter <- api.interpreter
21-
} yield interpreter
22-
case class GraphQLResponse[+E](data: ResponseValue, errors: List[E])
23-
val query = """
24-
{
25-
characters {
26-
name
27-
}
28-
}"""
29-
for {
30-
result <- interpreter.execute(query)
31-
_ <- zio.console.putStrLn(result.data.toString)
32-
} yield ()
27+
result <- interpreter.execute(query)
28+
} yield result
3329
```

0 commit comments

Comments
 (0)