GraphqlMarkdown.MarkdownHelpers (Graphql Markdown v1.1.0)

Copy Markdown View Source

A set of helpers to generate proper markdown easily

Summary

Functions

The deprecation notice for a field, argument or enum value, or an empty string when it is not deprecated.

Joins a (possibly nested) list of lines into a document.

Makes a value safe to place inside a markdown table cell: pipes are escaped so they do not start a new column, and line breaks become <br> so the row is not split.

Builds the description cell for a field or argument, appending the default value sentence when there is one.

Generates a code block for a GraphQL operation. Only the top-level fields returned are represented in the code block. When one of the fields returned is an object, the object's fields are not included in the code block.

Joins sentence fragments with a period and a space. Empty and nil fragments are skipped, and a fragment that already ends with a period is not given a second one.

Functions

anchor(text, anchor_text \\ nil)

@spec anchor(String.t(), String.t() | nil) :: String.t()

capitalize_first(text)

@spec capitalize_first(String.t()) :: String.t()

code(text)

@spec code(String.t()) :: String.t()

default_value(defaultValue)

@spec default_value(any()) :: String.t()

deprecation(arg1)

@spec deprecation(map()) :: String.t()

The deprecation notice for a field, argument or enum value, or an empty string when it is not deprecated.

document(lines)

@spec document([String.t() | nil | list()]) :: String.t()

Joins a (possibly nested) list of lines into a document.

Every line is terminated by a newline; an empty string produces a blank line. Nested lists are flattened, so builders can return lists of lines freely, and nil entries are skipped.

escape_cell(text)

@spec escape_cell(String.t() | nil) :: String.t()

Makes a value safe to place inside a markdown table cell: pipes are escaped so they do not start a new column, and line breaks become <br> so the row is not split.

field_description(description, default)

@spec field_description(String.t() | nil, any()) :: String.t()

Builds the description cell for a field or argument, appending the default value sentence when there is one.

graphql_operation_code_block(operation_details)

Generates a code block for a GraphQL operation. Only the top-level fields returned are represented in the code block. When one of the fields returned is an object, the object's fields are not included in the code block.

Example:

  mutation RefreshIdToken($refreshToken: String!) {
    refreshIdToken(refreshToken: $refreshToken) {
      idToken
      userSsoDetails {
      }
    }
  }

In this example, the idToken field is a scalar, so it is included in the code block. In this example the userSsoDetails field is an object, so its fields are not included in the code block.

header(text, level, capitalize \\ false)

@spec header(String.t(), non_neg_integer(), boolean()) :: String.t()

link(text, url \\ nil)

@spec link(String.t(), String.t() | nil) :: String.t()

list(text, level, capitalize \\ false)

@spec list(String.t(), non_neg_integer(), boolean()) :: String.t()

new_line()

@spec new_line() :: String.t()

sentences(parts)

@spec sentences([String.t() | nil]) :: String.t()

Joins sentence fragments with a period and a space. Empty and nil fragments are skipped, and a fragment that already ends with a period is not given a second one.

table(fields, rows)

@spec table(list(), list()) :: String.t()