Recipe: translate range types to/from Postgres' format instead of the object version
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 38/100
- Issue 類型
- 文件
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- graphql, postgresql, typescript
研究方向
未指定目標文件。首先在 graphile.github.io repository 中找到現有的 recipe 文件,然後使用所提供的 TranslateRangesPlugin 範例及其 builder hook 和 pg2GqlMapper 入口點作為參考資料。完成的標準是:加入該 recipe,並清楚說明 range translation 行為與範例程式碼。
由索引模型根據 Issue 內容生成。
描述
Sometimes the old way is more convenient :)
import { GraphQLScalarType } from "graphql"
import type { SchemaBuilder, Build } from "graphile-build"
import type { PgType } from "graphile-build-pg"
/**
* This plugin switches the expression of range types back to Postgres' native
* `[lower,upper)` formats instead of Postgraphile's more verbose nested-object
* `{start: {value, inclusive}, end: {...}` version.
*/
export default function TranslateRangesPlugin(builder: SchemaBuilder) {
builder.hook("build", (build: Build) => {
const {
pgIntrospectionResultsByKind,
pgRegisterGqlInputTypeByTypeId,
pgRegisterGqlTypeByTypeId,
pg2GqlMapper,
pgSql: sql,
} = build
// find our target type oid. If you want to change the behavior for a
// built-in range type, you can use one of the following default oids:
//
// 3904 int4range
// 3906 numrange
// 3908 tsrange
// 3910 tstzrange
// 3912 daterange
// 3926 int8range
const myRange = pgIntrospectionResultsByKind.type.find(
(t: PgType) => t.namespaceName === "my_schema" && t.name === "my_range"
)
if (!myRange) {
return build // something went horribly wrong, abort
}
// declare a new kind of scalar
const MyRangeType = new GraphQLScalarType({
name: "MyRange",
description: "An int8range dedicated to a more specific purpose",
serialize: (a: string) => a,
parseValue: (a: string) => a,
})
// register input and output types for the oid
pgRegisterGqlInputTypeByTypeId(myRange.id, () => MyRangeType)
pgRegisterGqlTypeByTypeId(myRange.id, () => MyRangeType)
// define mappings to and from
pg2GqlMapper[myRange.id] = {
// SQL -> GQL
map: (output: string) => output,
// GQL -> SQL; substitute your target range type for `int8range` as necessary
unmap: (input: string) => sql.fragment`${sql.value(input)}::int8range`,
}
return build // pass the build object back for the next stage
})
}
- 主要語言
- SCSS
- 星號
- 27
- 分支
- 124
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 沒有貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
graphile/graphile.github.io 的其他 Issue
-
help wanted quick
難度 2/5 1-3 小時 新手友好度 38/100
graphile/graphile.github.io#401 · 1 則留言 · 1 個 reaction ·
-
website: Update details on homepage and sponsor page可能重新可做 @jemgillam 於 1119 天前認領,目前沒有進行中的 PR。 未關閉quick
graphile/graphile.github.io#399 · 4 則留言 · 已指派 1 人 ·
-
sponsor page: New wording around Grafast needed!可能重新可做 @jemgillam 於 1149 天前認領,目前沒有進行中的 PR。 未關閉
graphile/graphile.github.io#393 · 1 個 reaction · 已指派 1 人 ·
-
難度 2/5 1-3 小時 新手友好度 25/100
graphile/graphile.github.io#280 · 2 則留言 · 5 個 reaction ·
-
難度 5/5 一週以上 新手友好度 25/100
graphile/graphile.github.io#273 · 2 則留言 ·
查看 graphile/graphile.github.io 的全部 Issue
相似的 Issue
-
agent/scanner bug stage/010-actionable
難度 1/5 1 小時以內 新手友好度 88/100
torch-spyre/spyre-inference#1812 ·
維護者通常 1 天內回覆
-
sync-en
難度 1/5 1 小時以內 新手友好度 82/100
維護者通常 1 天內回覆
-
[oblt-aw][autodoc] Update autodoc routing docs for relative in-repo lock uses可能已有人在做 @github-actions 今天認領。 未關閉
難度 1/5 1-3 小時 新手友好度 87/100
維護者通常 1 天內回覆
-
[Enhancement] platform-engineer: a definition change does not re-render running Applications; say how to roll it out可能已有人在做 @anoop2811 今天認領。 未關閉needs-triage type/enhancement
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
cloudflare/workers-sdk#17189 ·
維護者通常 1 天內回覆