atom attribute called status creates errors with latest ash_graphql
I just updated
ash_graphql
version to 0.25.4
and after doing that I get an error when compiling the project.
Seems like the problem is related to this attribute I have in my Offer
resource:
The strange thing is that if I change the attribute name to something else like status2
the error goes away, it only happens if the attribute name is status
.19 Replies
Here is the error:
Continuation:
🤔
Does your offer resource have a graphql type defined?
actually nvm it must
Something strange is definitely going on here. What is the most recent working version for you?
🤔 the fact that it only happens if the attribute's name is status is pretty bonkers
do you have any arguments on that resource w/ the same name perhaps?
@Zach Daniel I did some tests and I found that version 0.25.0 was the last version that the compilation worked fine, after that version 0.25.1 and newer all have the same problem
Okay, so we have a slight design problem with deriving these types. The basic issue is that the arguments with the name
:status
are conflicting with the attribute with the name :status
. I've created a github issue to track the deprecation of this behavior. @barnabasj you'll be interested in this as well I'm sure. We will still support the map type work that you've done, but only for explicitly defined NewType
s that define those map constraints. https://github.com/ash-project/ash_graphql/issues/73GitHub
Remove auto types for everything except
Ash.Type.Enum
and `Ash.Ty...The maintenance burden of deriving types automagically for things like this: argument :foo, :atom do constraints one_of: [:foo, :bar, :baz] end is surprisingly high, and is surprisingly easy to get...
To resolve this @Blibs what you will need to do is define an
Ash.Type.Enum
for your status, and use that both in the arguments and in the attribute
Then in the attribute and args you'd say:
So, @Zach Daniel , going back to this issue... Is there an alternative to creating a
user Ash.Type.Enum
for that case? I mean, that works, but it is inconvenient since this attribute would be the only one that is different from the rest, I would rather keep as it was before and adding something specific in the graphql
code block.
I tried something like this but it didn't work:
Can we have some way to define the graphql_type
of an attribute directly in the graphql
code block, or some other workaround, so I don't need to create a new module just for it?But you would need to define the type in your absinthe schema somewhere, than you can just reference it here.
Ah, got it, thanks @barnabasj
Actually, I have another question about this. So, the conflicting action is this one:
A way to also fix this issue is just change the argument name to something like
:property_status
.
But, this action is never used in graphql, I don't add it into the queries
or mutations
code blocks of the graphql
code block at all, in other words, there is no public GraphQL API to access that action.
In that case, why does this action still creates the conflict? I understand that if I added it into my queries
code block, it would create the conflict, but since I don't, why it is somehow affecting the AshGraphql
code generation?Probably just us not filtering that out when generating enums
Honestly though I’d suggest just creating the enum type and referring to it 🙂
Instead of repeating the same list of values multiple times in your resource.
Hmm, but I don ´t repeat it at all, I just add it in the attribute and that's it 🤔
Hmm…so you don’t have any action arguments that are of type atom that also list the values?
Does extracting it to a module fix the issue for you?
Yep, it fixes it because of the
def graphql_type, do: :thing_status
, but I'm not using it. In the end I just changed the argument name from :status
to :property_status
and called it a day.
Of course, I would love if Ash Graphql would filter out the actions that are not specified in the graphql do
code block since that would also resolve the issue (since I don't expose this action as a graphql api at all) and also, I would guess, make compilation faster (since it would avoid generate/compile graphql types for parts that are not used in graphql at all).I've added that change to
main
we should be filtering out argument definitions for actions that don't appear in ash_graphqlI will test it out ASAP
Hmm, doesn't seem to work, it still giving the same error
What line does the filtering? I can try see if it is actually filtering that out or not here to debug if you want
GitHub
ash_graphql/lib/ash_graphql.ex at main · ash-project/ash_graphql
An absinthe backed graphql API extension for the Ash Framework - ash_graphql/lib/ash_graphql.ex at main · ash-project/ash_graphql
actually its here: https://github.com/ash-project/ash_graphql/blob/main/lib/ash_graphql.ex#L544
GitHub
ash_graphql/lib/ash_graphql.ex at main · ash-project/ash_graphql
An absinthe backed graphql API extension for the Ash Framework - ash_graphql/lib/ash_graphql.ex at main · ash-project/ash_graphql
Ah, damn, I changed :ash to git, not :ash_graphql 🤦♂️ It is working fine