From 64e0d46305cfc689f31c8ab04175e6eafa554dbe Mon Sep 17 00:00:00 2001 From: shutangyu <79821006+shutangyu@users.noreply.github.com> Date: Fri, 26 Aug 2022 16:41:12 +0800 Subject: [PATCH] filter out non operation definition when naming that's possible includes sth like fragments in parsed result --- lib/new_relic/telemetry/absinthe/metadata.ex | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/new_relic/telemetry/absinthe/metadata.ex b/lib/new_relic/telemetry/absinthe/metadata.ex index 2c030406..43c031ec 100644 --- a/lib/new_relic/telemetry/absinthe/metadata.ex +++ b/lib/new_relic/telemetry/absinthe/metadata.ex @@ -1,4 +1,6 @@ defmodule NewRelic.Telemetry.Absinthe.Metadata do + alias Absinthe.Language.OperationDefinition + def resolver_name(middleware) do Enum.find_value(middleware, fn {{Absinthe.Resolution, :call}, resolver_fn} -> @@ -27,8 +29,9 @@ defmodule NewRelic.Telemetry.Absinthe.Metadata do def operation_span_name(input) when is_binary(input) do with {:ok, tokens} <- Absinthe.Lexer.tokenize(input), {:ok, parsed} <- :absinthe_parser.parse(tokens), - %Absinthe.Language.OperationDefinition{} = definition <- - Enum.find(parsed.definitions, fn x -> x.operation in [:query, :mutation] end) do + op_defs = Enum.filter(parsed.definitions, &match?(%OperationDefinition{}, &1)), + definition when not is_nil(definition) <- + Enum.find(ops_defs, fn x -> x.operation in [:query, :mutation] end) do "#{definition.operation}:#{definition.name || definition.selection_set.selections |> selections_name()}" end end