graphql-constraint-directive
graphql-constraint-directive copied to clipboard
Support Lists
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)
}
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
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?
What about using minItems
and maxItems
to stay compatible with "GraphQL Constraints Directives RFC"?