Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Executing a query that only contains a fragment spread causes the root value to be null.

Offen
#486 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
fsharp
Bereich
api, backend

Rechercherichtung

Beginne damit, die nur aus einem Fragment bestehende Abfrage mit FSharp.Data.GraphQL 2.2.1 zu reproduzieren, und untersuche während der Ausführung das root-Argument des organizationField-Resolvers. Vergleiche sie mit dem Fall eines Inline-Fragments und dem Fall einer Abfrage mit einem zusätzlichen Feld; abgeschlossen ist die Untersuchung, wenn alle drei Formen dasselbe nicht-null root bereitstellen und das organizations-Feld ohne einen null-Fehler aufgelöst wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Description

If you construct a query that only contains a spread fragment, it appears that the resolver's root argument becomes null. This only happens whenever there are no other fields being queried, only the fragment.

Repro steps

The following is an example of such a query:

fragment SidebarFragment on Query {
    organizations(first: 10) {
        edges {
            node {
                name
                id
            }
        }
    }
}

query MainLayoutMainQuery {
    ...SidebarFragment
}

The following is the resolver for the organizations field:

let organizationField (organizationType: OutputDef<Organization>) =
    Define.AsyncField(
        "organization",
        Nullable organizationType,
        "Gets one of the user's organizations by id",
        [ Define.Input("id", StringType) ],
        fun ctx (root: Root) ->
            let globalId = ctx.Arg<string> "id"

            match globalId with
            | GlobalId("Organization", id) ->
                let repository = buildOrganizationRepository root.Db root.UserId
                repository.Fetch(Guid(id))
            | _ -> raise (GQLMessageException "Invalid organization ID received.")
    )

And the root is a simple record value:

type Root = {
    Db: DbCtx
    UserId: string
}

If the query is executed against this setup, then the root argument of the resolver becomes null, even when that is not a valid value
for the field. This issue completely goes away whenever there is either another field in the main query, as in the following:

fragment SidebarFragment on Query {
    organizations(first: 10) {
        edges {
            node {
                name
                id
            }
        }
    }
}

query MainLayoutMainQuery {
    node(id: "") {
        id
    }
    ...SidebarFragment
}

Or the fragment is not used, and instead is sent inline as normal:

query MainLayoutMainQuery {
    organizations(first: 10) {
        edges {
            node {
                name
                id
            }
        }
    }
}
Expected behavior

The organizations field should be the same for all of the previous queries, and no null error should occur.

Actual behavior

The root argument is null.

Known workarounds

Add a dummy field to the main query, as that somehow makes the root field not be null.

Related information
  • Arch linux 6.10.5
  • FSharp.Data.GraphQL 2.2.1
  • .NET Core 8
Vorherrschende Sprache
F#
Sterne
407
Forks
74
Ø Merge
15 Std. 59 Min.
Gemergte PRs (30 T.)
20

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

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 fsprojects/FSharp.Data.GraphQL

Alle Issues in fsprojects/FSharp.Data.GraphQL

Ähnliche Issues

Weitere Issues zu Backend & API Design

Neue Issues direkt in Ihr Postfach

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