buildFederatedSchema only accepts one type definition
See original GitHub issueHi, using buildFederatedSchema
with multiple typeDefs
are not possible? When using apollo-server
I can pass an Array
of DocumentNode
for the parameter typeDefs
as seen here: https://www.apollographql.com/docs/apollo-server/api/apollo-server/#parameters however when I use buildFederatedSchema
it no longer takes an array and only one type def as seen here: https://www.apollographql.com/docs/apollo-server/api/apollo-federation/#buildfederatedschema
Shouldn’t these be the same?
How would you construct the following with buildFederatedSchema
:
const server = new ApolloServer({
typeDefs: [
createRateLimitTypeDef('burstRateLimit'),
createRateLimitTypeDef('sustainedRateLimit'),
typeDefs,
],
resolvers,
schemaDirectives: {
burstRateLimit: createRateLimitDirective(),
sustainedRateLimit: createRateLimitDirective(),
},
})
Not possible to pass an array to typeDefs
:
const schema = buildFederatedSchema([
{
typeDefs: gql(typeDefs),
resolvers,
},
])
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Implementing a subgraph with Apollo Server
Defining a subgraph · 1. Install and import @apollo/subgraph · 2. Opt in to Federation 2 · 3. Define an entity · 4....
Read more >apollo/federation throws an error with the example from the docs
Here is the error I get: GraphQLSchemaValidationError: Field "User.id" can only be defined once. Field "Product.upc" can only be defined once.
Read more >API Reference: @apollo/federation
buildFederatedSchema. A function that takes an array of GraphQL schema modules and returns a ... Used when defining a subgraph in a federated...
Read more >Your First Federated Schema with Apollo - DEV Community
An entity is a type that you define canonically in one implementing ... const server = new ApolloServer({ schema: buildFederatedSchema([{ ...
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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@drager I had the same issue, and the solution that worked for me was the following.
For me when passing typeDefs and resolvers that are themselves arrays, I had to pass
buildFederatedSchema
an object instead of an array.@trevor-scheer if you or one of the maintainers can confirm that this usage is correct, I would be happy to open a PR to add an example of how to pass arrays to
buildFederatedSchema
for the documentation for Apollo Federation.EDIT: I spoke too soon. The above implementation eliminates the errors, but the server does not actually work. I will keep working on this and post any solutions I find.
UPDATE: The above example does work if
resolvers
is an object. It does not work ifresolvers
is also an array. Ifresolvers
is an array, the server will start without error, but the resolvers will returnnull
. While the above example does work with the condition ofresolvers
being an object, after digging through the code, it seems that Federation wants consumers to use a slightly different format, which is shown below. @trevor-scheer would you or one of the maintainers confirm if the below example is the desired usage for an app with multiple type definitions?I got this error, it always returns null. Unable to connect to resolvers.
Does anyone have a better solution to this problem.
UPDATE 10/01/2020
My solution: