Skip to content
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

Better error for typos in Aggregates when using AshGraphQL #115

Open
BryanJBryce opened this issue Mar 9, 2024 · 0 comments
Open

Better error for typos in Aggregates when using AshGraphQL #115

BryanJBryce opened this issue Mar 9, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@BryanJBryce
Copy link

BryanJBryce commented Mar 9, 2024

Is your feature request related to a problem? Please describe.
The AshGraphQL library gives an unhelpful error when there is a typo in an Aggregate definition where if AshGraphQL is not used Spark gives a helpful error.

Describe the solution you'd like
Somehow the Spark error should be surfaced or the AshGraphQL error should give as good of information as the Spark error

Additional context
I've created an example repo which has a simple project with two branches which contain the typo error with the only difference being that one branch has AshGraphQL installed and the other does not.

https://github.com/BryceLabs/ash_issues_examples/tree/aggregate-typo-issue
https://github.com/BryceLabs/ash_issues_examples/tree/aggregate-typo-issue-graphql

In the project there is an Order resource which has_many OrderItem resources. Order aggregates the subtotal calculation of OrderItem via a sum. However, there is a typo:

aggregates do sum :subtotal, :order_items, :sub_total end

sub_total should be subtotal

The error given by the plain Ash project is this:

** (EXIT from #PID<0.98.0>) an exception was raised:
** (Spark.Error.DslError) [App.Store.Order]
aggregates -> sub_total:
All aggregates fields must be attributes or calculations. Got: :sub_total
(ash 2.19.14) lib/ash/resource/verifiers/ensure_aggregate_field_is_attribute_or_calculation.ex:23: anonymous fn/3 in Ash.Resource.Verifiers.EnsureAggregateFieldIsAttributeOrCalculation.verify/1
(elixir 1.16.1) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash 2.19.14) lib/ash/resource/verifiers/ensure_aggregate_field_is_attribute_or_calculation.ex:10: Ash.Resource.Verifiers.EnsureAggregateFieldIsAttributeOrCalculation.verify/1
lib/app/store/resources/order.ex:1: anonymous fn/1 in App.Store.Order.verify_spark_dsl/1
(elixir 1.16.1) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
lib/app/store/resources/order.ex:1: App.Store.Order.verify_spark_dsl/1
(elixir 1.16.1) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
(elixir 1.16.1) lib/module/parallel_checker.ex:271: Module.ParallelChecker.check_module/3

The error given when AshGraphQL is installed is this:

== Compilation error in file lib/app/schema.ex ==
** (UndefinedFunctionError) function nil.embedded?/0 is undefined. If you are using the dot syntax, such as module.function(), make sure the left-hand side of the dot is a module atom
nil.embedded?()
(ash_graphql 0.27.0) lib/resource/resource.ex:2619: AshGraphql.Resource.filterable?/2
(elixir 1.16.1) lib/enum.ex:4277: Enum.filter_list/2
(ash_graphql 0.27.0) lib/resource/resource.ex:2532: AshGraphql.Resource.aggregate_filter_fields/2
(ash_graphql 0.27.0) lib/resource/resource.ex:2498: AshGraphql.Resource.resource_filter_fields/2
(ash_graphql 0.27.0) lib/resource/resource.ex:1395: AshGraphql.Resource.args/5
(ash_graphql 0.27.0) lib/resource/resource.ex:528: anonymous fn/7 in AshGraphql.Resource.queries/6
(elixir 1.16.1) lib/enum.ex:1700: Enum."-map/2-lists^map/1-1-"/2

Associated Elixir Forum post: https://elixirforum.com/t/aggregates-causing-error-in-ashgraphql/62112

@BryanJBryce BryanJBryce added the enhancement New feature or request label Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant