Utility for creating GraphQL microservices, which can be combined into a single endpoint through tools like Apollo Gateway.
Use the package manager composer to install graphql-federation.
composer require pascaldevink/graphql-federation
Assuming you already have an existing GraphQL implementation using webonyx/graphql-php, these commands add federation:
# First, build your existing schema
$existingSchema = BuildSchema::build(file_get_contents(__DIR__ . '/schema.graphqls'));
# Then, extend it with Federation
$federation = new \PascalDeVink\GraphQLFederation\Federation();
$schema = $federation->extendSchema($existingSchema);
# Build your root value resolver
$rootValue = include __DIR__ . '/rootvalue.php';
# And extend it with Federation resolvers
$rootValue = $federation->addResolversToRootValue($rootValue);
# Finally, execute the query
GraphQL::executeQuery($schema, $query, $rootValue, null, $variableValues);
See the example of webonyx/graphql-php for the rest of the code to make it work.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.