Skip to content

Commit

Permalink
Clear compilation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce committed Dec 17, 2015
1 parent eaf3b78 commit fc69dfc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
34 changes: 26 additions & 8 deletions lib/ex_graphql/execution.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule ExGraphQL.Execution do
@type result_t :: %{data: %{binary => any}, errors: [error_t]}

@type t :: %{schema: Type.Schema.t, document: Language.Document.t, variables: map, validate: boolean, selected_operation: ExGraphQL.Type.ObjectType.t, operation_name: atom, errors: [error_t], categorized: boolean, strategy: atom, adapter: atom}
defstruct schema: nil, document: nil, variables: %{}, fragments: %{}, operations: %{}, validate: true, selected_operation: nil, operation_name: nil, errors: [], categorized: false, strategy: nil, adapter: ExGraphQL.Adapters.Passthrough
defstruct schema: nil, document: nil, variables: %{}, fragments: %{}, operations: %{}, validate: true, selected_operation: nil, operation_name: nil, errors: [], categorized: false, strategy: nil, adapter: nil

def run(execution, options \\ []) do
raw = execution |> Map.merge(options |> Enum.into(%{}))
Expand All @@ -20,7 +20,9 @@ defmodule ExGraphQL.Execution do
end

def prepare(execution) do
defined = execution |> categorize_definitions
defined = execution
|> add_configured_adapter
|> categorize_definitions
case selected_operation(defined) do
{:ok, operation} ->
%{defined | selected_operation: operation}
Expand All @@ -30,6 +32,22 @@ defmodule ExGraphQL.Execution do
end
end

@default_adapter ExGraphQL.Adapters.Passthrough

# Add the configured adapter, if needed
@spec add_configured_adapter(t) :: t
defp add_configured_adapter(%{adapter: nil} = execution) do
%{execution | adapter: configured_adapter}
end
defp add_configured_adapter(execution) do
execution
end

@spec configured_adapter :: atom
defp configured_adapter do
Application.get_env(:ex_graphql, :adapter, @default_adapter)
end

@spec format_error(binary | any, Language.t) :: error_t
def format_error(message, %{loc: %{start_line: line}}) when is_binary(message) do
%{message: message |> to_string, locations: [%{line: line, column: 0}]}
Expand All @@ -41,17 +59,17 @@ defmodule ExGraphQL.Execution do
end

@spec resolve_type(t, t, t) :: t | nil
def resolve_type(_target, nil = _child_type, _parent_type) do
nil
end
def resolve_type(target, nil = _child_type, %{__struct__: Type.Union} = parent_type) do
parent_type
|> Type.Union.resolve_type(target)
end
def resolve_type(_target, nil = _child_type, _parent_type) do
nil
end
def resolve_type(_target, %{__struct__: Type.Union} = child_type, parent_type) do
child_type |> Type.Union.member?(parent_type) || nil
end
def resolve_type(target, %{__struct__: Type.InterfaceType} = child_type, _parent_type) do
def resolve_type(target, %{__struct__: Type.InterfaceType} = _child_type, _parent_type) do
target
|> Type.InterfaceType.resolve_type
end
Expand Down Expand Up @@ -115,13 +133,13 @@ defmodule ExGraphQL.Execution do
op = ops |> Map.values |> List.first
{:ok, op}
end
def selected_operation(%{operations: ops, operation_name: name}) do
def selected_operation(%{operations: ops, operation_name: name}) when not is_nil(name) do
case Map.get(ops, name) do
nil -> {:error, "No operation with name: #{name}"}
op -> {:ok, op}
end
end
def selected_operation(%{operations: ops, operation_name: nil}) do
def selected_operation(%{operations: _, operation_name: nil}) do
{:error, "Multiple operations available, but no operation_name provided"}
end

Expand Down
6 changes: 3 additions & 3 deletions lib/ex_graphql/execution/resolution/field.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ defimpl ExGraphQL.Execution.Resolution, for: ExGraphQL.Language.Field do
@spec resolve(ExGraphQL.Language.Field.t,
ExGraphQL.Resolution.t,
ExGraphQL.Execution.t) :: {:ok, map} | {:error, any}
def resolve(%{name: name} = ast_node, %{parent_type: parent_type, target: target} = resolution, %{schema: schema, errors: errors, variables: variables, strategy: :serial} = execution) do
def resolve(%{name: name} = ast_node, %{parent_type: parent_type, target: target} = resolution, %{errors: errors, variables: variables, strategy: :serial} = execution) do
field = Type.field(parent_type, ast_node.name)
if field do
arguments = Execution.LiteralInput.arguments(ast_node.arguments, field.args, variables)
case field do
%{resolve: nil} ->
target |> Map.get(name |> String.to_atom) |> result(ast_node, field, resolution, execution)
%{resolve: resolver} ->
field.resolve.(arguments, execution, resolution)
resolver.(arguments, execution, resolution)
|> process_raw_result(ast_node, field, resolution, execution)
end
else
Expand All @@ -38,7 +38,7 @@ defimpl ExGraphQL.Execution.Resolution, for: ExGraphQL.Language.Field do
defp result(nil, _ast_node, _field, _resolution, execution) do
{:ok, nil, execution}
end
defp result(value, ast_node, field, resolution, execution) do
defp result(value, ast_node, field, _resolution, execution) do
resolved_type = Type.resolve_type(field.type, value)
Execution.Resolution.resolve(
resolved_type,
Expand Down
1 change: 0 additions & 1 deletion lib/ex_graphql/execution/resolution/selection_set.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defimpl ExGraphQL.Execution.Resolution, for: ExGraphQL.Language.SelectionSet do
alias ExGraphQL.Execution
alias ExGraphQL.Execution.Resolution
alias ExGraphQL.Language
alias ExGraphQL.Type

@spec resolve(Language.SelectionSet.t,
Resolution.t,
Expand Down
4 changes: 2 additions & 2 deletions lib/ex_graphql/execution/runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ defmodule ExGraphQL.Execution.Runner do
end
end

@spec execute(atom, ExGraphQL.Execution.t) :: {:ok, map} | {:error, any}
@spec execute(atom, ExGraphQL.Language.OperationDefinition.t, ExGraphQL.Execution.t) :: {:ok, Execution.result_t} | {:error, any}
defp execute(:query, operation, %{schema: %{query: query}} = execution) do
Resolution.resolve(operation, %Resolution{target: query}, %{execution | strategy: :serial})
end
defp execute(:mutation, operation, %{schema: %{mutation: mutation}} = execution) do
Resolution.resolve(operation, %Resolution{target: mutation}, %{execution | strategy: :serial})
end
defp execute(:subscription, %{schema: %{subscription: subscription}} = execution) do
defp execute(:subscription, operation, %{schema: %{subscription: subscription}} = execution) do
Resolution.resolve(operation, %Resolution{target: subscription}, %{execution | strategy: :serial})
end
defp execute(op_type, _operation, _execution) do
Expand Down

0 comments on commit fc69dfc

Please sign in to comment.