From 4bebd01c99a7e41106c82b576d16741bb477f980 Mon Sep 17 00:00:00 2001 From: Reid Mewborne Date: Wed, 7 Oct 2020 10:32:14 -0400 Subject: [PATCH 1/7] updated code to include caliban --- src/content/code/code.md | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/content/code/code.md b/src/content/code/code.md index 3383c51bf1..aed7301d2d 100644 --- a/src/content/code/code.md +++ b/src/content/code/code.md @@ -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\`: + +\`\`\`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 From 3b66ec3e5d27669282d9933e6148d9ef02c1cf6b Mon Sep 17 00:00:00 2001 From: Reid Mewborne Date: Wed, 7 Oct 2020 11:39:28 -0400 Subject: [PATCH 2/7] add to clients --- src/content/code/code.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/content/code/code.md b/src/content/code/code.md index aed7301d2d..f347ebcf57 100644 --- a/src/content/code/code.md +++ b/src/content/code/code.md @@ -646,6 +646,7 @@ for { - [Swift / Objective-C iOS](#swift-objective-c-ios) - [Python](#python-1) - [R](#r) +- [Scala](#scala) ### C# / .NET From 228781b649b2dc2e6b1c6fb80246d58a8bc92637 Mon Sep 17 00:00:00 2001 From: Reid Mewborne Date: Wed, 7 Oct 2020 10:32:14 -0400 Subject: [PATCH 3/7] updated code to include caliban --- src/content/code/code.md | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/content/code/code.md b/src/content/code/code.md index f347ebcf57..9da69eb473 100644 --- a/src/content/code/code.md +++ b/src/content/code/code.md @@ -628,6 +628,48 @@ for { \`\`\` +#### [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\`: + +\`\`\`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 From 70d346734df536ea41ea84aca1816635d35d0ac9 Mon Sep 17 00:00:00 2001 From: Reid Mewborne Date: Wed, 7 Oct 2020 10:32:14 -0400 Subject: [PATCH 4/7] updated code to include caliban --- src/content/code/code.md | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/content/code/code.md b/src/content/code/code.md index 9da69eb473..51ad16b8a9 100644 --- a/src/content/code/code.md +++ b/src/content/code/code.md @@ -670,6 +670,48 @@ for { \`\`\` +#### [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\`: + +\`\`\`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 From 7052d33c6dfa3971645f15c75630bf967b82f000 Mon Sep 17 00:00:00 2001 From: Reid Mewborne Date: Mon, 2 Nov 2020 20:15:14 -0500 Subject: [PATCH 5/7] cleanup --- src/content/code/code.md | 88 +--------------------------------------- 1 file changed, 2 insertions(+), 86 deletions(-) diff --git a/src/content/code/code.md b/src/content/code/code.md index 51ad16b8a9..c26e80e988 100644 --- a/src/content/code/code.md +++ b/src/content/code/code.md @@ -590,91 +590,7 @@ Executor.execute(schema, query) map println A simple example of a GraphQL schema and query with \`caliban\`: -\`\`\`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 () - -\`\`\` - -#### [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\`: - -\`\`\`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 () - -\`\`\` - -#### [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\`: - -\`\`\`scala +```scala case class Character(name: String, age: Int) def getCharacters(): List[Character] = ??? @@ -710,7 +626,7 @@ for { _ <- zio.console.putStrLn(result.data.toString) } yield () -\`\`\` +``` ### OCaml / Reason From 191802c4877504a7ba61f3c574c211df2efed9cc Mon Sep 17 00:00:00 2001 From: Reid Mewborne Date: Mon, 2 Nov 2020 20:18:06 -0500 Subject: [PATCH 6/7] add description for scala client --- src/content/code/code.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/content/code/code.md b/src/content/code/code.md index c26e80e988..897ec4fbf5 100644 --- a/src/content/code/code.md +++ b/src/content/code/code.md @@ -698,6 +698,10 @@ for { - [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. From acff35e8bdc943facb96829dd781fda55bb12c9f Mon Sep 17 00:00:00 2001 From: Reid Mewborne Date: Tue, 17 Nov 2020 11:06:55 -0500 Subject: [PATCH 7/7] adding comments and better wording --- src/content/code/code.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/content/code/code.md b/src/content/code/code.md index 897ec4fbf5..a53c95c929 100644 --- a/src/content/code/code.md +++ b/src/content/code/code.md @@ -588,32 +588,39 @@ 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\`: +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] = ??? -// schema +// 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]) -// resolver +// 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 {