How to re-use a resource as an argument type inside {:array, ...} ?

This does not work:
argument :elements, {:array, :struct},
allow_nil?: false,
constraints: [instance_of: __MODULE__]
argument :elements, {:array, :struct},
allow_nil?: false,
constraints: [instance_of: __MODULE__]
And the only constraint I can see that affects the items inside is nil_items? If I use a custom type I need to wrap it one extra layer so that isnt the same as this.. Anyone got any ideas?
Solution:
You can make a map type and set graphql_define_type? to false, and graphql_input_type to something like {:list, :some_input}
Jump to solution
22 Replies
ZachDaniel
ZachDaniel4mo ago
argument :elements, {:array, :struct},
allow_nil?: false,
constraints: [items: [instance_of: __MODULE__]]
argument :elements, {:array, :struct},
allow_nil?: false,
constraints: [items: [instance_of: __MODULE__]]
Oliver
OliverOP4mo ago
ohhh I knew it tickled my memory not implemented in ash_graphql apparently 😄
Oliver
OliverOP4mo ago
No description
Oliver
OliverOP4mo ago
do you think its feasible to get that implemented? if you had to guess an effort level 1-10 I could take a crack at it I have a bunch of these bulk manual actions where we just want to make changesets and validate them as a preprocess step
ZachDaniel
ZachDaniel4mo ago
oh no thats never really going to work you'll need to make a custom map type w/ the inputs you want
Oliver
OliverOP4mo ago
yeah Is there a way to just re-use the existing graphql type as an input for a generic action? like I could type it as :map and it would work, but I want the action to have the type signature of the ArchitecturalElementInput that the create action already made there seems to be a gap here where you can make custom types and use them, but you cant re-use types across actions I think I am not understanding how to do it with current escape hatches if you can give a good dsl suggestion I can do the implementation I was thinking
action: :foo_action, :foo_action, return_type: :existing_type
action: :foo_action, :foo_action, return_type: :existing_type
then you can just return :map and we can resolve as-is maybe return_type_override (this comes from not being able to make bulk create mappings for :create btw) or, partially, I still need the generic for the bulk validate step
ZachDaniel
ZachDaniel4mo ago
Input types and types are not the same thing Accepting the result of a create action doesn't really make sense You want to accept some input to a create action.
Oliver
OliverOP4mo ago
yeah sorry that was a brainfart, we need it somewhere in the argument dsl is there a way in spark to have one plugin adjust another thing by giving it more options?
Solution
ZachDaniel
ZachDaniel4mo ago
You can make a map type and set graphql_define_type? to false, and graphql_input_type to something like {:list, :some_input}
ZachDaniel
ZachDaniel4mo ago
On my phone so can't type it out
Oliver
OliverOP4mo ago
ahhh, that works so basically just set a bogus type that is empty and then reuse the generated type trying that right now is there a setting to not have ash validate the type btw? so that it doesn't go boom if I send data through it
ZachDaniel
ZachDaniel4mo ago
what? 😆
Oliver
OliverOP4mo ago
haha ahhh lol if you dont put fields in constraints it wont validate anything but it being a map thats where my disconnect was I am having this conversation at the same time I am making sure my two year old doesn't die from climbing the couch :p
ZachDaniel
ZachDaniel4mo ago
brb, making ash_child_care
Oliver
OliverOP4mo ago
hahaha I'll be alpha tester I'll pr up a blurb about this workaround in the graphql docs on using your own types the docs are almost there, just missing some pieces
ZachDaniel
ZachDaniel4mo ago
Its also not really ideal because it only works if you define that type in your GraphQL API somewhere its very brittle
Oliver
OliverOP4mo ago
I cant just specify the one that is generated?
ZachDaniel
ZachDaniel4mo ago
what would be better is to be able to use something like {:action_input, Resource, :action} you can but what I'm saying is that if you were to then go and remove the create/update action or w/e that you're using
Oliver
OliverOP4mo ago
yeah then it goes back to jsonstring
ZachDaniel
ZachDaniel4mo ago
then this workaround would break
Oliver
OliverOP4mo ago
Everything worked as a charm I could also metaprogram this with ash resource info I guess
ZachDaniel
ZachDaniel4mo ago
probably yes

Did you find this page helpful?