actor icon indicating copy to clipboard operation
actor copied to clipboard

New notation for array inputs

Open williampollet opened this issue 4 years ago • 15 comments

Hey @sunny !!

Thanks for the amazing work :D

I have an idea, regarding inputs and outputs.

What do you think about accepting a new notation when expecting an array of similar objects, such as:

    inputs :orders, type: [Orders]

(Similar to the GraphQL notation)

This way it will be easier to type arrays.

williampollet avatar Jun 30 '21 14:06 williampollet

That makes a lot of sense! I’d be happy to merge a PR for that šŸ™šŸ»

sunny avatar Jun 30 '21 16:06 sunny

Actually, since now the array syntax for types is used as an "or":

input :age, type: [Integer, Float]

I think it would make more sense to just keep the plural and not have an array:

input :order, type: Order
inputs :orders, type: Order

But perhaps better than the plural which can be a bit too discreet, having it as a new array: true option could make it much more explicit:

input :order, type: Order
input :orders, type: Order, array: true

sunny avatar Jul 31 '21 09:07 sunny

@williampollet Would you be willing to try a patch for this feature using the array: true syntax? šŸ™šŸ»

sunny avatar Dec 15 '21 17:12 sunny

I'm taking it !

williampollet avatar Jan 11 '22 10:01 williampollet

One import disadvantage of array: true it that it won't support type: [T, [T]] input constraints usecase.

In gerenal [T] seems to be more generic ADT-like approach

viralpraxis avatar Feb 28 '24 20:02 viralpraxis

Good point. I think I’d still like the constraints here to be as light as possible and not try to handle all possible types.

One way we could accept more types would be to lean on another constraints/validation gem.

sunny avatar Feb 29 '24 12:02 sunny

One way we could accept more types would be to lean on another constraints/validation gem.

Do you have examples of such gems in mind?

viralpraxis avatar Mar 02 '24 12:03 viralpraxis