mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-19 21:03:09 +12:00
fix: ignore embedded resources accidentally placed in API
This commit is contained in:
parent
553152abef
commit
5d35cf092e
7 changed files with 26 additions and 17 deletions
|
@ -97,6 +97,7 @@ defmodule AshGraphql.Api do
|
|||
resource_types =
|
||||
api
|
||||
|> Ash.Api.resources()
|
||||
|> Enum.reject(&Ash.Resource.Info.embedded?/1)
|
||||
|> Enum.flat_map(fn resource ->
|
||||
if AshGraphql.Resource in Ash.Resource.Info.extensions(resource) do
|
||||
AshGraphql.Resource.type_definitions(resource, api, schema) ++
|
||||
|
@ -127,11 +128,11 @@ defmodule AshGraphql.Api do
|
|||
end
|
||||
end
|
||||
|
||||
def global_type_definitions(schema) do
|
||||
[mutation_error(schema), sort_order(schema)]
|
||||
def global_type_definitions(schema, env) do
|
||||
[mutation_error(schema, env), sort_order(schema, env)]
|
||||
end
|
||||
|
||||
defp sort_order(schema) do
|
||||
defp sort_order(schema, env) do
|
||||
%Absinthe.Blueprint.Schema.EnumTypeDefinition{
|
||||
module: schema,
|
||||
name: "SortOrder",
|
||||
|
@ -139,27 +140,31 @@ defmodule AshGraphql.Api do
|
|||
%Absinthe.Blueprint.Schema.EnumValueDefinition{
|
||||
module: schema,
|
||||
identifier: :desc,
|
||||
__reference__: AshGraphql.Resource.ref(env),
|
||||
name: "DESC",
|
||||
value: :desc
|
||||
},
|
||||
%Absinthe.Blueprint.Schema.EnumValueDefinition{
|
||||
module: schema,
|
||||
identifier: :asc,
|
||||
__reference__: AshGraphql.Resource.ref(env),
|
||||
name: "ASC",
|
||||
value: :asc
|
||||
}
|
||||
],
|
||||
identifier: :sort_order
|
||||
identifier: :sort_order,
|
||||
__reference__: AshGraphql.Resource.ref(env)
|
||||
}
|
||||
end
|
||||
|
||||
defp mutation_error(schema) do
|
||||
defp mutation_error(schema, env) do
|
||||
%Absinthe.Blueprint.Schema.ObjectTypeDefinition{
|
||||
description: "An error generated by a failed mutation",
|
||||
fields: error_fields(schema),
|
||||
identifier: :mutation_error,
|
||||
module: schema,
|
||||
name: "MutationError"
|
||||
name: "MutationError",
|
||||
__reference__: AshGraphql.Resource.ref(env)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ defmodule AshGraphql do
|
|||
|
||||
global_enums = AshGraphql.global_enums(apis, __MODULE__, __ENV__)
|
||||
|
||||
AshGraphql.Api.global_type_definitions(__MODULE__) ++
|
||||
AshGraphql.Api.global_type_definitions(__MODULE__, __ENV__) ++
|
||||
AshGraphql.Api.type_definitions(api, __MODULE__) ++
|
||||
global_enums ++
|
||||
embedded_types
|
||||
|
@ -74,6 +74,8 @@ defmodule AshGraphql do
|
|||
AshGraphql.Api.type_definitions(api, __MODULE__)
|
||||
end
|
||||
|
||||
Enum.filter(type_definitions, &is_nil(&1.__reference__))
|
||||
|
||||
new_defs =
|
||||
List.update_at(blueprint_with_mutations.schema_definitions, 0, fn schema_def ->
|
||||
%{
|
||||
|
@ -122,6 +124,7 @@ defmodule AshGraphql do
|
|||
%Absinthe.Blueprint.Schema.EnumValueDefinition{
|
||||
module: schema,
|
||||
identifier: value,
|
||||
__reference__: AshGraphql.Resource.ref(env),
|
||||
name: String.upcase(to_string(value)),
|
||||
value: value
|
||||
}
|
||||
|
@ -208,7 +211,7 @@ defmodule AshGraphql do
|
|||
__MODULE__
|
||||
)
|
||||
] ++
|
||||
AshGraphql.Resource.enum_definitions(embedded_type, __MODULE__)
|
||||
AshGraphql.Resource.enum_definitions(embedded_type, __MODULE__, __ENV__)
|
||||
else
|
||||
[
|
||||
AshGraphql.Resource.embedded_type_input(
|
||||
|
@ -217,7 +220,7 @@ defmodule AshGraphql do
|
|||
embedded_type,
|
||||
__MODULE__
|
||||
)
|
||||
] ++ AshGraphql.Resource.enum_definitions(embedded_type, __MODULE__)
|
||||
] ++ AshGraphql.Resource.enum_definitions(embedded_type, __MODULE__, __ENV__)
|
||||
end
|
||||
end)
|
||||
|> Enum.uniq_by(& &1.identifier)
|
||||
|
|
|
@ -1085,7 +1085,7 @@ defmodule AshGraphql.Resource do
|
|||
List.wrap(filter_input(resource, schema)) ++
|
||||
filter_field_types(resource, schema) ++
|
||||
List.wrap(page_of(resource, schema)) ++
|
||||
enum_definitions(resource, schema) ++
|
||||
enum_definitions(resource, schema, __ENV__) ++
|
||||
managed_relationship_definitions(resource, schema)
|
||||
end
|
||||
|
||||
|
@ -1935,7 +1935,7 @@ defmodule AshGraphql.Resource do
|
|||
String.to_atom(to_string(type) <> "_sort_field")
|
||||
end
|
||||
|
||||
def enum_definitions(resource, schema, only_auto? \\ false) do
|
||||
def enum_definitions(resource, schema, env, only_auto? \\ false) do
|
||||
atom_enums =
|
||||
resource
|
||||
|> get_auto_enums()
|
||||
|
@ -1951,6 +1951,7 @@ defmodule AshGraphql.Resource do
|
|||
%Absinthe.Blueprint.Schema.EnumValueDefinition{
|
||||
module: schema,
|
||||
identifier: value,
|
||||
__reference__: AshGraphql.Resource.ref(env),
|
||||
name: String.upcase(to_string(value)),
|
||||
value: value
|
||||
}
|
||||
|
@ -1975,6 +1976,7 @@ defmodule AshGraphql.Resource do
|
|||
%Absinthe.Blueprint.Schema.EnumValueDefinition{
|
||||
module: schema,
|
||||
identifier: sort_value,
|
||||
__reference__: AshGraphql.Resource.ref(env),
|
||||
name: String.upcase(to_string(sort_value)),
|
||||
value: sort_value
|
||||
}
|
||||
|
|
2
mix.exs
2
mix.exs
|
@ -83,7 +83,7 @@ defmodule AshGraphql.MixProject do
|
|||
[
|
||||
{:ash, ash_version("~> 1.50")},
|
||||
{:absinthe_plug, "~> 1.4"},
|
||||
{:absinthe, "~> 1.5.3"},
|
||||
{:absinthe, path: "deps/absinthe", override: true},
|
||||
{:dataloader, "~> 1.0"},
|
||||
{:jason, "~> 1.2"},
|
||||
{:ex_doc, "~> 0.22", only: :dev, runtime: false},
|
||||
|
|
6
mix.lock
6
mix.lock
|
@ -8,11 +8,11 @@
|
|||
"combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"},
|
||||
"comparable": {:hex, :comparable, "1.0.0", "bb669e91cedd14ae9937053e5bcbc3c52bb2f22422611f43b6e38367d94a495f", [:mix], [{:typable, "~> 0.1", [hex: :typable, repo: "hexpm", optional: false]}], "hexpm", "277c11eeb1cd726e7cd41c6c199e7e52fa16ee6830b45ad4cdc62e51f62eb60c"},
|
||||
"credo": {:hex, :credo, "1.5.5", "e8f422026f553bc3bebb81c8e8bf1932f498ca03339856c7fec63d3faac8424b", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "dd8623ab7091956a855dc9f3062486add9c52d310dfd62748779c4315d8247de"},
|
||||
"dataloader": {:hex, :dataloader, "1.0.8", "114294362db98a613f231589246aa5b0ce847412e8e75c4c94f31f204d272cbf", [:mix], [{:ecto, ">= 3.4.3 and < 4.0.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "eaf3c2aa2bc9dbd2f1e960561d616b7f593396c4754185b75904f6d66c82a667"},
|
||||
"dataloader": {:hex, :dataloader, "1.0.10", "a42f07641b1a0572e0b21a2a5ae1be11da486a6790f3d0d14512d96ff3e3bbe9", [:mix], [{:ecto, ">= 3.4.3 and < 4.0.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:telemetry, "~> 1.0 or ~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "54cd70cec09addf4b2ace14cc186a283a149fd4d3ec5475b155951bf33cd963f"},
|
||||
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
|
||||
"dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"},
|
||||
"earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"},
|
||||
"ecto": {:hex, :ecto, "3.7.1", "a20598862351b29f80f285b21ec5297da1181c0442687f9b8329f0445d228892", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d36e5b39fc479e654cffd4dbe1865d9716e4a9b6311faff799b6f90ab81b8638"},
|
||||
"ecto": {:hex, :ecto, "3.7.2", "44c034f88e1980754983cc4400585970b4206841f6f3780967a65a9150ef09a8", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a600da5772d1c31abbf06f3e4a1ffb150e74ed3e2aa92ff3cee95901657a874e"},
|
||||
"elixir_make": {:hex, :elixir_make, "0.6.3", "bc07d53221216838d79e03a8019d0839786703129599e9619f4ab74c8c096eac", [:mix], [], "hexpm", "f5cbd651c5678bcaabdbb7857658ee106b12509cd976c2c2fca99688e1daf716"},
|
||||
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
|
||||
"ets": {:hex, :ets, "0.8.1", "8ff9bcda5682b98493f8878fc9dbd990e48d566cba8cce59f7c2a78130da29ea", [:mix], [], "hexpm", "6be41b50adb5bc5c43626f25ea2d0af1f4a242fb3fad8d53f0c67c20b78915cc"},
|
||||
|
@ -33,7 +33,7 @@
|
|||
"mime": {:hex, :mime, "1.5.0", "203ef35ef3389aae6d361918bf3f952fa17a09e8e43b5aa592b93eba05d0fb8d", [:mix], [], "hexpm", "55a94c0f552249fc1a3dd9cd2d3ab9de9d3c89b559c2bd01121f824834f24746"},
|
||||
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
|
||||
"nimble_options": {:hex, :nimble_options, "0.3.7", "1e52dd7673d36138b1a5dede183b5d86dff175dc46d104a8e98e396b85b04670", [:mix], [], "hexpm", "2086907e6665c6b6579be54ef5001928df5231f355f71ed258f80a55e9f63633"},
|
||||
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
|
||||
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
|
||||
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
|
||||
"picosat_elixir": {:hex, :picosat_elixir, "0.2.1", "407dcb90755167fd9e3311b60565ff32ed0d234010363406c07cdb4175b95bc5", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "68f4bdb2ac3b594209e54625d3d58c9e2e98b90f2ec8e03235f66e88c9eda5fe"},
|
||||
"plug": {:hex, :plug, "1.11.0", "f17217525597628298998bc3baed9f8ea1fa3f1160aa9871aee6df47a6e4d38e", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2d9c633f0499f9dc5c2fd069161af4e2e7756890b81adcbb2ceaa074e8308876"},
|
||||
|
|
|
@ -9,7 +9,6 @@ defmodule AshGraphql.Test.Registry do
|
|||
entry(AshGraphql.Test.User)
|
||||
entry(AshGraphql.Test.NonIdPrimaryKey)
|
||||
entry(AshGraphql.Test.CompositePrimaryKey)
|
||||
entry(AshGraphql.Test.DoubleRelEmbed)
|
||||
entry(AshGraphql.Test.DoubleRelRecursive)
|
||||
entry(AshGraphql.Test.DoubleRelToRecursiveParentOfEmbed)
|
||||
end
|
||||
|
|
|
@ -10,6 +10,6 @@ defmodule AshGraphql.Test.DoubleRelEmbed do
|
|||
end
|
||||
|
||||
attributes do
|
||||
attribute(:recursive?, :string, default: "No, not I, but me dad be!")
|
||||
attribute(:recursive, :string, default: "No, not I, but me dad be!")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue