AshGraphql fails to compile when using uuid_v7_primary_key in resource

I have a resource with uuid_v7_primary_key :id, I’m trying to use AshGraphql with it, but when I try to compile the project, it fails with:

== Compilation error in file lib/core/graphql/schema.ex ==
** (RuntimeError) Could not determine graphql field type for Ash.Type.UUIDv7 on Core.Marketplace.Ap.Appointment.id

If this is an `Ash.Type.Enum` or a custom type, you can add `def graphql_type/1` or `def graphql_input_type/1`
to your type. This does not *define* the type, but tells us what type to use for it, so you may need
to add a type to your absinthe schema if it does not map to a built in absinthe data type.

## Ash.Type.NewType

The exception to the above are special instances of `Ash.Type.NewType`. If you have an `Ash.Type.NewType`,
that is a subset of `:union` or `:map`(with the `:fields` constraint), AshGraphql will define that type for you.
If you are seeing this message, it likely means that you are missing `def graphql_type/1` or `def graphql_input_type/1`
on your type definition.

    (ash_graphql 1.3.3) lib/resource/resource.ex:4423: AshGraphql.Resource.get_specific_field_type/4
    (ash_graphql 1.3.3) lib/resource/resource.ex:1651: anonymous fn/3 in AshGraphql.Resource.read_args/4
    (elixir 1.17.2) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
    (ash_graphql 1.3.3) lib/resource/resource.ex:1534: AshGraphql.Resource.args/7
    (ash_graphql 1.3.3) lib/resource/resource.ex:626: anonymous fn/6 in AshGraphql.Resource.queries/7
    (elixir 1.17.2) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.17.2) lib/enum.ex:4353: Enum.flat_map_list/2
    (elixir 1.17.2) lib/enum.ex:4354: Enum.flat_map_list/2

It seems it can’t find a definition for Ash.Type.UUIDv7 for graphql, shouldn’t that have already built-in support?

Here is my schema file:

defmodule Core.GraphQL.Schema do
  @moduledoc false

  alias Core.GraphQL.{Middlewares, Schema.Types}

  alias Core.Marketplace.{Accounts, Admin}

  use Absinthe.Schema

  @domains [
    Core.Marketplace.Markets,
    Core.Marketplace.Accounts,
    Core.Marketplace.Invoices,
    Core.Marketplace.Analytics,
    Core.Marketplace.Ap,
    Core.Pacman.Markets
  ]

  use AshGraphql, domains: @domains

  @not_auth_domains [
    :register_with_password,
    :sign_in_with_password,
    :request_password_reset,
    :password_reset_with_password
  ]

  import_types Types
  import_types Accounts.User.GraphQL
  import_types Admin.FeatureFlag.GraphQL

  query do
    import_fields :accounts_user_queries
    import_fields :admin_feature_flag_queries
  end

  mutation do
  end

  def middleware(middleware, field, obj) do
    if obj.identifier in [:query, :subscription, :mutation] and
         field.identifier not in @not_auth_domains do
      [Middlewares.EnsureAuthenticated | middleware]
    else
      middleware
    end
  end

  def plugins, do: [Absinthe.Middleware.Dataloader | Absinthe.Plugin.defaults()]
end

Yes, this was an oversight on my part. Can you try main of ash_graphql? I’ve just pushed a fix up.

2 Likes

Yep, that fixed it

1 Like