I've added a small random generator query to star-wars-api example:
letrandoms=letinputs=[
Define.Input ("count", IntType)
Define.Input ("range", Nullable (Define.InputObject("RandomRange",[
Define.Input ("min", IntType)
Define.Input ("max", IntType)])))]letrenderRandoms(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 in1..ctx.Arg("count")-> System.Random.Shared.Next()]
Define.Field ("random", ListOf IntType,"Render random numbers", inputs, renderRandoms)and plugged it into existing Query:
letQuery=letinputs=[ 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.
I've added a small random generator query to star-wars-api example:
and plugged it into existing Query:
Now I can say
and get
{ "documentId": -804090008, "data": { "random": [1773619870, 512090916, 1972640319, 301711584, 480788316] }}Problem
When I call
The
ctx.args("range")is always passed as an empty unpopulatedobj()without any type or properties,whereas
ctx.args("count")works as expected.