赵锐德/graphql-federation

用于创建 GraphQL 微服务的实用程序,可以通过像 Apollo Gateway 这样的工具将其组合成单个端点

v0.1 2019-10-30 16:27 UTC

This package is auto-updated.

Last update: 2024-08-29 05:00:54 UTC


README

用于创建 GraphQL 微服务的实用程序,可以通过像 Apollo Gateway 这样的工具将其组合成单个端点。

Build Status

安装

使用包管理器 composer 安装 graphql-federation。

composer require pascaldevink/graphql-federation

用法

假设您已经使用 webonyx/graphql-php 具备了现有的 GraphQL 实现,以下命令将添加联邦

# 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);

请参见 webonyx/graphql-php 的示例,了解其余代码以使其工作。

贡献

欢迎提交拉取请求。对于重大更改,请首先打开一个问题来讨论您想要进行的更改。

请确保适当更新测试。

许可证

MIT