Created
January 22, 2022 18:25
-
-
Save maartenvanvliet/3f1026812d5ebd7b822c4a6f0b54a12f to your computer and use it in GitHub Desktop.
removes __schema node from a query.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SkipIntrospection do | |
@behaviour Absinthe.Phase | |
def run(doc, options \\ []) do | |
node = Absinthe.Blueprint.prewalk(doc, &handle_node/1) | |
{:ok, node} | |
end | |
defp handle_node(%Absinthe.Blueprint.Document.Operation{} = node) do | |
selections = | |
node.selections | |
|> Enum.reduce([], fn e, acc -> | |
if e.schema_node.identifier == :__schema do | |
acc | |
else | |
[e | acc] | |
end | |
end) | |
|> Enum.reverse() | |
%{node | selections: selections} | |
end | |
defp handle_node(node) do | |
node | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment