question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

buildFederatedSchema with existing GraphQLSchema

See original GitHub issue

I’m trying to implement apollo-federation in type-graphql library which uses GraphQL*Type to construct schemas. Is it possible to build convert/build a federated schema from a GraphQLSchema? It seems like these libraries will have to convert to outputting SDL instead of using graphql-js directly.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
jcommented, Jul 3, 2019

@JacksonKearl Hey! I started hacking at it and got type-graphql to output a federation type of schema.

The directive hack is here: https://github.com/19majkel94/type-graphql/pull/369/files#diff-48f4a1f7b529a17d4579df20f8af7af1R272

And here’s a quick test showing that it works (well prints schema correctly): https://github.com/19majkel94/type-graphql/pull/369/files#diff-b0c36f08a566dd0298fff8e07447781b

I mimic’d the demo reviews service.

I’m not sure if I break schema by using astNode instead of extensionASTNodes. I’d think I should use extensionASTNodes but apollo federation doesn’t pull directives unless astNode IS defined and using typescript, I can’t have it be an empty object (https://github.com/apollographql/apollo-server/blob/master/packages/apollo-federation/src/service/printFederatedSchema.ts#L170).

That directive issue you listed is so people can use directives more as middleware / validation / etc, whereas I believe federation just uses them for referencing schema and doesn’t do anything on a resolver level with them? So I thought I could implement them directly for now to see if I can get it to work. I believe I could create a __resolveReference field resolver within type-graphql, so

I’m not too sure where to go from here though, haha. I was going about it the “manual” way you mentioned instead of using the buildFederatedSchema route.

/cc @19majkel94

0reactions
MichalLytekcommented, Nov 3, 2019

It looks like the only difference between type-graphql’s ResolversMap and our GraphQLResolverMap is the addition of a top-level “ResolverOptions” construct on their side. I’m not quite sure what that does, but if we can just filter it out the types should be identical.

@JacksonKearl type-graphql’s ResolversMap is designed to work with other tools, like graphql-tools - I’ve basically copied their types and refactored them a bit. The ResolverOptions are responsible for handling subscribe instead of resolve (not supported in federation) as well as __resolveType and __isTypeOf for unions and interfaces.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to convert GraphqlSchema into a Federation Schema?
When I passing existing GrpahqlSchema to buildFederatedSchema , I am getting below error. Cannot read property 'kind' of undefined.
Read more >
Introduction to Apollo Federation - Apollo GraphQL Docs
With federation, you can responsibly share ownership of your supergraph across any number of teams. And even if you currently only have one...
Read more >
GraphQL Schema Federation With Apollo, TypeScript and ...
The last step is to make our schema available to be federated by the Gateway , by using buildFederatedSchema like we did before...
Read more >
Best Practices for Designing a Federated GraphQL Schema
Learn GraphQL with Apollo Odyssey, our hands-on training and tutorial course platform - https://odyssey.apollographql.com/Learn from our ...
Read more >
Your First Federated Schema with Apollo Server - YouTube
Talk by Mandi Wise, Author of Advanced GraphQL with Apollo & React and Owner, 8-Bit Press Inc.Since its launch last year, Apollo Federation ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found