Skip to content

Commit

Permalink
Add typespecs and doc for OperationDetailsHelpers functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Clifton McIntosh committed Jun 23, 2024
1 parent 7ffa07c commit 66f0e3e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/graphql_markdown/operation_details_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ defmodule GraphqlMarkdown.OperationDetailsHelpers do
return_type: return_type()
}

@doc """
Creates a map with the details of a query or mutation. The details created include
the operation type, operation name, arguments, and return type.
"""
@spec generate_operation_details(String.t(), map(), GraphqlMarkdown.Schema.t()) ::
graphql_operation_details()
def generate_operation_details(type, field, schema_details) do
Expand All @@ -50,6 +54,7 @@ defmodule GraphqlMarkdown.OperationDetailsHelpers do
operation_details
end

@spec operation_arguments([map()]) :: [argument()]
defp operation_arguments(args) do
Enum.map(args, fn arg ->
arg_type = arg["type"]
Expand All @@ -64,6 +69,7 @@ defmodule GraphqlMarkdown.OperationDetailsHelpers do
end)
end

@spec return_fields(map(), GraphqlMarkdown.Schema.t()) :: return_type()
defp return_fields(%{"name" => name, "kind" => "OBJECT"}, schema_details) do
object_fields =
schema_details
Expand All @@ -86,10 +92,12 @@ defmodule GraphqlMarkdown.OperationDetailsHelpers do
defp return_fields(return_type, _schema_details) do
%{
name: return_type["name"],
kind: return_type["kind"]
kind: return_type["kind"],
fields: []
}
end

@spec return_field_type(map()) :: String.t()
defp return_field_type(%{"type" => %{"kind" => "NON_NULL"}} = field) do
get_in(field, ["type", "ofType", "kind"])
end
Expand Down

0 comments on commit 66f0e3e

Please sign in to comment.