Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit fddf0a7

Browse files
author
Josh Price
authored
Fix 1.3 imperative assignment warnings (#103)
- Fix imperative assignment warnings - Update deps Closes #89
1 parent 7bc41a5 commit fddf0a7

File tree

4 files changed

+54
-56
lines changed

4 files changed

+54
-56
lines changed

lib/graphql/lang/ast/type_info_visitor.ex

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defmodule GraphQL.Lang.AST.TypeInfoVisitor do
2424
old_type_info = var!(accumulator)[:type_info]
2525
new_type_info = %TypeInfo{old_type_info |
2626
unquote(stack_name) => Stack.push(old_type_info.unquote(stack_name), unquote(value))}
27-
var!(accumulator) = put_in(var!(accumulator)[:type_info], new_type_info)
27+
put_in(var!(accumulator)[:type_info], new_type_info)
2828
end
2929
end
3030

@@ -33,30 +33,26 @@ defmodule GraphQL.Lang.AST.TypeInfoVisitor do
3333
old_type_info = var!(accumulator)[:type_info]
3434
new_type_info = %TypeInfo{old_type_info |
3535
unquote(stack_name) => Stack.pop(old_type_info.unquote(stack_name))}
36-
var!(accumulator) = put_in(var!(accumulator)[:type_info], new_type_info)
36+
put_in(var!(accumulator)[:type_info], new_type_info)
3737
end
3838
end
3939

40-
defmacrop set_directive(directive) do
41-
quote do
42-
var!(accumulator) = put_in(
43-
var!(accumulator)[:type_info],
44-
%TypeInfo{ var!(accumulator)[:type_info] | directive: unquote(directive)}
45-
)
46-
end
40+
def set_directive(accumulator, directive) do
41+
put_in(
42+
accumulator[:type_info],
43+
%TypeInfo{accumulator[:type_info] | directive: directive}
44+
)
4745
end
4846

49-
defmacrop set_argument(argument) do
50-
quote do
51-
var!(accumulator) = put_in(
52-
var!(accumulator)[:type_info],
53-
%TypeInfo{var!(accumulator)[:type_info] | argument: unquote(argument)}
54-
)
55-
end
47+
def set_argument(accumulator, argument) do
48+
put_in(
49+
accumulator[:type_info],
50+
%TypeInfo{accumulator[:type_info] | argument: argument}
51+
)
5652
end
5753

5854
def enter(_visitor, node, accumulator) do
59-
case node.kind do
55+
accumulator = case node.kind do
6056
:SelectionSet ->
6157
type = TypeInfo.type(accumulator[:type_info])
6258
named_type = TypeInfo.named_type(type)
@@ -74,10 +70,10 @@ defmodule GraphQL.Lang.AST.TypeInfoVisitor do
7470
node
7571
)
7672
field_def_type = if field_def, do: field_def.type, else: nil
77-
stack_push(:field_def_stack, field_def)
73+
accumulator = stack_push(:field_def_stack, field_def)
7874
stack_push(:type_stack, field_def_type)
7975
else
80-
stack_push(:field_def_stack, nil)
76+
accumulator = stack_push(:field_def_stack, nil)
8177
stack_push(:type_stack, nil)
8278
end
8379
:Directive ->
@@ -89,7 +85,7 @@ defmodule GraphQL.Lang.AST.TypeInfoVisitor do
8985
#this._directive = schema.getDirective(node.name.value); // JS example
9086
# and set it like this
9187
#set_directive(directive_def)
92-
set_directive(nil)
88+
set_directive(accumulator, nil)
9389
:OperationDefinition ->
9490
type = case node.operation do
9591
:query -> accumulator[:type_info].schema.query
@@ -115,15 +111,15 @@ defmodule GraphQL.Lang.AST.TypeInfoVisitor do
115111
Map.get(field_or_directive, :arguments, %{}),
116112
fn(arg) -> arg == node.name.value end
117113
)
118-
set_argument(arg_def)
114+
accumulator = set_argument(accumulator, arg_def)
119115
stack_push(:input_type_stack, (if arg_def && Map.has_key?(arg_def, :type), do: arg_def.type, else: nil))
120116
else
121-
set_argument(nil)
117+
accumulator = set_argument(accumulator, nil)
122118
stack_push(:input_type_stack, nil)
123119
end
124120
:List ->
125121
input_type = TypeInfo.input_type(accumulator[:type_info])
126-
list_type = TypeInfo.nullable_type(accumulator[:type_info], input_type)
122+
list_type = TypeInfo.named_type(input_type)
127123
if %Type.List{} === list_type do
128124
stack_push(:input_type_stack, list_type.ofType)
129125
else
@@ -144,7 +140,7 @@ defmodule GraphQL.Lang.AST.TypeInfoVisitor do
144140
stack_push(:input_type_stack, nil)
145141
end
146142
_ ->
147-
:ignore
143+
accumulator
148144
end
149145
{:continue, accumulator}
150146
end
@@ -154,20 +150,19 @@ defmodule GraphQL.Lang.AST.TypeInfoVisitor do
154150
:SelectionSet ->
155151
stack_pop(:parent_type_stack)
156152
:Field ->
157-
stack_pop(:field_def_stack)
153+
accumulator = stack_pop(:field_def_stack)
158154
stack_pop(:type_stack)
159155
:Directive ->
160-
set_directive(nil)
156+
set_directive(accumulator, nil)
161157
kind when kind in [:OperationDefinition, :InlineFragment, :FragmentDefinition] ->
162158
stack_pop(:type_stack)
163159
:Argument ->
164-
set_argument(nil)
160+
set_argument(accumulator, nil)
165161
kind when kind in [:List, :ObjectField, :VariableDefinition] ->
166162
stack_pop(:input_type_stack)
167163
_ ->
168-
:ignore
164+
accumulator
169165
end
170-
accumulator
171166
end
172167
end
173168
end

