Fix relation snippet in why-nullable

Offen
#69 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Dokumentation
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
graphql, javascript
Bereich
documentation

Rechercherichtung

Beginne mit der im Issue verlinkten why-nullable-Seite und prüfe das eingebettete NonNullRelationsPlugin-Snippet. Verifiziere sein Verhalten für Relationen, die von nullable und non-nullable Spalten unterstützt werden, und aktualisiere anschließend das Beispiel so, dass nur Relationen, deren verknüpfte Spalten non-nullable sind, als non-null markiert werden; füge relevante Checks hinzu oder führe sie aus, falls das Projekt solche bereitstellt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

important quick

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)

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

Vorherrschende Sprache
SCSS
Sterne
27
Forks
124
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

  • Kein Dockerfile und keine Docker-Compose-Datei
  • Hat eine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus graphile/graphile.github.io

Alle Issues in graphile/graphile.github.io

Ähnliche Issues

Weitere Issues zu Documentation

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.