ash-project / ash_graphql

The extension for building GraphQL APIs with Ash
https://hexdocs.pm/ash_graphql
MIT License
73 stars 49 forks source link

Unable to update calculation type with attribute_types #104

Closed skanderm closed 10 months ago

skanderm commented 10 months ago

Is your feature request related to a problem? Please describe. Hello! This may either be a bug or a feature request, but it seems I'm unable to update a calculation's graphql type through attribute_types.

Describe the solution you'd like I'd like to wrap a calculation's type in a non_null. More specifically, I have a calculation with type {:array, {:array, {:array, :integer}}} which translates to [[[Int!]!]!] but I'd like one more non-null on the end there via attribute_types {:non_null, {:array, {:array, {:array, :integer}}}}.

Describe alternatives you've considered I've tried creating a new Ash type using use Ash.Type.NewType but I ran into errors trying out a subtype of {:array, ...}. Ditto with a full use Ash.Type, where for some reason even the simplified def graphql_type(_), do: {:array, :integer} even gave me this error:

== Compilation error in file lib/myapp_web/schema.ex ==
** (FunctionClauseError) no function clause matching in Absinthe.Phase.Schema.Validation.TypeReferencesExist.inner_type/1

    The following arguments were given to Absinthe.Phase.Schema.Validation.TypeReferencesExist.inner_type/1:

        # 1
        {:array, :integer}

    Attempted function clauses (showing 3 out of 3):

        defp inner_type(value) when is_binary(value) or is_atom(value)
        defp inner_type(%{of_type: type})
        defp inner_type(%Absinthe.Blueprint.TypeReference.Name{name: name})

    (absinthe 1.7.6) lib/absinthe/phase/schema/validation/type_references_exist.ex:122: Absinthe.Phase.Schema.Validation.TypeReferencesExist.inner_type/1
    (absinthe 1.7.6) lib/absinthe/phase/schema/validation/type_references_exist.ex:104: Absinthe.Phase.Schema.Validation.TypeReferencesExist.check_or_error/4
    (absinthe 1.7.6) lib/absinthe/blueprint/transform.ex:16: anonymous fn/3 in 

Express the feature either with a change to resource syntax, or with a change to the resource interface

For example

  graphql do
    ...
    attribute_types my_calc: {:non_null, {:array, {:array, {:array, :integer}}}}
  end
zachdaniel commented 10 months ago

I believe you're looking for :list_of, not :array, since its absinthe terminology. With that said, you can also mark the calculation as allow_nil?: false to get the type you're looking for I believe.

skanderm commented 10 months ago

I believe you're looking for :list_of, not :array, since its absinthe terminology. With that said, you can also mark the calculation as allow_nil?: false to get the type you're looking for I believe.

Oh oops, that was a complete oversight. The allow_nil?: false worked just fine, thank you!