Recipe: translate range types to/from Postgres' format instead of the object version
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 38/100
- Tipo de issue
- Documentación
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- graphql, postgresql, typescript
- Área
- documentation
Línea de trabajo
No se ha indicado ningún archivo de documentación de destino. Empieza localizando la documentación existente de recetas en el repositorio graphile.github.io y, a continuación, utiliza como material de referencia el ejemplo proporcionado de TranslateRangesPlugin, junto con su builder hook y sus puntos de entrada pg2GqlMapper. La tarea estará terminada cuando se haya añadido la receta con el comportamiento de traducción de rangos y se haya explicado claramente el código de ejemplo.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
})
}
- Lenguaje dominante
- SCSS
- Estrellas
- 27
- Forks
- 124
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de graphile/graphile.github.io
-
help wanted quick
Dificultad 2/5 1-3 horas Aptitud para principiantes 38/100
graphile/graphile.github.io#401 · 1 comentario · 1 reacción ·
-
website: Update details on homepage and sponsor pageQuizá libre de nuevo @jemgillam la tomó hace 1119 días y no hay ningún pull request abierto. Abiertoquick
graphile/graphile.github.io#399 · 4 comentarios · 1 asignado ·
-
sponsor page: New wording around Grafast needed!Quizá libre de nuevo @jemgillam la tomó hace 1149 días y no hay ningún pull request abierto. Abierto
graphile/graphile.github.io#393 · 1 reacción · 1 asignado ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 25/100
graphile/graphile.github.io#280 · 2 comentarios · 5 reacciones ·
-
Postgraphile Sandbox/PlaygroundAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
graphile/graphile.github.io#273 · 2 comentarios ·
Todos los issues de graphile/graphile.github.io
Issues similares
-
marketing
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
gke-labs/kube-agents#7308 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 Medio día Aptitud para principiantes 62/100
-
chore
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
lugassawan/swe-workbench#841 ·