Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

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

Ouverte
#486 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
45/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
fsharp
Domaine
api, backend

Piste de recherche

Commencez par reproduire la requête composée uniquement du fragment avec FSharp.Data.GraphQL 2.2.1 et examinez l’argument root du resolver organizationField pendant l’exécution. Comparez-la avec les cas du fragment inline et de la requête avec un champ supplémentaire ; c’est terminé lorsque les trois formes fournissent le même root non nul et que le champ organizations se résout sans erreur de null.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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
Langage dominant
F#
Étoiles
406
Forks
74
Merge moyen
15 h 59 min
PR mergées (30 j)
20

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de fsprojects/FSharp.Data.GraphQL

Toutes les issues de fsprojects/FSharp.Data.GraphQL

Issues similaires

Plus d'issues Backend & API Design

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.