graphile / graphile/graphile.github.io
Fix relation snippet in why-nullable
- Langage dominant
- SCSS
- Étoiles
- 27
- Forks
- 126
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Start with the why-nullable page linked in the issue and inspect the embedded NonNullRelationsPlugin snippet. Verify its behavior for relations backed by nullable and non-nullable columns, then update the example so only relations whose linked columns are non-nullable are marked non-null; add or run the relevant checks if the project provides them.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- graphql, javascript
- Domaine
- documentation
- Type d'issue
- Documentation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100