-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Build Federated Schemas From Existing Schema #3013
Conversation
@JacksonKearl Thoughts on this? |
I implemented directives into |
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.
Hey! Super exciting to see this coming together, it will be great to be able to federate services from even more backends. I left a few initial comments, and pinging @jbaxleyiii for a more complete review.
packages/apollo-federation/src/service/__tests__/buildFederatedSchema.test.ts
Outdated
Show resolved
Hide resolved
packages/apollo-federation/src/service/__tests__/buildFederatedSchema.test.ts
Outdated
Show resolved
Hide resolved
packages/apollo-federation/src/service/__tests__/buildFederatedSchema.test.ts
Outdated
Show resolved
Hide resolved
packages/apollo-federation/src/service/__tests__/buildFederatedSchema.test.ts
Outdated
Show resolved
Hide resolved
I can cleanup the tests. I wrapped them all just to quickly reuse the tests in place then another wrapped call which is the schema instance. |
@JacksonKearl thoughts? |
packages/apollo-federation/src/service/__tests__/buildFederatedSchema.test.ts
Outdated
Show resolved
Hide resolved
@JacksonKearl I cleaned the implementation up. It should be more clear on what's going on. Let me know what you think. /cc @jbaxleyiii We feature-locked our API until this is implemented so we can move to federated services, so I'm willing to fix changes in near real time. And others using the Also, when |
@abernix thoughts on this PR? We really want to start moving our existing servers to federation without having to use the resolvers + SDL method. Right now, you almost HAVE to convert schema to SDL + resolvers which is pretty ugly :( |
@j we are going to do another pass of reviews first of next week. A few of us are out of office right now which is why there has been some delay on this review! Thank you so much for working on this, very excited to get it merged in |
@jbaxleyiii Sounds good! This is going to help adoption a ton! Thanks! 🏄 |
Ah, this is amazing! |
@ldiego08 thanks! Federation support in |
@JacksonKearl it's saying there's changes requested still but I don't see any. I thought I resolved them all. :\ |
packages/apollo-federation/src/service/extractFederationResolvers.ts
Outdated
Show resolved
Hide resolved
packages/apollo-federation/src/service/extractFederationResolvers.ts
Outdated
Show resolved
Hide resolved
// GraphQLSchema and transform it to a federated schema. | ||
if (modulesOrSDLOrSchema instanceof GraphQLSchema) { | ||
return transformFederatedSchema(modulesOrSDLOrSchema, [ | ||
extractFederationResolvers(modulesOrSDLOrSchema), |
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.
I don't think this needs to be an array of GraphQLResolverMap
.
// support for preserving the *uses* of federation directives while removing | ||
// their *definitions* from the sdl. | ||
const sdl = printSchema(schema); | ||
const resolvers = modules |
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.
Alternatively, we could merge resolvers from all modules here, so we can simplify transformFederatedSchema
.
return undefined; | ||
}); | ||
|
||
(Array.isArray(resolvers) ? resolvers : [resolvers]).forEach(map => |
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.
This could be simplified if we always pass in a merged GraphQLResolverMap
.
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.
@martijnwalraven I was trying to keep the logic the same as what is currently happening where we're iterating over the modules and calling addResolversToSchema
when module.resolvers
is defined. How do you propose I merge resolvers without adding too much logic into this method. Do I iterate over resolvers, check if it's a scalar type and over-ride, otherwise do a "merge"?
Note that we may soon be able to remove these workarounds and switch to using |
Thank you! |
💪 |
+1 on this. There is a ticket at work that I'm blocked on while waiting for this PR. Trying to migrate our backend codebase to the future 💻 |
How can I help u guys ? |
It's been about a month... I wish I could help but what is really blocking this? |
@JacksonKearl I keep getting these pings of people wanting this. What are your thoughts to move forward? Extensions is out in |
@j apologies for the delay on this. We've had some discussions about upgrading the graphql version within federation and have decided that we'd like to go forward with it as we'll be using the |
Are there currently any updates with regards to this? |
Is there any way we can help this PR moving forward? |
Just to bring attention to this PR |
@j 's fork seems to have disappeared from his GitHub, i've taken the liberty of taking his branch and rebasing on master on my own fork. We've been using this PR internally for the last few months and would love to see it makes its way to upstream. @trevor-scheer @jbaxleyiii is the rebase enough or do you guys need the graphql-js bump & extensions rewrite to go through with it ? |
Oops, @Superd22 I went on a cleaning spree. I for some reason had >200 forks. Thanks. I haven't had time to implement this as we decided this was too new and aren't implementing it at this time. |
Would it be possible to merge this PR as it is (apart from resolving the conflicts) and work on the extensions rewrite later when someone has time? |
@j Any update on this PR. I have a similar requirement in my project. When can we expect this to be production-ready? |
@nivas-everest We since then decided to not use federation until it's proven. It shouldn't be hard to build atop this. |
If one doesn't have any experience with this codebase, at least for me it's unfortunately difficult to follow. How exactly do the |
Fixed with an upcoming update ? |
This was an unintentional closing. Please stand-by and see #4304 for more details. (While I could put the branch back in place and re-open this right now, I'd prefer to let GitHub Support diagnose what might have gone wrong and try to explain why only a portion of pull-requests were re-targeted and the rest closed, in order to make sure the (somewhat recently introduced) pull-request re-targeting feature is working properly for other GitHub users.) |
This is one of 5 PRs that I was unable to re-open after the process described #4304. The 4 others I couldn't re-open were because they had already been re-opened, and this was because the source branch had been deleted. To preserve this, I've re-opened this as a new PR, myself, from the same ref ( |
Hello!
So I'm implementing federation in
type-graphql
and saw that there's some improvements that I feel will make 3rd party libraries not using typeDefs & resolver maps for creating schemas.This adds the ability to pass in an existing GraphQLSchema object and does the following if the argument passed to
buildFederatedSchema
is an instance of GraphQLSchema:1a. First checks type's
resolveReference
property1b. Checks if type has a field named
__resolveReference
(also deletes this field after saving the function)addResolversToSchema
Everything else stays the same. I ended up creating a utility function to all of the tests to automatically test a wrapped version of the federated schema as well as included one manual one.
This will make federation support super easy for projects like
type-graphql
instead of doing printSchema hacks, converting to typeDefs and plucking resolvers out to then be re-converted to SDL and schema, etc. We can then not have federation as a dependency but instead require@apollo/federation
on our own app and expose the federated server.References:
MichalLytek/type-graphql#369
Example Usage in
type-graphql
: MichalLytek/type-graphql@9bbed68