mindgram/graphql-federation

用于创建 GraphQL 微服务的实用工具,可以通过 Apollo Gateway 等工具将其合并为单个端点

2.0.0 2023-09-08 12:48 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