From 761a60f3b4a548ac48c93e480c80aa1fe6c7d5d7 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Sat, 11 May 2024 18:20:42 -0400 Subject: [PATCH] chore: add an experimental `auto_import_types?` option to `use AshGraphql` this is to solve a very specific technical issue around conflicts with using `import_types` on your schema, and having conflicts with a named type you already have defined, and the types we import --- lib/ash_graphql.ex | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/ash_graphql.ex b/lib/ash_graphql.ex index 9a2b83c..4ebdfba 100644 --- a/lib/ash_graphql.ex +++ b/lib/ash_graphql.ex @@ -32,12 +32,22 @@ defmodule AshGraphql do end defmacro __using__(opts) do + auto_import_types = + if Keyword.get(opts, :auto_import_absinthe_types?, true) do + quote do + import_types(Absinthe.Type.Custom) + import_types(AshGraphql.Types.JSON) + import_types(AshGraphql.Types.JSONString) + end + end + quote bind_quoted: [ domains: opts[:domains], domain: opts[:domain], action_middleware: opts[:action_middleware] || [], define_relay_types?: Keyword.get(opts, :define_relay_types?, true), - relay_ids?: Keyword.get(opts, :relay_ids?, false) + relay_ids?: Keyword.get(opts, :relay_ids?, false), + auto_import_types: Macro.escape(auto_import_types) ], generated: true do require Ash.Domain.Info @@ -219,9 +229,7 @@ defmodule AshGraphql do end if first? do - import_types(Absinthe.Type.Custom) - import_types(AshGraphql.Types.JSON) - import_types(AshGraphql.Types.JSONString) + Code.eval_quoted(auto_import_types, [], __ENV__) end @pipeline_modifier Module.concat(domain, AshTypes)