-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from CargoSense/resolution-inside-execution
Cleanup Resolution function signatures
- Loading branch information
Showing
22 changed files
with
214 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule ExGraphQL.Execution.Arguments do | ||
|
||
alias ExGraphQL.Execution.Literal | ||
|
||
def build(ast_arguments, schema_arguments, variables) do | ||
schema_arguments | ||
|> Enum.reduce(%{}, fn ({name, definition}, acc) -> | ||
schema_arg_name = name |> to_string | ||
ast_arg = ast_arguments |> Enum.find(&(&1.name == schema_arg_name)) | ||
if ast_arg do | ||
ast_value = if ast_arg.value do | ||
Literal.coerce(definition.type, ast_arg.value, variables) | ||
else | ||
nil | ||
end | ||
variable_value = variables[ast_arg.name] | ||
default_value = definition.default_value | ||
acc | ||
|> Map.put(name, ast_value || variable_value || default_value) | ||
else | ||
acc | ||
end | ||
end) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule ExGraphQL.Execution.Literal do | ||
|
||
alias ExGraphQL.Type | ||
alias ExGraphQL.Language | ||
|
||
def coerce(input_type, input_value, variables) do | ||
input_type | ||
|> Type.unwrap | ||
|> coerce_unwrapped(input_value, variables) | ||
end | ||
|
||
defp coerce_unwrapped(%Type.Scalar{} = scalar, %{value: internal_value}, _variables) do | ||
internal_value | ||
|> scalar.parse_value.() | ||
end | ||
defp coerce_unwrapped(definition_type, %Language.Variable{name: name}, variables) do | ||
variable_value = variables |> Map.get(name) | ||
coerce(definition_type, variable_value, variables) | ||
end | ||
defp coerce_unwrapped(%Type.Scalar{} = scalar, bare, _variables) do | ||
bare | ||
|> to_string | ||
|> scalar.parse_value.() | ||
end | ||
|
||
defp coerce_unwrapped(%Type.InputObjectType{fields: thunked_schema_fields}, %{fields: input_fields}, variables) do | ||
schema_fields = thunked_schema_fields |> Type.unthunk | ||
input_fields | ||
|> Enum.reduce(%{}, fn (%{name: name, value: input_value}, acc) -> | ||
case schema_fields |> Map.get(name |> String.to_existing_atom) do | ||
nil -> acc | ||
field -> acc |> Map.put(name |> to_string, coerce(field.type, input_value, variables)) | ||
end | ||
end) | ||
end | ||
defp coerce_unwrapped(%Type.Enum{values: enum_values}, %{value: raw_value}, _variables) do | ||
enum_values |> Map.get(raw_value) | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.