lib/graphql/validation/rules/fields_on_correct_type.ex

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ defmodule GraphQL.Validation.Rules.FieldsOnCorrectType do
1616
schema = accumulator[:type_info].schema
1717
parent_type = TypeInfo.parent_type(accumulator[:type_info])
1818
field_def = TypeInfo.find_field_def(schema, parent_type, node)
19-
if parent_type do
20-
if !field_def do
21-
accumulator = report_error(
22-
accumulator,
23-
undefined_field_message(schema, node.name.value, parent_type)
24-
)
25-
end
19+
if parent_type && !field_def do
20+
{:continue, report_error(
21+
accumulator,
22+
undefined_field_message(schema, node.name.value, parent_type)
23+
)}
24+
else
25+
{:continue, accumulator}
2626
end
27-
{:continue, accumulator}
2827
end
2928

3029
def enter(_visitor, _node, accumulator), do: {:continue, accumulator}
@@ -44,6 +43,7 @@ defmodule GraphQL.Validation.Rules.FieldsOnCorrectType do
4443

4544
defp field_usage_count({_, count}), do: count
4645

46+
# TODO is this meant to be a ==?
4747
defp is_a_graphql_object_type(type), do: %ObjectType{} = type
4848

4949
defp to_self_and_interfaces(type), do: [type] ++ type.interfaces
@@ -85,10 +85,11 @@ defmodule GraphQL.Validation.Rules.FieldsOnCorrectType do
8585
|> Enum.slice(0, @max_type_suggestions)
8686
|> Enum.map(&"\"#{&1}\"")
8787
|> Enum.join(", ")
88-
message = "#{message} However, this field exists on #{suggestions}. "
89-
<> "Perhaps you meant to use an inline fragment?"
88+
"#{message} However, this field exists on #{suggestions}. " <>
89+
"Perhaps you meant to use an inline fragment?"
90+
else
91+
message
9092
end
91-
message
9293
end
9394
end
9495
end

lib/graphql/validation/rules/no_fragment_cycles.ex

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ defmodule GraphQL.Validation.Rules.NoFragmentCycles do
3131

3232
def leave(_visitor, _node, acc), do: acc
3333

