class Skylight::Core::Normalizers::GraphQL::ExecuteMultiplex

Public Instance Methods

normalize_after(trace, _span, _name, payload) click to toggle source
# File lib/skylight/core/normalizers/graphql/base.rb, line 71
def normalize_after(trace, _span, _name, payload)
  # This is in normalize_after because the queries may not have
  # an assigned operation name before they are executed.
  # For example, if you send a single query with a defined operation name, e.g.:
  # ```graphql
  #   query MyNamedQuery { user(id: 1) { name } }
  # ```
  # ... but do _not_ send the operationName request param, the GraphQL docs[1]
  # specify that the executor should use the operation name from the definition.
  #
  # In graphql-ruby's case, the calculation of the operation name is lazy, and
  # has not been done yet at the point where execute_multiplex starts.
  # [1] https://graphql.org/learn/serving-over-http/#post-request
  queries, has_errors = payload[:multiplex].queries.each_with_object([Set.new, Set.new]) do |query, (names, errors)|
    names << extract_query_name(query)
    errors << query.static_errors.any?
  end

  trace.endpoint = "graphql:#{queries.sort.join('+')}"
  trace.compound_response_error_status = if has_errors.all?
                                           :all
                                         elsif !has_errors.none?
                                           :partial
                                         end
end