Error message in a grapqhl mutation

== Compilation error in file lib/safari_web/graphql_schema.ex ==
** (KeyError) key :error_location not found in: %AshGraphql.Resource.Mutation{
name: :supplemental_document_create,
action: %Ash.Resource.Actions.Action{
name: :create_graphql,
description: nil,
returns: Safari.Types.SafariFileUploadInfo,
run: {Ash.Resource.Action.ImplementationFunction,
[
fun: &Safari.Outcrop.SupplementalDocument.run_0_generated_174EE05532EAC7ACD9CA74CC91968491/2
]},
... snip
}
(ash_graphql 1.7.6) lib/resource/resource.ex:1123: anonymous fn/5 in AshGraphql.Resource.mutation_types/4
(elixir 1.17.2) lib/enum.ex:4353: Enum.flat_map_list/2
(ash_graphql 1.7.6) lib/domain/domain.ex:293: anonymous fn/5 in AshGraphql.Domain.type_definitions/8
(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
(ash_graphql 1.7.6) lib/domain/domain.ex:284: AshGraphql.Domain.type_definitions/8
deps/ash_graphql/lib/ash_graphql.ex:334: Safari.Outcrop.AshTypes.run/2
(absinthe 1.7.9) lib/absinthe/pipeline.ex:408: Absinthe.Pipeline.run_phase/3
== Compilation error in file lib/safari_web/graphql_schema.ex ==
** (KeyError) key :error_location not found in: %AshGraphql.Resource.Mutation{
name: :supplemental_document_create,
action: %Ash.Resource.Actions.Action{
name: :create_graphql,
description: nil,
returns: Safari.Types.SafariFileUploadInfo,
run: {Ash.Resource.Action.ImplementationFunction,
[
fun: &Safari.Outcrop.SupplementalDocument.run_0_generated_174EE05532EAC7ACD9CA74CC91968491/2
]},
... snip
}
(ash_graphql 1.7.6) lib/resource/resource.ex:1123: anonymous fn/5 in AshGraphql.Resource.mutation_types/4
(elixir 1.17.2) lib/enum.ex:4353: Enum.flat_map_list/2
(ash_graphql 1.7.6) lib/domain/domain.ex:293: anonymous fn/5 in AshGraphql.Domain.type_definitions/8
(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
(ash_graphql 1.7.6) lib/domain/domain.ex:284: AshGraphql.Domain.type_definitions/8
deps/ash_graphql/lib/ash_graphql.ex:334: Safari.Outcrop.AshTypes.run/2
(absinthe 1.7.9) lib/absinthe/pipeline.ex:408: Absinthe.Pipeline.run_phase/3
I have not a clue what can be wrong here, even after trying to understand what makes this error out in the graphql lib code.
Solution:
looking at the commit that adds in the bit causing the error https://github.com/ash-project/ash_graphql/commit/4bcea7846fbcd752bce94047135ed83780f26204 and it suggests that you should have AshGraphql.Resource.Action structs but you have Mutation structs instead - so it might be defined in your schema incorrectly
Jump to solution
4 Replies
Oliver
OliverOP3w ago
From type:
defmodule Safari.Types.SupplementalDocumentnitialInput do
@moduledoc false
use Ash.Type.NewType,
subtype_of: :map,
constraints: [
fields: [
note: [type: :string, allow_nil?: true],
outcrop_id: [type: :integer, allow_nil?: true],
study_id: [type: :integer, allow_nil?: true]
]
]

def graphql_input_type(_), do: :supplemental_document_initial_input
end
defmodule Safari.Types.SupplementalDocumentnitialInput do
@moduledoc false
use Ash.Type.NewType,
subtype_of: :map,
constraints: [
fields: [
note: [type: :string, allow_nil?: true],
outcrop_id: [type: :integer, allow_nil?: true],
study_id: [type: :integer, allow_nil?: true]
]
]

def graphql_input_type(_), do: :supplemental_document_initial_input
end
Used as such
action :create_graphql, Safari.Types.SafariFileUploadInfo do
argument :note, Safari.Types.SupplementalDocumentnitialInput, allow_nil?: false

run fn %{
arguments: %{
note: note
}
},
%{actor: actor} ->
params =
note
|> Map.put(:file_data, %{category: "model", public: false})

__MODULE__.create(params, load: [file: :upload_url], actor: actor)
|> case do
{:ok, sd} ->
{
:ok,
sd.file.upload_url
}

other ->
other
end
end
end
action :create_graphql, Safari.Types.SafariFileUploadInfo do
argument :note, Safari.Types.SupplementalDocumentnitialInput, allow_nil?: false

run fn %{
arguments: %{
note: note
}
},
%{actor: actor} ->
params =
note
|> Map.put(:file_data, %{category: "model", public: false})

__MODULE__.create(params, load: [file: :upload_url], actor: actor)
|> case do
{:ok, sd} ->
{
:ok,
sd.file.upload_url
}

other ->
other
end
end
end
I have identical code in another resource, only the argument input type differs
Rebecca Le
Rebecca Le3w ago
so it looks like error_location was added for generic actions as queries, but not as mutations can you share how you've added that action to your graphql schema
Solution
Rebecca Le
Rebecca Le3w ago
looking at the commit that adds in the bit causing the error https://github.com/ash-project/ash_graphql/commit/4bcea7846fbcd752bce94047135ed83780f26204 and it suggests that you should have AshGraphql.Resource.Action structs but you have Mutation structs instead - so it might be defined in your schema incorrectly
Oliver
OliverOP3w ago
Ahhhhh yes I am pointing a create at it Thank you I will make an issue to see if we can make this error message more meaningful

Did you find this page helpful?