pascaldevink / graphql-federation
Utility for creating GraphQL microservices, which can be combined into a single endpoint through tools like Apollo Gateway
Requires
- php: ^7.3
- webonyx/graphql-php: ^0.13.8
Requires (Dev)
- phpunit/phpunit: ^8.4
This package is auto-updated.
Last update: 2024-10-29 05:41:04 UTC
README
Utility for creating GraphQL microservices, which can be combined into a single endpoint through tools like Apollo Gateway.
Installation
Use the package manager composer to install graphql-federation.
composer require pascaldevink/graphql-federation
Usage
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.
Contributing
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.