Recipe: translate range types to/from Postgres' format instead of the object version
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 38/100
- Type d'issue
- Documentation
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Stack technique
- graphql, postgresql, typescript
- Domaine
- documentation
Piste de recherche
Aucun fichier de documentation cible n’est indiqué. Commencez par localiser la documentation existante des recettes dans le dépôt graphile.github.io, puis utilisez comme source le exemple fourni de TranslateRangesPlugin ainsi que son builder hook et ses points d’entrée pg2GqlMapper. La tâche est terminée lorsque la recette a été ajoutée avec le comportement de traduction des plages et que le code d’exemple a été clairement expliqué.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
})
}
- Langage dominant
- SCSS
- Étoiles
- 27
- Forks
- 124
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Aucun guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de graphile/graphile.github.io
-
help wanted quick
Difficulté 2/5 1-3 heures Accessibilité débutants 38/100
graphile/graphile.github.io#401 · 1 commentaire · 1 réaction ·
-
website: Update details on homepage and sponsor pagePeut-être à nouveau libre @jemgillam l’a pris il y a 1119 jours, et aucune pull request n’est ouverte. Ouvertequick
graphile/graphile.github.io#399 · 4 commentaires · 1 personne assignée ·
-
sponsor page: New wording around Grafast needed!Peut-être à nouveau libre @jemgillam l’a pris il y a 1149 jours, et aucune pull request n’est ouverte. Ouverte
graphile/graphile.github.io#393 · 1 réaction · 1 personne assignée ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 25/100
graphile/graphile.github.io#280 · 2 commentaires · 5 réactions ·
-
Postgraphile Sandbox/PlaygroundOuverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
graphile/graphile.github.io#273 · 2 commentaires ·
Toutes les issues de graphile/graphile.github.io
Issues similaires
-
agent/scanner bug stage/010-actionable
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
torch-spyre/spyre-inference#1812 ·
Les mainteneurs répondent en général sous 1 jour
-
sync-en
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 1 jour
-
[oblt-aw][autodoc] Update autodoc routing docs for relative in-repo lock usesPeut-être pris @github-actions l’a pris aujourd’hui. Ouverte
Difficulté 1/5 1-3 heures Accessibilité débutants 87/100
Les mainteneurs répondent en général sous 1 jour
-
[Enhancement] platform-engineer: a definition change does not re-render running Applications; say how to roll it outPeut-être pris @anoop2811 l’a pris aujourd’hui. Ouverteneeds-triage type/enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
cloudflare/workers-sdk#17189 ·
Les mainteneurs répondent en général sous 1 jour