menu

Apollo

A community of developers, designers and others who love Apollo and GraphQL. 🚀

Channels
# All channels
view-forward
# General
view-forward
# Apollo Angular
view-forward
# Announcements
view-forward
# Apollo Android
view-forward
# Apollo Client
view-forward
# Apollo iOS
view-forward
# Apollo Link
view-forward
# Apollo Link Rest
view-forward
# Local State
view-forward
# Apollo Platform
view-forward
# Apollo Server
view-forward
# Apollo Tooling
view-forward
# Contributing
view-forward
# Docs
view-forward
# Events
view-forward
# GraphQL Tools
view-forward
# Jobs
view-forward
# Random
view-forward
# React Apollo
view-forward
# Showcase
view-forward
# Subscriptions
view-forward
# Testing
view-forward
# Vue Apollo
view-forward
Team

Apollo Federation with drupal/graphql: How??

February 4, 2020 at 4:02pm

Apollo Federation with drupal/graphql: How??

February 4, 2020 at 4:02pm
Hi! Has anybody managed to successfully federate the schema produced by the drupal/graphql module?
I am using this package to implement federation: https://github.com/pascaldevink/php-graphql-federation
As you can see, there are two steps -- first you must call that "extendSchema" method. I was able to do this by extending SdlSchemaPluginBase and overriding getSchema (as is done in the drupal/graphql example module from their github page. https://github.com/drupal-graphql/graphql/blob/8.x-4.x/examples/src/Plugin/GraphQL/Schema/ExampleSchema.php).
The second part is calling that method to attach the resolvers to the root value for query execution, but i'm not sure where i would go to modify this. Any suggestions?

February 6, 2020 at 7:06pm
I'm back for another day of shouting into the void! I figured out that you can override the default ExecutorFactory by overriding the graphql.executor setting in your module's service definition. Unfortunately, the gateway is now complaining about all the directives being redefined, even if I remove them manually from the Federation class! Any ideas?
(node:1539) UnhandledPromiseRejectionWarning: GraphQLSchemaValidationError: Directive "external" already exists in the schema. It cannot be redefined.
Directive "requires" already exists in the schema. It cannot be redefined.
Directive "provides" already exists in the schema. It cannot be redefined.
Directive "key" already exists in the schema. It cannot be redefined.
Directive "extends" already exists in the schema. It cannot be redefined.
at ApolloGateway.createSchema (/var/www/html/node_modules/@apollo/gateway/dist/index.js:207:19)
at ApolloGateway.<anonymous> (/var/www/html/node_modules/@apollo/gateway/dist/index.js:178:32)
at Generator.next (<anonymous>)
at fulfilled (/var/www/html/node_modules/@apollo/gateway/dist/index.js:5:58)
at process._tickCallback (internal/process/next_tick.js:68:7)
  • reply
  • like
Here's what I'm using to test:
const {
ApolloGateway,
RemoteGraphQLDataSource
} = require( '@apollo/gateway');
const {ApolloServer} = require( 'apollo-server-express');
/**
* The cms schema needs to be federated, but it's not really possible from the drupal plugin.
* This datasource extends the RemoteGraphQLDataSource, but federates the schema request.
*/
class FederatedRemoteGraphQLDataSource extends RemoteGraphQLDataSource {
didReceiveResponse(res, req, context) {
res.body.on('data', data => {
console.log('DATA: ', data.toString())
});
try {
return super.didReceiveResponse(res, req, context);
} catch (e) {
console.log(e.stack);
}
}
}
const gateway = new ApolloGateway({
serviceList: [
{ name: 'cms', url: 'http://cms:80/graphql' },
],
buildService({ name, url }) {
return new FederatedRemoteGraphQLDataSource({ url });
},
debug: true,
});
const create_ssr_apollo_server = new ApolloServer({
gateway,
subscriptions: false,
context: ({req, res}) => ({
req,
res,
}),
tracing: true,
cacheControl: true,
debug: true,
formatError: error => {
console.log(error.stack);
},
});
  • reply
  • like

February 27, 2020 at 8:49pm
Hey. Did you found a solution now? Is that correct that the existing implementation is not usable because the directives, which generate php-graphql-federation, does something wrong?
Edited
  • reply
  • like

March 2, 2020 at 9:30pm
Unfortunately I'm on a tight development schedule, I'm still not entirely sure what the issue was, but I got an issue opened for it on the drupal-graphql github page. For now I'm just using schema stitching, and plan to migrate to federation once that's sorted out.
  • reply
  • like

March 3, 2020 at 5:15pm
Yes. Saw in https://github.com/drupal-graphql/graphql/issues/975. Thanks for your response
  • reply
  • like