Skip to content

updated code to include caliban #927

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

Closed
wants to merge 7 commits into from
Closed
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
54 changes: 54 additions & 0 deletions src/content/code/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,55 @@ val query = graphql"{ hello }"
Executor.execute(schema, query) map println
```

#### [Caliban](https://ghostdogpr.github.io/caliban/) ([github](https://github.com/ghostdogpr/caliban)): Caliban is a purely functional library for building GraphQL servers and clients in Scala

An example of a GraphQL schema and query with \`caliban\`:

```scala
// Define a case class for our Schema
case class Character(name: String, age: Int)

def getCharacters(): List[Character] = ???
def getCharacter(name: String): Option[Character] = ???

// The schema is derived from our case class [[Character]]
// We use [[CharacterName]] to name our arguments.
case class CharacterName(name: String)
// Our Query schema is just a case class
case class Queries(characters: List[Character],
character: CharacterName => Option[Character])
// We build our Query schema by providing resolvers that satisfy our Queries case class
val queries = Queries(getCharacters, args => getCharacter(args.name))

import caliban.GraphQL.graphQL
import caliban.RootResolver

// Our first line of Caliban! pass your `queries` val to the RootResolver
// and give that to a function `graphQL` that returns a graphQL api.
val api = graphQL(RootResolver(queries))

// In order to process requests, you need to turn your API into an interpreter
for {
interpreter <- api.interpreter
} yield interpreter

case class GraphQLResponse[+E](data: ResponseValue, errors: List[E])

// Here is an example of querying your API with a console app.
val query = """
{
characters {
name
}
}"""

for {
result <- interpreter.execute(query)
_ <- zio.console.putStrLn(result.data.toString)
} yield ()

```

### OCaml / Reason

#### [ocaml-graphql-server](https://github.com/andreas/ocaml-graphql-server): GraphQL server library for OCaml and Reason
Expand All @@ -604,6 +653,7 @@ Executor.execute(schema, query) map println
- [Swift / Objective-C iOS](#swift-objective-c-ios)
- [Python](#python-1)
- [R](#r)
- [Scala](#scala)

### C# / .NET

Expand Down Expand Up @@ -655,6 +705,10 @@ Executor.execute(schema, query) map println

- [graphql-kotlin](https://github.com/ExpediaGroup/graphql-kotlin/): A set of GraphQL libraries that includes a lightweight, typesafe GraphQL HTTP client.

### Scala

- [Caliban](https://ghostdogpr.github.io/caliban/): Functional GraphQL library for Scala, with client code generation and type-safe queries.

### Swift / Objective-C iOS

- [Apollo iOS](https://www.apollographql.com/docs/ios/) ([github](https://github.com/apollographql/apollo-ios)): A GraphQL client for iOS that returns results as query-specific Swift types, and integrates with Xcode to show your Swift source and GraphQL side by side, with inline validation errors.
Expand Down