Packages

ash_graphql

1.11.0

The extension for building GraphQL APIs with Ash

Current section

Files

Jump to
ash_graphql lib default_metadata_handler.ex
Raw

lib/default_metadata_handler.ex

# SPDX-FileCopyrightText: 2020 ash_graphql contributors <https://github.com/ash-project/ash_graphql/graphs.contributors>
#
# SPDX-License-Identifier: MIT

defmodule AshGraphql.DefaultMetadataHandler do
  @moduledoc """
  Default handler for building response metadata.

  Returns complexity and duration_ms in the response extensions.
  """

  @doc """
  Builds metadata from execution info. Used when `response_metadata: true`.

  ## Info Map

  - `:complexity` - Query complexity (integer or nil if analysis disabled)
  - `:duration_ms` - Execution time in milliseconds
  - `:operation_name` - The GraphQL operation name (or nil)
  - `:operation_type` - `:query`, `:mutation`, or `:subscription`
  """
  def build_metadata(info) do
    %{
      complexity: info.complexity,
      duration_ms: info.duration_ms,
      operation_name: info.operation_name,
      operation_type: info.operation_type
    }
  end
end