Skip to content

Improve example for Caliban #971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/content/code/language-support/scala/server/caliban.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,23 @@ github: ghostdogpr/caliban

An example of a GraphQL schema and query with `caliban`:
```scala
import caliban.GraphQL.graphQL
import caliban.RootResolver

case class Character(name: String, age: Int)

def getCharacters(): List[Character] = ???

// schema
case class Queries(characters: List[Character])

// resolver
val queries = Queries(getCharacters)
import caliban.GraphQL.graphQL
import caliban.RootResolver

val api = graphQL(RootResolver(queries))

for {
interpreter <- api.interpreter
} yield interpreter
case class GraphQLResponse[+E](data: ResponseValue, errors: List[E])
val query = """
{
characters {
name
}
}"""
for {
result <- interpreter.execute(query)
_ <- zio.console.putStrLn(result.data.toString)
} yield ()
result <- interpreter.execute("{ characters { name } }")
} yield result
```