Skip to content

Commit

Permalink
sdl based blueprint inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryseed committed Jun 1, 2019
1 parent 15e42ce commit d3d9dcd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
12 changes: 10 additions & 2 deletions lib/absinthe/schema/notation/sdl_render.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions test/absinthe/schema/sdl_render_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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 !!
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d3d9dcd

Please sign in to comment.