-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add federation 2.6 support, update gateway dependencies (#2043)
- Loading branch information
1 parent
81d9b9d
commit 9dd2287
Showing
10 changed files
with
56 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 9 additions & 65 deletions
74
examples/src/main/scala/example/federation/FederatedApp.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,19 @@ | ||
package example.federation | ||
|
||
import caliban.quick._ | ||
import example.federation.FederationData.characters.sampleCharacters | ||
import example.federation.FederationData.episodes.sampleEpisodes | ||
import caliban.Http4sAdapter | ||
import caliban.interop.tapir.HttpInterpreter | ||
import cats.data.Kleisli | ||
import com.comcast.ip4s._ | ||
import fs2.io.net.Network | ||
import org.http4s.StaticFile | ||
import org.http4s.implicits._ | ||
import org.http4s.server.Router | ||
import org.http4s.ember.server.EmberServerBuilder | ||
import org.http4s.server.middleware.CORS | ||
import zio._ | ||
import zio.interop.catz._ | ||
|
||
object FederatedApp extends CatsApp { | ||
import sttp.tapir.json.circe._ | ||
object FederatedApp extends ZIOAppDefault { | ||
|
||
type ExampleTask[A] = RIO[Any, A] | ||
|
||
private implicit val network: Network[ExampleTask] = Network.forAsync | ||
|
||
val service1 = | ||
CharacterService | ||
.make(sampleCharacters) | ||
.memoize | ||
.flatMap(layer => | ||
for { | ||
interpreter <- FederatedApi.Characters.api.interpreter.map(_.provideLayer(layer)) | ||
_ <- EmberServerBuilder | ||
.default[ExampleTask] | ||
.withHost(host"localhost") | ||
.withPort(port"8089") | ||
.withHttpApp( | ||
Router[ExampleTask]( | ||
"/api/graphql" -> CORS.policy(Http4sAdapter.makeHttpService(HttpInterpreter(interpreter))), | ||
"/graphiql" -> Kleisli.liftF(StaticFile.fromResource("/graphiql.html", None)) | ||
).orNotFound | ||
) | ||
.build | ||
.toScopedZIO | ||
_ <- Console.printLine("Server online at http://localhost:8089/\nPress RETURN to stop...") | ||
_ <- Console.readLine | ||
} yield () | ||
) | ||
|
||
val service2 = | ||
EpisodeService | ||
.make(sampleEpisodes) | ||
.memoize | ||
.flatMap(layer => | ||
for { | ||
interpreter <- FederatedApi.Episodes.api.interpreter.map(_.provideLayer(layer)) | ||
_ <- EmberServerBuilder | ||
.default[ExampleTask] | ||
.withHost(host"localhost") | ||
.withPort(port"8088") | ||
.withHttpApp( | ||
Router[ExampleTask]( | ||
"/api/graphql" -> CORS.policy(Http4sAdapter.makeHttpService(HttpInterpreter(interpreter))), | ||
"/graphiql" -> Kleisli.liftF(StaticFile.fromResource("/graphiql.html", None)) | ||
).orNotFound | ||
) | ||
.build | ||
.toScopedZIO | ||
_ <- Console.printLine("Server online at http://localhost:8088/\nPress RETURN to stop...") | ||
_ <- Console.readLine | ||
} yield () | ||
) | ||
val episodesApi = FederatedApi.Episodes.api.runServer(8089, "/api/graphql", Some("/graphiql")) | ||
val charactersApi = FederatedApi.Characters.api.runServer(8088, "/api/graphql", Some("/graphiql")) | ||
|
||
override def run = | ||
(service1 race service2).exitCode | ||
(episodesApi zipPar charactersApi) | ||
.provide( | ||
EpisodeService.make(sampleEpisodes), | ||
CharacterService.make(sampleCharacters) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/src/main/scala/example/federation/v2/FederationData.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
federation/src/main/scala/caliban/federation/v2x/FederationDirectivesV2_6.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package caliban.federation.v2x | ||
|
||
import caliban.InputValue.ListValue | ||
import caliban.Value.StringValue | ||
import caliban.parsing.adt.Directive | ||
import caliban.schema.Annotations.GQLDirective | ||
|
||
trait FederationDirectivesV2_6 extends FederationDirectivesV2_5 { | ||
|
||
def Policy(policies: List[List[String]]) = | ||
Directive("policy", Map("policies" -> ListValue(policies.map(s => ListValue(s.map(s => StringValue(s))))))) | ||
|
||
case class GQLPolicy(policies: List[List[String]]) extends GQLDirective(Policy(policies)) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters