graphql-constraint-directive icon indicating copy to clipboard operation
graphql-constraint-directive copied to clipboard

Support Lists

Open karavaan opened this issue 3 years ago • 3 comments

It would be nice if there was support for list constraints in particulair:

minListLength and maxListLength

input Example {
  beep: [Int!]! @constraint(minListLength: 3)
  boop: [String!]! @constraint(maxListLength: 3)
}

karavaan avatar Sep 15 '21 13:09 karavaan

I got most of the code ready for this: https://github.com/karavaan/graphql-constraint-directive/blob/master/scalars/list.js

Only I can't get it to work for a list of objects, the fields get lost when the custom scalar gets created.

You can see this unit test failing for example: https://github.com/karavaan/graphql-constraint-directive/blob/master/test/list.test.js#L1206

I'm not even sure if a custom scalar is the best way to go for this?

Any thoughts @confuser

karavaan avatar Sep 15 '21 14:09 karavaan

I can't see tests failing, only the code ;) You shouldn't be losing the Title type 🤔 Unfortunately the only way to achieve this library at the time was to use a custom scalar; you could try overwriting the resolver function instead and see if that suffices?

confuser avatar Sep 15 '21 14:09 confuser

What about using minItems and maxItems to stay compatible with "GraphQL Constraints Directives RFC"?

velias avatar May 10 '22 13:05 velias