ds78662302 2018-09-02 14:11
浏览 63

Graphql Php:类类型定义与模式语言

New to Graphql, using webonyx/graphql-php.

What benefit is there to defining my schema with class style definitions vs. graphql's provided syntax?

I have a basic working example using class style schema defs as following:

use MyApp\Type\MediaType;
use MyApp\TypeRegistry;

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;

class MusicType extends ObjectType {

    public function __construct() {
        $config = [
            'fields' => [
                'id' => Type::id(),
                'name' => Type::String(),
                'url' => Type::String(),
                'dateStart' => Type::String(),
                'dateEnd' => Type::String()
            ],
            'interfaces' => [
                TypeRegistry::media(),
                TypeRegistry::dateRestricted(),
            ]
        ];
        parent::__construct($config);
    }
}

However, I find defining the schema this way to be clunky, with the only real benefit I can see being that I can define my resolvers in the same location as the schema.

Using the schema.graphqls syntax looks cleaner and would be more easily ported to other server-side languages...

type Music implements Media {
    id: ID!
    name: String!
    url: String!
    dateStart: String
    dateEnd: String
}

What benefit is there to defining my schema with class style definitions vs. graphql's provided syntax?

  • 写回答

1条回答 默认 最新

  • dongman5539 2019-06-04 12:51
    关注

    In my opinion, the Type language style is more compact and readable. I still have to understand how to write the resolvers for union types and interfaces with this library, anyway, they should be equivalent.

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line