Skip to content

Nested InputObjects don't get populated #472

Open
@pkese

Description

@pkese

I've added a small random generator query to star-wars-api example:

    let randoms =
        let inputs = [
            Define.Input ("count", IntType)
            Define.Input ("range", Nullable (Define.InputObject("RandomRange", [
                Define.Input ("min", IntType)
                Define.Input ("max", IntType)
            ])))
        ]
        let renderRandoms (ctx:ResolveFieldContext) (r:Root) =
            // printfn "Random called with count:%A and range:%A" (ctx.Arg "count") (ctx.Arg "range")
            // todo: ranges are not implemented, because ctx.Arg("range") is always empty (read below)
            [ for i in 1..ctx.Arg("count") -> System.Random.Shared.Next() ]

        Define.Field ("random", ListOf IntType, "Render random numbers", inputs, renderRandoms)

and plugged it into existing Query:

    let Query =
        let inputs = [ Define.Input ("id", StringType) ]
        Define.Object<Root> (
            name = "Query",
            fields =
                [ Define.Field ("hero", Nullable HumanType, "Gets human hero", inputs, fun ctx _ -> getHuman (ctx.Arg ("id")))
                  Define.Field ("droid", Nullable DroidType, "Gets droid", inputs, (fun ctx _ -> getDroid (ctx.Arg ("id"))))
                  Define.Field ("planet", Nullable PlanetType, "Gets planet", inputs, fun ctx _ -> getPlanet (ctx.Arg ("id")))
                  Define.Field ("characters", ListOf CharacterType, "Gets characters", (fun _ _ -> characters))
                  randoms // <-- here
                ])

Now I can say

query { random(count:5) }

and get

{ "documentId": -804090008,
  "data": {
    "random": [1773619870, 512090916, 1972640319, 301711584, 480788316]
}}

Problem

When I call

query { random(count:5, range:{min:10, max:20}) }

The ctx.args("range") is always passed as an empty unpopulated obj() without any type or properties,
whereas ctx.args("count") works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions