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:
attribute :status, :atom do
allow_nil? false

constraints one_of: [:submitted, :denied, :withdrawn, :evaluating, :accepted, :done, :old]

default :submitted
end
attribute :status, :atom do
allow_nil? false

constraints one_of: [:submitted, :denied, :withdrawn, :evaluating, :accepted, :done, :old]

default :submitted
end
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
Blibs
BlibsOP2y ago
Here is the error:
== Compilation error in file lib/marketplace/graphql/schema.ex ==
** (Absinthe.Schema.Error) Compilation failed:
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:3244

In field Status, :offer_status is not defined in your schema.

Types must exist if referenced.
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:1925

In field Eq, :offer_status is not defined in your schema.

Types must exist if referenced.
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:1925

In field Not_eq, :offer_status is not defined in your schema.

Types must exist if referenced.
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:1975

In field In, :offer_status is not defined in your schema.

Types must exist if referenced.
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:1925

In field Less_than, :offer_status is not defined in your schema.

Types must exist if referenced.
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:1925

In field Greater_than, :offer_status is not defined in your schema.

Types must exist if referenced.
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:1925

In field Less_than_or_equal, :offer_status is not defined in your schema.
== Compilation error in file lib/marketplace/graphql/schema.ex ==
** (Absinthe.Schema.Error) Compilation failed:
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:3244

In field Status, :offer_status is not defined in your schema.

Types must exist if referenced.
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:1925

In field Eq, :offer_status is not defined in your schema.

Types must exist if referenced.
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:1925

In field Not_eq, :offer_status is not defined in your schema.

Types must exist if referenced.
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:1975

In field In, :offer_status is not defined in your schema.

Types must exist if referenced.
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:1925

In field Less_than, :offer_status is not defined in your schema.

Types must exist if referenced.
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:1925

In field Greater_than, :offer_status is not defined in your schema.

Types must exist if referenced.
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:1925

In field Less_than_or_equal, :offer_status is not defined in your schema.
Continuation:
Types must exist if referenced.
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:1925

In field Greater_than_or_equal, :offer_status is not defined in your schema.

Types must exist if referenced.


(absinthe 1.7.1) lib/absinthe/schema.ex:392: Absinthe.Schema.__after_compile__/2
(stdlib 4.3) lists.erl:1350: :lists.foldl/3
Types must exist if referenced.
---------------------------------------
## Locations
/run/host/home/sezdocs/projects/rebuilt/platform/marketplace/deps/ash_graphql/lib/resource/resource.ex:1925

In field Greater_than_or_equal, :offer_status is not defined in your schema.

Types must exist if referenced.


(absinthe 1.7.1) lib/absinthe/schema.ex:392: Absinthe.Schema.__after_compile__/2
(stdlib 4.3) lists.erl:1350: :lists.foldl/3
ZachDaniel
ZachDaniel2y ago
🤔 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?
Blibs
BlibsOP2y ago
@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
Blibs
BlibsOP2y ago
In case that helps, here is the resource code:
ZachDaniel
ZachDaniel2y ago
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 NewTypes that define those map constraints. https://github.com/ash-project/ash_graphql/issues/73
GitHub
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...
ZachDaniel
ZachDaniel2y ago
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
defmodule YourApp.Types.Thing.Status do
use Ash.Type.Enum, values: [:submitted, :denied, :withdrawn, :evaluating, :accepted, :done, :old]

def graphql_type, do: :thing_status
end
defmodule YourApp.Types.Thing.Status do
use Ash.Type.Enum, values: [:submitted, :denied, :withdrawn, :evaluating, :accepted, :done, :old]

def graphql_type, do: :thing_status
end
Then in the attribute and args you'd say:
attribute :status, YourApp.Types.Thing.Status
...
argument :status, YourApp.Types.Thing.Status
attribute :status, YourApp.Types.Thing.Status
...
argument :status, YourApp.Types.Thing.Status
Blibs
BlibsOP2y ago
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:
field_names status: :property_status
field_names status: :property_status
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?
barnabasj
barnabasj2y ago
Ash HQ
Ash.Resource
View the documentation for Ash.Resource on Ash HQ.
barnabasj
barnabasj2y ago
But you would need to define the type in your absinthe schema somewhere, than you can just reference it here.
Blibs
BlibsOP2y ago
Ah, got it, thanks @barnabasj Actually, I have another question about this. So, the conflicting action is this one:
read :list_by_status do
argument :status, :atom, allow_nil?: false

pagination offset?: true, countable: true, default_limit: 10, required?: true

filter expr(
property.organization_id == ^actor(:organization_id) and
status == ^arg(:status)
)

prepare build(sort: [updated_at: :desc])
end
read :list_by_status do
argument :status, :atom, allow_nil?: false

pagination offset?: true, countable: true, default_limit: 10, required?: true

filter expr(
property.organization_id == ^actor(:organization_id) and
status == ^arg(:status)
)

prepare build(sort: [updated_at: :desc])
end
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?
ZachDaniel
ZachDaniel2y ago
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.
Blibs
BlibsOP2y ago
Hmm, but I don ´t repeat it at all, I just add it in the attribute and that's it 🤔
ZachDaniel
ZachDaniel2y ago
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?
Blibs
BlibsOP2y ago
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).
ZachDaniel
ZachDaniel2y ago
I've added that change to main we should be filtering out argument definitions for actions that don't appear in ash_graphql
Blibs
BlibsOP2y ago
I 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
ZachDaniel
ZachDaniel2y ago
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
ZachDaniel
ZachDaniel2y ago
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
Blibs
BlibsOP2y ago
Ah, damn, I changed :ash to git, not :ash_graphql 🤦‍♂️ It is working fine

Did you find this page helpful?