Skip to content

Latest commit

 

History

History
48 lines (32 loc) · 1.6 KB

README.md

File metadata and controls

48 lines (32 loc) · 1.6 KB

GraphQL Federation for PHP

Utility for creating GraphQL microservices, which can be combined into a single endpoint through tools like Apollo Gateway.

Build Status

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.

License

MIT