-
-
Notifications
You must be signed in to change notification settings - Fork 250
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
add federation 2.6 support, update gateway dependencies #2043
Merged
paulpdaniels
merged 1 commit into
ghostdogpr:series/2.x
from
paulpdaniels:update-federation-version
Dec 17, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow 😂