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 6 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
47 changes: 47 additions & 0 deletions src/content/code/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,48 @@ 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

A simple example of a GraphQL schema and query with \`caliban\`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love the word simple here (here's a good talk from Jim Fisher that explains why). Maybe instead, it could briefly summarize what's happening in the schema/query?


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

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

// schema
case class CharacterName(name: String)
case class Queries(characters: List[Character],
character: CharacterName => Option[Character])
// resolver
val queries = Queries(getCharacters, args => getCharacter(args.name))

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 ()

```

### OCaml / Reason

#### [ocaml-graphql-server](https://github.com/andreas/ocaml-graphql-server): GraphQL server library for OCaml and Reason
Expand All @@ -604,6 +646,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 +698,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