Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphQL: prevent empty array as input [duplicate]

I'm learning GraphQL now and I faced a problem that I am unable to resolve.

i have defined type in schema as

input School { name: String! exams: [subject!]! } input subject { name: String! mark: Number! }

But while running the server. I give data as "data": { "name":"varun", "exams":[], }

Server does not throw any validation error. Please suggest me solution. Is there any possible way to get validation error on passing exams as empty array.

I have tried alternate methods, but nothing works on schema level. I have to put a check explicitly to check exam field should not be an empty array. Thanks

like image 798
VARUN MISHRA Avatar asked Oct 22 '25 07:10

VARUN MISHRA


1 Answers

GraphQL cannot validate the length of a list. You need to include this validation logic as part of your resolver.

like image 90
Daniel Rearden Avatar answered Oct 23 '25 20:10

Daniel Rearden



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!