compwright/graphql-php-jetpack
Composer 安装命令:
composer require compwright/graphql-php-jetpack
包简介
Easily enable support for custom scalars and directives with https://github.com/webonyx/graphql-php
关键字:
README 文档
README
Unlock new graphql-php superpowers with Jetpack scalar and directive support
Features
- Improve your GraphQL schema validation with custom scalars
- Post-process resolved field values with directives
Installation
$ composer require compwright/graphql-php-jetpack
Usage
Install Jetpack schema support at schema build time:
use Compwright\GraphqlPhpJetpack\JetpackDecorator; use GraphQL\Utils\BuildSchema; $schemaTypeDecorator = new JetpackDecorator(); $schema = BuildSchema::build($ast, $schemaTypeDecorator);
Install Jetpack directive support at server config build time:
use Compwright\GraphqlPhpJetpack\DirectiveResolver; use GraphQL\Server\ServerConfig; use GraphQL\Type\Definition\ResolveInfo; $resolver = function ($root, array $args, $context, ResolveInfo $info) { // resolve field value return $root; }; $serverConfig = ServerConfig::create() ->setFieldResolver(new DirectiveResolver($resolver));
Declare the directives and scalars you wish to use in your schema, and call them where desired:
directive @uppercase on FIELD_DEFINITION scalar Email type User { email: Email! @uppercase } type Query { user: User! }
Jetpack Scalars
You can use the provided Scalars just like any other type in your schema definition.
scalar BigInt
An arbitrarily long sequence of digits that represents a big integer.
scalar Date
A date string with format Y-m-d, e.g. 2011-05-23.
The following conversion applies to all date scalars:
- Outgoing values can either be valid date strings or
\DateTimeInterfaceinstances. - Incoming values must always be valid date strings and will be converted to
\DateTimeImmutableinstances.
scalar DateTime
A datetime string with format Y-m-d H:i:s, e.g. 2018-05-23 13:43:32.
scalar DateTimeTz
A datetime string with format Y-m-d\TH:i:s.uP, e.g. 2020-04-20T16:20:04+04:00, 2020-04-20T16:20:04Z.
scalar Email
A RFC 5321 compliant email.
scalar JSON
Arbitrary data encoded in JavaScript Object Notation. See https://www.json.org.
This expects a string in JSON format, not a GraphQL literal.
type Query { foo(bar: JSON!): JSON! } # Wrong, the given value is a GraphQL literal object { foo(bar: { baz: 2 }) } # Correct, the given value is a JSON string representing an object { foo(bar: "{ \"bar\": 2 }") }
JSON responses will contain nested JSON strings.
{
"data": {
"foo": "{ \"bar\": 2 }"
}
}
scalar Latitude
Any number between -90 and 90 degrees.
scalar Longitude
Any number between -180 and 180 degrees.
scalar Mixed
Loose type that allows any value. Be careful when passing in large Int or Float literals,
as they may not be parsed correctly on the server side. Use String literals if you are
dealing with really large numbers to be on the safe side.
scalar Null
Always null. Strictly validates value is non-null, no coercion.
scalar UsState
Any valid two-character US State abbreviation.
scalar UsZipCode
Five digits, optionally followed by a dash and four additional digits.
Jetpack Directives
directive @callback(fn: String!) on FIELD_DEFINITION
Execute a function on the resolved value
directive @lowercase on FIELD_DEFINITION
Transform resolved text lowercase
directive @uppercase on FIELD_DEFINITION
Transform resolved text uppercase
License
MIT License
compwright/graphql-php-jetpack 适用场景与选型建议
compwright/graphql-php-jetpack 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.18k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 01 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「directive」 「scalar」 「graphql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 compwright/graphql-php-jetpack 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 compwright/graphql-php-jetpack 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 compwright/graphql-php-jetpack 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Lightweight scalar-type container
Test scalar values.
A php library to bootstrap the use of Domain Driven Design valueObjects
Laravel blade class directive
Enumeration with scalar values
Alfabank REST API integration
统计信息
- 总下载量: 7.18k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-31