ChilliCream / graphql-workshop

Getting started with GraphQL on ASP.NET Core and Hot Chocolate - Workshop
465 stars 199 forks source link

IArgumentDescriptor.Type function problem #74

Closed Sally-Xu closed 3 years ago

Sally-Xu commented 3 years ago

I'm trying to write my QueryType using ObjectType and IObjectTypeDescriptor,

My Id field are Guid types, the following code output 2 queries, the 1st one works fine. the 2nd one does not.

descriptor .Field($"sessionById") .Argument("id", a => a.ID().Type(typeof(Guid))) // add Input Argument .UseDbContext() .ResolverWith(r=> ...);

descriptor .Field($"sessionListById") .Argument("ids", a => a.ID().Type(typeof(Guid[]))) // add Input Argument
.UseDbContext() .ResolverWith(r=> ...);

I have 2 problems: Problem 1: The argument for the 2nd query will be output to : ids: [ID!] , instead of ids: [ID!]! --- should be not null field.

Problem 2: when I plug my ID value into the 2nd query input, I got the following error telling me the IDs have an invalid format.

The same ID works for the first query when input just uses single ID instead of an Array.

query GetSessions { a: sessionListById(ids: ["U2Vzc2lvbgpnNWUxZmEzNWU3YWFiNGZkMmI0ZWM5YTM1YjE1OTY1NjQ="]) { id, title } b: sessionById(id: "U2Vzc2lvbgpnNWUxZmEzNWU3YWFiNGZkMmI0ZWM5YTM1YjE1OTY1NjQ=") { id, title } }

Result: { "errors": [ { "message": "The IDs U2Vzc2lvbgpnNWUxZmEzNWU3YWFiNGZkMmI0ZWM5YTM1YjE1OTY1NjQ= have an invalid format." } ], "data": { "a": null, "b": { "id": "U2Vzc2lvbgpnNWUxZmEzNWU3YWFiNGZkMmI0ZWM5YTM1YjE1OTY1NjQ=", "title": "Session 5" } } }

Anyone can help?

Sally-Xu commented 3 years ago

I finally figured out, I have to use

.Argument("ids", a => a.ID().Type<NonNullType<ListType<NonNullType>>>()) // add Input Argument

to output [ID!]! type.