From d3d9dcde3bc6623ff839148fbe21df7f6bef2b6b Mon Sep 17 00:00:00 2001 From: Vince Foley Date: Fri, 31 May 2019 22:12:48 -0700 Subject: [PATCH] sdl based blueprint inspect --- lib/absinthe/schema/notation/sdl_render.ex | 12 ++++++++++-- test/absinthe/schema/sdl_render_test.exs | 12 +++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/absinthe/schema/notation/sdl_render.ex b/lib/absinthe/schema/notation/sdl_render.ex index fb686377e9..cd716f3ecc 100644 --- a/lib/absinthe/schema/notation/sdl_render.ex +++ b/lib/absinthe/schema/notation/sdl_render.ex @@ -394,18 +394,26 @@ defmodule Absinthe.Schema.Notation.SDL.Render do concat(["[", render(type), "]"]) end - def render(%Blueprint.TypeReference.List{type_name: type_name}) do + def render(%Blueprint.TypeReference.List{type_name: type_name}) when is_binary(type_name) do concat(["[", string(type_name), "]"]) end + def render(%Blueprint.TypeReference.List{of_type: of_type}) do + concat(["[", render(of_type), "]"]) + end + def render(%{"ofType" => type, "kind" => "NON_NULL"}) do concat([render(type), "!"]) end - def render(%Blueprint.TypeReference.NonNull{type_name: type_name}) do + def render(%Blueprint.TypeReference.NonNull{type_name: type_name}) when is_binary(type_name) do concat([string(type_name), "!"]) end + def render(%Blueprint.TypeReference.NonNull{of_type: of_type}) do + concat([render(of_type), "!"]) + end + def render(%{"name" => name}) do string(name) end diff --git a/test/absinthe/schema/sdl_render_test.exs b/test/absinthe/schema/sdl_render_test.exs index bfab9ced0d..5a500b39b9 100644 --- a/test/absinthe/schema/sdl_render_test.exs +++ b/test/absinthe/schema/sdl_render_test.exs @@ -11,7 +11,7 @@ defmodule SdlRenderTest do TODO: - [ ] `Inspect` protocol for Blueprint structs!!!!! - [ ] Generate `Blueprint` from introspection - instead of render(introspection) + remove from_introspection Make tickets: - default values !! @@ -82,8 +82,14 @@ defmodule SdlRenderTest do end test "Render SDL from blueprint defined with SDL" do - rendered_sdl = - Absinthe.Schema.Notation.SDL.Render.from_blueprint(SdlTestSchema.__absinthe_blueprint__()) + pipeline = [ + Absinthe.Phase.Schema.Debugger + ] + + {:ok, blueprint, _phases} = + Absinthe.Pipeline.run(SdlTestSchema.__absinthe_blueprint__(), pipeline) + + rendered_sdl = inspect(blueprint, pretty: true) assert rendered_sdl == SdlTestSchema.sdl() end