Recipe: translate range types to/from Postgres' format instead of the object version
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 38/100
- Tipo di issue
- Documentazione
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- graphql, postgresql, typescript
- Ambito
- documentation
Direzione di ricerca
Non è indicato alcun file di documentazione di destinazione. Inizia individuando la documentazione esistente delle ricette nel repository graphile.github.io, quindi usa come materiale di riferimento l’esempio fornito di TranslateRangesPlugin e i relativi builder hook e punti di ingresso pg2GqlMapper. Il lavoro è completato quando la ricetta è stata aggiunta con il comportamento di traduzione degli intervalli e il codice di esempio è stato spiegato chiaramente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
})
}
- Lingua principale
- SCSS
- Stelle
- 27
- Fork
- 124
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di graphile/graphile.github.io
-
help wanted quick
Difficoltà 2/5 1-3 ore Idoneità per principianti 38/100
graphile/graphile.github.io#401 · 1 commento · 1 reazione ·
-
website: Update details on homepage and sponsor pageForse di nuovo libera @jemgillam l’ha presa 1119 giorni fa e non c’è nessuna pull request aperta. Apertaquick
graphile/graphile.github.io#399 · 4 commenti · 1 assegnatario ·
-
sponsor page: New wording around Grafast needed!Forse di nuovo libera @jemgillam l’ha presa 1149 giorni fa e non c’è nessuna pull request aperta. Aperta
graphile/graphile.github.io#393 · 1 reazione · 1 assegnatario ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 25/100
graphile/graphile.github.io#280 · 2 commenti · 5 reazioni ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
graphile/graphile.github.io#273 · 2 commenti ·
Tutte le issue di graphile/graphile.github.io
Issue simili
-
marketing
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
gke-labs/kube-agents#7308 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 62/100
-
chore
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
lugassawan/swe-workbench#841 ·