Skip to content
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

Federation support #462

Closed
hnrklssn opened this issue Oct 24, 2019 · 13 comments
Closed

Federation support #462

hnrklssn opened this issue Oct 24, 2019 · 13 comments

Comments

@hnrklssn
Copy link

Is there any plan to support Apollo Federation?

@jregistr
Copy link

Hi!
For something like this it'd make sense for it to be a package, similar to what we do already for Relay.

Speaking of which, in the next few weeks I'm going to start some chatter in this repo on a draft I'm working on.

@danestig
Copy link

danestig commented Nov 6, 2019

I'm also interested in this and would be happy to contribute.

I've done some experimentation and the the main issue I'm facing is the _entities resolver. Currently it looks like this:

implicit ctx => Action.sequence[Ctx, Option[Any]](ctx.arg[Seq[JsValue]]("representations").map(getEntity))

and getEntity has this signature:

def getEntity(data: JsValue)(implicit ctx: Context[Ctx, _]): LeafAction[Ctx, Option[Any]]

This works as long as I don't have any DeferredValues, if I do, I run in to this issue #465.

@joshjones95
Copy link

Hi,

Has there been any discussions or packages that have started to support this for sangria?

@paulpdaniels
Copy link
Contributor

It is possible to do, we have an internal implementation of it that we use for our services. The main issue that the marshallers need to be changed to support object scalars.

@yanns
Copy link
Contributor

yanns commented Sep 23, 2020

@paulpdaniels we would also be interested in that.
As far as I can understand you, it's not possible to support federation with a "simple" library.
Some more deeper changes are needed?

@paulpdaniels
Copy link
Contributor

@yanns The spec itself is purely additive and can be put on top of the existing implementation. You need to add some new directives and probably some sugar to make them easy to add. But then the only change is that you need to basically wrap your existing schema with something like:

def federate[Ctx, Val: ClassTag](_schema: Schema[Ctx, Val], resolvers: EntityResolver[Ctx]*): Schema[Ctx, Val]

Where EntityResolver looks something like this:

trait EntityResolver[Ctx] {
  def typename: String

  def resolve(obj: JsObject): LeafAction[Ctx, Option[Any]]
}

I'll see if I can extract a gist of what we are doing. The incompatibility comes from the fact that the existing marshallers won't support the _Any scalar that federation needs. So we had to forked our own, basically: here and here need to be amended to accept the ObjectNode of the marshaller.

@paulpdaniels
Copy link
Contributor

Here we go: https://gist.github.com/paulpdaniels/f6e637d1bbbd67d13ec661a7306e6af4

@danestig
Copy link

danestig commented Sep 23, 2020

I've been using the same approach but I'm running into this #465 when the entity resolver doesn't return a deferred value but the entity has has nested deferred fields. Currently I'm resolving all entities to DeferredValues instead of LeafActions to work around this.

Other than that this is working well for me.

@paulpdaniels
Copy link
Contributor

Interesting, haven't encountered that @ErikHedblom , though we still have a relatively small interplay of our federated services. Yeah the LeafAction is decidedly not great, there is probably someway to improve that syntax but will need some work on the internals I think.

@yanns
Copy link
Contributor

yanns commented Sep 24, 2020

Should I create a new repo under the sangria organization for that?
We could mark the library as "alpha" first.

@danestig
Copy link

I think that would be great, we should be able to use @paulpdaniels gist for the first version.

@zvuki
Copy link

zvuki commented Mar 31, 2021

👋 Is there any progress in this area?

@yanns
Copy link
Contributor

yanns commented Mar 31, 2021

You can find the first implementation here: https://github.com/sangria-graphql/sangria-federated/
Please use it with caution and provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants