承接 skillshare/apollo-federation-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

skillshare/apollo-federation-php

Composer 安装命令:

composer require skillshare/apollo-federation-php

包简介

A PHP port of the Apollo Federation specification.

README 文档

README

This package provides classes and utilities for webonyx/graphql-php for creating federated GraphQL subgraphs in PHP to be consumed by the Apollo Gateway.

⚠️ IMPORTANT: This package is still in active development and it might introduce breaking changes.

Usage

Via composer:

composer require skillshare/apollo-federation-php

Entities

An entity is an object type that you define canonically in one subgraph and can then reference and extend in other subgraphs. It can be defined via the EntityObjectType which takes the same configuration as the default ObjectType plus a keyFields and __resolveReference properties.

use Apollo\Federation\Types\EntityObjectType;

$userType = new EntityObjectType([
    'name' => 'User',
    'keyFields' => ['id', 'email'],
    'fields' => [
        'id' => ['type' => Type::int()],
        'email' => ['type' => Type::string()],
        'firstName' => ['type' => Type::string()],
        'lastName' => ['type' => Type::string()]
    ],
    '__resolveReference' => static function ($ref) {
        // .. fetch from a data source.
    }
]);
  • keyFields — defines the entity's primary key, which consists of one or more of the type's. An entity's key cannot include fields that return a union or interface.

  • __resolveReference — resolves the representation of the entity from the provided reference. Subgraphs use representations to reference entities from other subgraphs. A representation requires only an explicit __typename definition and values for the entity's primary key fields.

For more detail on entities, see the official docs.

Entity references

A subgraph can reference entities from another subgraph by defining a stub including just enough information to know how to interact with the referenced entity. Entity references are created via the EntityRefObjectType which takes the same configuration as the base EntityObjectType.

use Apollo\Federation\Types\EntityRefObjectType;

$userType = new EntityRefObjectType([
    'name' => 'User',
    'keyFields' => ['id', 'email'],
    'fields' => [
        'id' => ['type' => Type::int()],
        'email' => ['type' => Type::string()]
    ]
]);

For more detail on entity references, see the official docs.

Extending

A subgraph can add fields to an entity that's defined in another subgraph. This is called extending the entity. When a subgraph extends an entity, the entity's originating subgraph is not aware of the added fields. Only the extending subgraph (along with the gateway) knows about these fields.

use Apollo\Federation\Types\EntityRefObjectType;

$userType = new EntityRefObjectType([
    'name' => 'User',
    'keyFields' => ['id', 'email'],
    'fields' => [
        'id' => [
            'type' => Type::int(),
            'isExternal' => true
        ],
        'email' => [
            'type' => Type::string(),
            'isExternal' => true
        ]
    ]
]);

The subgraph can extend using the following configuration properties:

  • isExternal marks a field as owned by another service. This allows service A to use fields from service B while also knowing at runtime the types of that field.

  • provides used to annotate the expected returned fieldset from a field on a base type that is guaranteed to be selectable by the gateway.

  • requires used to annotate the required input fieldset from a base type for a resolver. It is used to develop a query plan where the required fields may not be needed by the client, but the service may need additional information from other services.

Federated schema

The FederatedSchema class extends from the base GraphQL\Schema class and augments a schema configuration using entity types and federated field annotations with Apollo Federation metadata. See the docs for more info.

use GraphQL\GraphQL;
use Apollo\Federation\FederatedSchema;


$schema = new FederatedSchema($config);
$query = 'query GetServiceSDL { _service { sdl } }';

$result = GraphQL::executeQuery($schema, $query);

Config

The config parameter for the FederatedSchema object is entirely compatible with the Schema config argument. On top of this, we support the following optional parameters:

  1. entityTypes - the entity types (which extend EntityObjectType) which will form the _Entity type on the federated schema. If not provided, the Schema will scan the Query type tree for all types extending EntityObjectType.

Disclaimer

Documentation in this project include content quoted directly from the Apollo official documentation to reduce redundancy.

skillshare/apollo-federation-php 适用场景与选型建议

skillshare/apollo-federation-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 57.11k 次下载、GitHub Stars 达 37, 最近一次更新时间为 2021 年 10 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 skillshare/apollo-federation-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 skillshare/apollo-federation-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 skillshare/apollo-federation-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 57.11k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 39
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 37
  • Watchers: 37
  • Forks: 12
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-12