34+
defp detect_cycles(acc, nil), do: acc
3435
defp detect_cycles(acc, fragment_def) do
3536
acc
3637
|> mark_visited(fragment_def)
@@ -40,18 +41,18 @@ defmodule GraphQL.Validation.Rules.NoFragmentCycles do
4041
defp detect_cycles_via_spread_nodes(acc, _, []), do: acc
4142
defp detect_cycles_via_spread_nodes(acc, fragment_def, spread_nodes) do
4243
frag_name = fragment_def.name.value
43-
acc = %{ acc | spread_path_indices:
44+
acc = %{acc | spread_path_indices:
4445
Map.merge(acc[:spread_path_indices], %{frag_name => Stack.length(acc[:spread_path])})}
4546

4647
acc = process_spread_nodes(acc, spread_nodes)
4748

48-
%{ acc | spread_path_indices: Map.delete(acc[:spread_path_indices], frag_name)}
49+
%{acc | spread_path_indices: Map.delete(acc[:spread_path_indices], frag_name)}
4950
end
5051

5152
defp process_spread_nodes(acc, []), do: acc
5253
defp process_spread_nodes(acc, [spread_node|rest]) do
5354
spread_name = spread_node.name.value
54-
cycle_index = Map.get(acc[:spread_path_indices], spread_name, nil)
55+
cycle_index = Map.get(acc[:spread_path_indices], spread_name)
5556
process_spread_nodes(process_one_node(acc, spread_node, cycle_index), rest)
5657
end
5758

@@ -65,14 +66,15 @@ defmodule GraphQL.Validation.Rules.NoFragmentCycles do
6566
end
6667

6768
defp process_one_node(acc, spread_node, _) do
68-
acc = %{ acc | spread_path: Stack.push(acc[:spread_path], spread_node)}
69-
if !visited?(acc, spread_node) do
70-
spread_fragment = DocumentInfo.get_fragment_definition(acc[:document_info], spread_node.name.value)
71-
if spread_fragment do
72-
acc = detect_cycles(acc, spread_fragment)
69+
acc = %{acc | spread_path: Stack.push(acc[:spread_path], spread_node)}
70+
acc =
71+
if !visited?(acc, spread_node) do
72+
spread_fragment = DocumentInfo.get_fragment_definition(acc[:document_info], spread_node.name.value)
73+
detect_cycles(acc, spread_fragment)
74+
else
75+
acc
7376
end
74-
end
75-
%{ acc | spread_path: Stack.pop(acc[:spread_path])}
77+
%{acc | spread_path: Stack.pop(acc[:spread_path])}
7678
end
7779

7880
defp visited?(acc, node) do

mix.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
%{"bunt": {:hex, :bunt, "0.1.6", "5d95a6882f73f3b9969fdfd1953798046664e6f77ec4e486e6fafc7caad97c6f", [:mix], []},
2-
"credo": {:hex, :credo, "0.3.13", "90d2d2deb9d376bb2a63f81126a320c3920ce65acb1294982ab49a8aacc7d89f", [:mix], [{:bunt, "~> 0.1.4", [hex: :bunt, optional: false]}]},
3-
"dialyxir": {:hex, :dialyxir, "0.3.3", "2f8bb8ab4e17acf4086cae847bd385c0f89296d3e3448dc304c26bfbe4b46cb4", [:mix], []},
4-
"dogma": {:hex, :dogma, "0.1.5", "d8d9c9d50f099c5bde47334da077b555b2027147d16906ea7bb4e7cdaedb2d8b", [:mix], [{:poison, ">= 1.0.0", [hex: :poison, optional: false]}]},
2+
"credo": {:hex, :credo, "0.4.11", "03a64e9d53309b7132556284dda0be57ba1013885725124cfea7748d740c6170", [:mix], [{:bunt, "~> 0.1.6", [hex: :bunt, optional: false]}]},
3+
"dialyxir": {:hex, :dialyxir, "0.3.5", "eaba092549e044c76f83165978979f60110dc58dd5b92fd952bf2312f64e9b14", [:mix], []},
4+
"dogma": {:hex, :dogma, "0.1.7", "927f76a89a809db96e0983b922fc899f601352690aefa123529b8aa0c45123b2", [:mix], [{:poison, ">= 1.0.0", [hex: :poison, optional: false]}]},
55
"earmark": {:hex, :earmark, "0.2.1", "ba6d26ceb16106d069b289df66751734802777a3cbb6787026dd800ffeb850f3", [:mix], []},
6-
"ex_doc": {:hex, :ex_doc, "0.11.5", "0dc51cb84f8312162a2313d6c71573a9afa332333d8a332bb12540861b9834db", [:mix], [{:earmark, "~> 0.1.17 or ~> 0.2", [hex: :earmark, optional: true]}]},
6+
"ex_doc": {:hex, :ex_doc, "0.12.0", "b774aabfede4af31c0301aece12371cbd25995a21bb3d71d66f5c2fe074c603f", [:mix], [{:earmark, "~> 0.2", [hex: :earmark, optional: false]}]},
77
"fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], []},
8-
"inch_ex": {:hex, :inch_ex, "0.5.1", "c1c18966c935944cbb2d273796b36e44fab3c54fd59f906ff026a686205b4e14", [:mix], [{:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: false]}]},
8+
"inch_ex": {:hex, :inch_ex, "0.5.3", "39f11e96181ab7edc9c508a836b33b5d9a8ec0859f56886852db3d5708889ae7", [:mix], [{:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: false]}]},
99
"mix_test_watch": {:hex, :mix_test_watch, "0.2.6", "9fcc2b1b89d1594c4a8300959c19d50da2f0ff13642c8f681692a6e507f92cab", [:mix], [{:fs, "~> 0.9.1", [hex: :fs, optional: false]}]},
10-
"poison": {:hex, :poison, "2.1.0", "f583218ced822675e484648fa26c933d621373f01c6c76bd00005d7bd4b82e27", [:mix], []}}
10+
"poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [:mix], []}}

0 commit comments

Comments
 (0)