Plugin example: setting the GraphQL type to use for a given PostgreSQL type

オープン
#270 コメント 0 件 リアクション 5 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
45/100
issue の種類
ドキュメント
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
graphql, postgresql, typescript

調査の方向性

issue本文には、GraphQLとPostgreSQLを使用するTypeScriptプラグインの例がありますが、リポジトリ内のファイルもテストも示されていません。適切なプラグイン例またはドキュメント例の領域を特定し、次に、ドキュメント化された例がスカラー型に類似した型を扱い、複合型では入力/出力を個別に登録する必要があることを記載しているか確認してください。

索引モデルが issue の本文から書いたものです。

説明

Thanks to @Gomes on Discord. This only works for scalar-like types, for composite types you'll need to register separate input and output types (i.e. in addition to calling pgRegisterGqlTypeByTypeId you also need to call pgRegisterGqlInputTypeByTypeId)

import type { GraphQLType } from "graphql";
import type { Plugin } from "graphile-build";
import type { PgType } from "graphile-build-pg";

interface PgDomainToGqlTypePluginArgs {
  /** PostgreSQL type identifier, e.g. "my_schema.my_type" */
  typeIdentifier: string;
  /** What GraphQL type should we use for this PG type */
  gqlType: GraphQLType | ((build: Build) => GraphQLType);
}

/**
 * Sets the GraphQL type `gqlType` to be used for the PostgreSQL type identified
 * by `typeIdentifier`
 */
export function makePgDomainToGqlTypePlugin({
  typeIdentifier,
  gqlType,
}: PgDomainToGqlTypePluginArgs): Plugin {
  return (builder) => {
    builder.hook("build", (build) => {
      const { namespaceName, entityName: typeName } = build.pgParseIdentifier(
        typeIdentifier
      );

      const pgType = build.pgIntrospectionResultsByKind.type.find(
        (type: PgType) =>
          type.namespaceName === namespaceName && type.name === typeName
      );

      if (!pgType) {
        throw new Error(`Failed to find the type '${typeIdentifier}'`);
      }

      build.pgRegisterGqlTypeByTypeId(pgType.id, () =>
        typeof gqlType === "function" ? gqlType(build) : gqlType
      );

      return build;
    });
  };
}
主要言語
SCSS
スター
27
フォーク
124
PR マージ指標
30日以内にマージされた PR はありません

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

graphile/graphile.github.io のほかの issue

graphile/graphile.github.io の issue をすべて見る

似ている issue

Backend & API Design の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。