GraphqlMarkdown.OperationDetailsHelpers (Graphql Markdown v1.2.0)

Copy Markdown View Source

Builds the details of an example operation (query, mutation or subscription): its name, arguments and the selection set to request.

The selection set recurses into object, interface and union types down to a configurable depth, selecting scalar and enum leaves, so that the example is valid GraphQL. A field whose type is already selected further up the same path is skipped, which breaks cycles such as friends: [Character].

Summary

Types

One entry of a selection set: a field, or an inline fragment on a possible type of an interface or union. Leaves have an empty selections list.

Functions

The number of nested selection-set levels an example operation contains by default.

Creates a map with the details of an operation: the operation type and name, its arguments, its (unwrapped) return type and the selection set.

Types

argument()

@type argument() :: %{name: String.t(), type: String.t(), required: boolean()}

graphql_operation_details()

@type graphql_operation_details() :: %{
  operation_type: String.t(),
  operation_name: String.t(),
  arguments: [argument()],
  return_type: return_type(),
  selections: [selection()]
}

return_type()

@type return_type() :: %{name: String.t(), kind: String.t()}

selection()

@type selection() ::
  %{name: String.t(), selections: [selection()]}
  | %{on: String.t(), selections: [selection()]}

One entry of a selection set: a field, or an inline fragment on a possible type of an interface or union. Leaves have an empty selections list.

Functions

default_depth()

@spec default_depth() :: pos_integer()

The number of nested selection-set levels an example operation contains by default.

generate_operation_details(type, field, schema_details, options \\ [])

@spec generate_operation_details(
  String.t(),
  map(),
  GraphqlMarkdown.Schema.t(),
  keyword()
) ::
  graphql_operation_details()

Creates a map with the details of an operation: the operation type and name, its arguments, its (unwrapped) return type and the selection set.

Options:

  • :depth - how many nested selection-set levels to generate (default 2). 1 selects only the leaves of the return type.