-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.5.0-rc.2: Calling functions in enum value 'as:' option results in compile error. #843
Comments
The schema compilation step is operating on the AST representation of the function call, it's not executing the function directly (by design). @benwilson512 Is this type of thing intended to work? |
No, you'd want to construct this type via the hydrate call back. We need to document how to do that though, and I'm not actually sure that |
@benwilson512 do you mean |
I believe I'm encountering this same issue. This is the code which fails to compile: defmodule MyApp.GraphQL.Schema.Types.Purchase do
use Absinthe.Schema.Notation
alias MyApp.Purchase
enum :purchase_payment_status do
@desc "The purchase has not yet been paid"
value(:not_paid, as: Purchase.payment_status().not_paid)
end
end Although the error message I get is slightly different, at least until I remove the use of an
And this works: defmodule MyApp.GraphQL.Schema.Types.Purchase do
use Absinthe.Schema.Notation
enum :purchase_payment_status do
@desc "The purchase has not yet been paid"
value(:not_paid, as: "Not Paid")
end
end |
Here's another slightly different case where I'm reusing a more complex fragment as my internal value (which I use in my Relay dataloader implementation): import Ecto.Query, only: :macros
enum :item_sort_field do
value(:id, as: :internal_id, description: "Order by ID")
value(:name, as: item_name_sort(), description: "Order by Item name")
end
defp item_name_sort do
dynamic([mi], fragment("?->>?", mi.payload, "Name"))
end And the error for that:
It doesn't appear that there's much of a workaround in this particular case since I'm actually trying to pass a value that needs to be generated by that function (rather than a constant string). I guess I could try something like passing an anonymous |
Hi @bgentry the thing you're seeing is unrelated. Expanding modules is supposed to work, having function calls in type definitions is not supposed to work. Specifically:
Is not supposed to work, even if Taking a step further though, it sort of looks like you're trying to use an |
@benwilson512 yeah, I understand that Ecto and Absinthe are different projects — that's not my issue 🙂 In existing released versions of Absinthe, you can use any value at all in the However, due to the significant rewriting of Absinthe in v1.5, some previously functional bits appear to be broken. That includes:
Regarding this |
Yeah it's unfortunate that calling (simple) functions will no longer work going forward. It means we will be having state or enumeration strings defined in multiple places |
Check out #859 , it's still possible via |
Ah, my bad. Thanks for this. |
Environment
Expected behavior
Expected successful compilation, with enum values defined by function calls. (Worked in 1.4)
Actual behavior
Relevant Schema/Middleware Code
The text was updated successfully, but these errors were encountered: