graphile / graphile/graphile.github.io

Fix relation snippet in why-nullable

Abierto
#69 0 comentarios 0 reacciones 0 asignados Ver en GitHub
important quick
Lenguaje dominante
SCSS
Estrellas
27
Forks
126
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

https://www.graphile.org/postgraphile/why-nullable/

Currently the snippet (incorrectly) marks all relations as non-nullable. Should only apply if the columns themselves are non-nullable.

Something like this: (needs testing)

```js
module.exports = function NonNullRelationsPlugin(builder) {
builder.hook('GraphQLObjectType:fields:field', (field, build, context) => {
const { isPgForwardRelationField, pgFieldIntrospection } = context.scope;
if (isPgForwardRelationField) {
const linkedAttributeNums = pgFieldIntrospection.keyAttributeNums;
const relationIsNotNull = pgFieldIntrospection.class.attributes.filter(
attr => linkedAttributeNums.indexOf(attr.num) >= 0
).every(attr => attr.isNotNull || attr.type.domainIsNotNull);

if (relationIsNotNull) {
return {
...field,
type: new build.graphql.GraphQLNonNull(field.type),
};
}
}

return field;
});
};
```

HT @enisdenjo

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.