Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put 1.9-dev on master #2038

Merged
merged 300 commits into from
Jan 10, 2019
Merged
Changes from 1 commit
Commits
Show all changes
300 commits
Select commit Hold shift + click to select a range
fd62944
Split out interpreter files; better authorization support
rmosolgo Aug 28, 2018
552d48b
Fix some stuff after merging
rmosolgo Aug 29, 2018
7e36ac5
Use a hacky flag to support both interpreter and non-interpreter
rmosolgo Sep 5, 2018
8ab3f6a
Support mutations the old way
rmosolgo Sep 5, 2018
e81c28a
Implement null propagation
rmosolgo Sep 6, 2018
001d413
Merge branch '1.9-dev' into urlsafe_base64
rmosolgo Sep 10, 2018
18d5461
Merge pull request #1698 from gfx/urlsafe_base64
Sep 10, 2018
dd52ddc
Merge pull request #1338 from tenderlove/immutable-nodes
Jul 9, 2018
82da9c9
Merge pull request #1290 from rmosolgo/class-based-visitor
Jul 10, 2018
b459bf4
Merge pull request #1740 from rmosolgo/ast-maniputation
Aug 14, 2018
09c0ec7
Merge pull request #1758 from rmosolgo/field-filter-instances
Aug 14, 2018
8a03c24
Merge pull request #1774 from rmosolgo/fix-connections
Aug 14, 2018
9a5b2cb
Merge pull request #1698 from gfx/urlsafe_base64
Sep 10, 2018
52ddbbf
Merge pull request #1849 from rmosolgo/1.9-dev-2
Sep 13, 2018
891bc6a
get the simple case working
Aug 30, 2018
c291057
make subselections work
Aug 30, 2018
f563502
one test to fix
Aug 30, 2018
13ba137
all green
Aug 30, 2018
6238d03
linter
Aug 30, 2018
8c12dcf
run rufo
Aug 30, 2018
3060ced
align things
Aug 30, 2018
851ec2f
fix loop problem
Aug 30, 2018
bef746b
Use struct to carry field info
Aug 31, 2018
a0587bb
add comment
Aug 31, 2018
d56d134
compared fragment cache
Aug 31, 2018
af57fb8
add fragment name and selection cache
Aug 31, 2018
95b945c
more optimizations, fix fragment name issue
Aug 31, 2018
00792cd
fix test
Aug 31, 2018
48922ba
more edge cases
Aug 31, 2018
980f90e
failing test for yet another case
Sep 5, 2018
1cdd8d1
track all parents
Sep 5, 2018
94b621e
exclusivity logic, removed caching for now
Sep 5, 2018
81a9de2
lets not have infinite loops
Sep 5, 2018
48bb6ba
unused vars
Sep 5, 2018
dc1e315
add some tests
Sep 11, 2018
190637a
well this kinda works
Sep 13, 2018
d2b0a04
clean up a bit
Sep 13, 2018
a28ec6c
Remove Untitled
rmosolgo Sep 13, 2018
345ecd4
Remove unused ivar; remove focus
rmosolgo Sep 13, 2018
cbcac61
Merge pull request #1824 from xuorig/fields-will-merge-ast
Sep 13, 2018
25103fb
Merge branch '1.9-dev' into interpreter
rmosolgo Sep 14, 2018
f30b34d
Support skip & include
rmosolgo Sep 14, 2018
d73a4ba
making existing stuff work
Sep 14, 2018
b383774
Fix some stuff for dairy schema with interpreter
rmosolgo Sep 17, 2018
8e78480
query complexity works :tada:
Sep 19, 2018
2844c72
Try avoiding double-resolution
rmosolgo Sep 20, 2018
33ae307
Intepret with a custom AST routine
rmosolgo Sep 20, 2018
fc549e3
Fix null propagation with later writes
rmosolgo Sep 21, 2018
827608a
Improve support for nil propagation and errors
rmosolgo Sep 21, 2018
1ea1f8c
resolve late-bound types
rmosolgo Sep 21, 2018
96fb4b8
Support Tracing
rmosolgo Sep 21, 2018
8b86f53
Start multiplexing support
rmosolgo Sep 21, 2018
358388b
Skip some rescue from tests
rmosolgo Sep 21, 2018
cd2e78c
Extract Interpreter installation into a plugin
rmosolgo Sep 21, 2018
c1ef9d2
Add a guide
rmosolgo Sep 21, 2018
f66654c
more doc
rmosolgo Sep 21, 2018
c8479d3
Move context flag out of user hash
rmosolgo Sep 21, 2018
c5414aa
Remove some needless changes
rmosolgo Sep 21, 2018
9152913
remove more needless changes
rmosolgo Sep 21, 2018
eeaff01
Less nesting in interpreter
rmosolgo Sep 21, 2018
1b306fa
Update-bench
rmosolgo Sep 21, 2018
128027d
Update a few tests
rmosolgo Sep 25, 2018
55a35d6
Fix typestack spec
rmosolgo Sep 25, 2018
f36e75b
Make the tests pass without the interpreter; add a single build with …
rmosolgo Sep 25, 2018
06cce11
Fix rubocop, fix for old rubies
rmosolgo Sep 25, 2018
04de1fc
Fix travis config; fix for old rubies
rmosolgo Sep 25, 2018
4134ea8
Add interpreter to more test schemas
rmosolgo Sep 25, 2018
fc799d8
update warden_spec for interpreter'
rmosolgo Sep 25, 2018
f511ebe
Migrate system test to class-based, add interpreter run on CI
rmosolgo Sep 25, 2018
cb3fc0c
Remove needless fields stack
rmosolgo Sep 28, 2018
aa5c5c0
Remove objects stack
rmosolgo Sep 28, 2018
f21e29d
Remove path stack
rmosolgo Sep 28, 2018
c466d02
remove types stack
rmosolgo Sep 28, 2018
4340573
update tracing
rmosolgo Sep 28, 2018
3286c91
Keep a reference to trace instead of passing it everywhere
rmosolgo Sep 28, 2018
79e49d7
Trace cleanup
rmosolgo Sep 28, 2018
1f6050b
Update some test schemas to class-based
rmosolgo Sep 28, 2018
51a0b95
Start on subscriptions implementation
rmosolgo Sep 28, 2018
b020e6f
Support subscription & mutation root fields; improve support for unau…
rmosolgo Sep 29, 2018
c5127ca
Make sure interpreter-introspected types have class definitions
rmosolgo Sep 29, 2018
232b7c8
Implement batching across multiplexes
rmosolgo Sep 29, 2018
09d4a56
Fix execute_query_lazy and running one query
rmosolgo Sep 29, 2018
3fcf1c9
implement prepare for arguments
rmosolgo Sep 29, 2018
ddb9baf
Fix system tests
rmosolgo Sep 29, 2018
53a38d4
Fix rails/relay tests
rmosolgo Sep 29, 2018
1401f05
Update .node and .nodes fields
rmosolgo Oct 1, 2018
af2167e
Ignore tests that don't apply to interpreter
rmosolgo Oct 1, 2018
4f13db8
Fix client_mutation_id for interpreter
rmosolgo Oct 1, 2018
e972235
Get tracing parity
rmosolgo Oct 1, 2018
31d494d
add tests for max query complexity and multiplex
Oct 1, 2018
c65c3ec
convert query depth
Oct 2, 2018
608e369
Add workaroudn for list auth test
rmosolgo Oct 2, 2018
c0031f4
use schema graphql definition in test
Oct 3, 2018
a29fc31
convert field usage analyzer
Oct 3, 2018
de12c78
Oct 3, 2018
ec3bedd
rubocop
Oct 3, 2018
85d6b79
Make #write_into_result private; refactor @completely_nulled
rmosolgo Oct 5, 2018
8739e56
Fix lint error
rmosolgo Oct 5, 2018
8e623f0
Remove needless late-bound type check
rmosolgo Oct 5, 2018
74295cc
Refactor to not use throw/catch
rmosolgo Oct 5, 2018
233c77b
Document a method
rmosolgo Oct 5, 2018
cf2db9a
Clean up next_selections prep
rmosolgo Oct 5, 2018
4e33f2b
Extract subscription root field logic into a module
rmosolgo Oct 5, 2018
30b3e60
Reduce usage of trace in visitor
rmosolgo Oct 5, 2018
c3481bf
fix-lint-error
rmosolgo Oct 5, 2018
505bdcc
Extract response collection from runtime
rmosolgo Oct 5, 2018
47c3c6d
Improve dead path handling
rmosolgo Oct 5, 2018
3e52d58
Remove needless legacy adapter
rmosolgo Oct 5, 2018
26b10bc
Document the multiplex interactions a little bit
rmosolgo Oct 5, 2018
f2d8f6b
merge trace and visitor into runtime, since they have the same lifecy…
rmosolgo Oct 5, 2018
8b31eed
Clarify behavior differences
rmosolgo Oct 5, 2018
057fd4a
Update some done todos
rmosolgo Oct 5, 2018
eac1add
Explain difference in tracing spec
rmosolgo Oct 5, 2018
89b8d9f
Uncomment non-broken thing
rmosolgo Oct 5, 2018
224c4a9
Rename resolve_field_2 -> resolve
rmosolgo Oct 5, 2018
b6767d6
fix lint error
rmosolgo Oct 5, 2018
edf4946
Merge pull request #1394 from rmosolgo/interpreter
Oct 5, 2018
dcd0a97
Merge branch 'master' into 1.9-dev
rmosolgo Oct 5, 2018
4768e2d
Update for changes on master
rmosolgo Oct 5, 2018
5aca4cc
Add a large result benchmark
rmosolgo Oct 5, 2018
7c79479
Remove needless late-bound type check
rmosolgo Oct 5, 2018
5170bd3
Compare with strings to avoid slow #=== check
rmosolgo Oct 5, 2018
c5476b0
Implement #get_field to avoid hash merging
rmosolgo Oct 5, 2018
81fd4e7
Tighten up writing logic
rmosolgo Oct 5, 2018
c384aaa
Add memory benchmark
rmosolgo Oct 5, 2018
f062469
Simplify creation of next_path
rmosolgo Oct 5, 2018
41aac40
Don't use multiple return, since it allocates an Array
rmosolgo Oct 5, 2018
a7553e0
make fewer arguments hashes
rmosolgo Oct 5, 2018
eb4d17b
fix spec for old analysis
Oct 5, 2018
a175e39
ivars moved to visitor class
Oct 5, 2018
3f34bd7
analyze selected operation only
Oct 5, 2018
3089d17
Merge branch '1.9-dev' into ast-analyzers
Oct 5, 2018
22b2471
fix multiplex analyze method signature
Oct 6, 2018
b285f37
a bit of documentation
Oct 6, 2018
8fbee06
fix spec
Oct 6, 2018
8fa7e33
preliminary guide
Oct 6, 2018
d551ec7
add a per schema analysis engine
Oct 6, 2018
2e1759f
detect analysis engine in validation pipeline
Oct 6, 2018
ed2d1c3
authorization analyzer in validation pipeline
Oct 6, 2018
3c6222c
document new way to use ast analyzers
Oct 6, 2018
24e998b
typo
Oct 6, 2018
2831983
test authorization with both ast and not using constant
Oct 6, 2018
c592354
remove focus
Oct 6, 2018
b3dcc3f
fix schema api
Oct 6, 2018
0c835bb
Merge pull request #1886 from rmosolgo/interpreter-profile
Oct 8, 2018
824affe
deprecate authorization analyzer, filter it out when using analysis e…
Oct 9, 2018
40e1711
rm focus
Oct 9, 2018
8002816
remove the testing constant, and fix comment
Oct 9, 2018
446ab42
Merge branch '1.9-dev' of github.com:rmosolgo/graphql-ruby into ast-a…
Oct 10, 2018
4ca8545
Merge pull request #1841 from xuorig/ast-analyzers
Oct 10, 2018
670d092
Fix cache busting when duping nodes
rmosolgo Oct 15, 2018
c00d355
Merge pull request #1901 from rmosolgo/language-duping-fix
Oct 15, 2018
c38545c
Add a failing test
rmosolgo Oct 16, 2018
f174e92
Support unbalanced scoping between to maybe-conflicting fields
rmosolgo Oct 16, 2018
52159ce
Merge pull request #1905 from rmosolgo/fields-will-merge-bug
Oct 16, 2018
a7ec916
Fix missing super
rmosolgo Oct 19, 2018
32497dd
Fix replacing nodes in the SDL
rmosolgo Oct 23, 2018
8fe3b53
Fix fields and args in SDL updates
rmosolgo Oct 23, 2018
4c9556d
Merge pull request #1920 from rmosolgo/fix-sdl-visit
Oct 23, 2018
8083833
Require opting in to Authorization::Analyzer
rmosolgo Oct 25, 2018
c0f5c7c
Merge pull request #1924 from rmosolgo/skip-auth-analyzer-when-no-auth
Oct 25, 2018
79770a3
Merge branch 'master' into 1.9-dev
rmosolgo Oct 25, 2018
7bbe4b0
1.9.0.pre1
rmosolgo Oct 25, 2018
c2d0b07
Update for changes to execution_strategy tracking
rmosolgo Oct 25, 2018
cd68de6
Add Query#lookahead
rmosolgo Oct 29, 2018
5f0baac
fix lint error
rmosolgo Oct 29, 2018
e9c2566
Merge pull request #1931 from rmosolgo/query-lookahead
Oct 29, 2018
46bec30
Merge branch 'master' into 1.9-dev
rmosolgo Oct 29, 2018
a6589b1
Merge branch '1.9-dev' of github.com:rmosolgo/graphql-ruby into 1.9-dev
rmosolgo Oct 29, 2018
16ec1f9
fix root types for lookahead
rmosolgo Oct 29, 2018
86a2a3d
Fix lookahead#selections with fragments
rmosolgo Oct 30, 2018
5478180
Fix lint error
rmosolgo Oct 30, 2018
de70c58
Merge pull request #1933 from rmosolgo/fix-fragment-lookahead-selections
Oct 30, 2018
6bb3a6e
Support lookahead on invalid queries
rmosolgo Oct 30, 2018
4fa45fe
Merge pull request #1934 from rmosolgo/fix-lookahead-invalid
Oct 30, 2018
9d3d71a
Fix RelayClassicMutation extras on interpreter
rmosolgo Nov 2, 2018
279f918
Merge pull request #1940 from rmosolgo/fix-mutation-extras
Nov 2, 2018
58b2d40
Fix default values for input objs
rmosolgo Nov 9, 2018
a341de2
Support directives too
rmosolgo Nov 9, 2018
c116c48
Merge pull request #1951 from rmosolgo/fix-default-value-objects
Nov 9, 2018
3e5dad2
Change fields to path in validation responses
krider2010 Nov 20, 2018
d43c956
Introduce Field#resolver_method
swalkinshaw Nov 19, 2018
c6413b7
Test updates
swalkinshaw Nov 19, 2018
0f11230
Docs updates
swalkinshaw Nov 19, 2018
f495e91
All the changes to populate and emit extensions details
krider2010 Nov 22, 2018
1be06f2
Update all the tests
krider2010 Nov 22, 2018
526f282
Failing test for invalid scenario
Nov 26, 2018
83ea356
handle invalid fragment types in fragments are used validator
Nov 26, 2018
21f6e67
rm focus
Nov 26, 2018
d75aef4
Merge pull request #1973 from xuorig/fix-fragment-are-used-with-inval…
Nov 26, 2018
3134852
Merge branch 'master' into 1.9-dev
rmosolgo Nov 29, 2018
3b60efc
Support lookahead in interpreter
rmosolgo Nov 29, 2018
6fc7ec4
Merge pull request #1976 from rmosolgo/interpreter-lookahead
Nov 29, 2018
6464cb1
Fix root-level lazy auth hooks
rmosolgo Nov 30, 2018
38148d1
Fix direct call to .sync_lazy
rmosolgo Nov 30, 2018
ff59465
Rework errors to be ruby classes.
krider2010 Dec 3, 2018
790fb95
Merge branch '1.9-dev' into validation-more-data-in-errors
krider2010 Dec 3, 2018
9836b5f
Fix up test from branch to new style with extensions/path
krider2010 Dec 3, 2018
169f684
Wip hunting
rmosolgo Dec 3, 2018
3999a11
Resolve lazies level-by-level
rmosolgo Dec 3, 2018
9eb3e8b
Clean up the diff, add some docs
rmosolgo Dec 3, 2018
cbcabdf
Remove unused code
rmosolgo Dec 3, 2018
2b16b52
isolate fix
rmosolgo Dec 3, 2018
b6cc43d
Oops, handle nil values properly
rmosolgo Dec 3, 2018
9b39bff
Merge pull request #1984 from rmosolgo/hunt-batching-issue
Dec 4, 2018
a83d41a
Fix non-null abstract fields that return nil
rmosolgo Dec 4, 2018
daf0ad9
Fix for non-null lists with nullable items
rmosolgo Dec 4, 2018
b32573f
Fix lazy list members returning nil
rmosolgo Dec 4, 2018
2f28769
Merge pull request #1986 from rmosolgo/fix-non-null-unions
Dec 4, 2018
eb83c01
Rename declared to defined from nit
krider2010 Dec 4, 2018
9a04fd8
Rename `Message` to `Error`
krider2010 Dec 4, 2018
8ce8bec
Merge pull request #1970 from krider2010/validation-more-data-in-errors
Dec 4, 2018
fdd54f9
Put runtime info in mutable context, too
rmosolgo Dec 5, 2018
3bd64ac
Merge pull request #1989 from rmosolgo/runtime-info
Dec 5, 2018
0dbce0f
Update some random hotspots
rmosolgo Dec 7, 2018
e70ce3e
Tighten up some more
rmosolgo Dec 7, 2018
252a946
Merge pull request #1996 from rmosolgo/interpreter-hotspots
Dec 7, 2018
3f138b0
Use the actual list index for type-at-path, to handle lists of abstra…
rmosolgo Dec 12, 2018
8c9f2ab
Add tests for lists of union type with differing field nullability
rmosolgo Dec 12, 2018
afe9ffb
Merge pull request #2004 from rmosolgo/interpreter-type-at-path-fix
Dec 12, 2018
b05c081
Skip rewrite when interpreter is enabled
rmosolgo Dec 12, 2018
04e168c
Merge pull request #2005 from rmosolgo/skip-rewrite-when-possible
Dec 13, 2018
3ef4490
Fix introspection
rmosolgo Dec 13, 2018
5cab5ca
Fix when type doesn't exist
rmosolgo Dec 13, 2018
06144cb
Merge pull request #2006 from rmosolgo/fix-input-fields
Dec 13, 2018
4654c13
Add AST::Visitor#previous_field_definition
rmosolgo Dec 14, 2018
e41bc1d
Merge pull request #2009 from rmosolgo/ast-previous-field
Dec 14, 2018
52b89c0
Skip rewrite more often
rmosolgo Dec 14, 2018
8d89dcd
Don't even visit if no visit is required
rmosolgo Dec 14, 2018
e41a963
Tighten up some array handling
rmosolgo Dec 14, 2018
dbfce25
Fix empty value
rmosolgo Dec 14, 2018
357cb1c
Fix return value
rmosolgo Dec 14, 2018
3c36ad4
Tighten up children arrays
rmosolgo Dec 14, 2018
7870b8a
Fix array depth
rmosolgo Dec 15, 2018
7d5fa1e
Merge pull request #2012 from rmosolgo/visitor-perf
Dec 17, 2018
91ac924
Merge branch '1.9-dev' into refactor-field-resolving-methods
rmosolgo Dec 17, 2018
740061d
Fix mongoid tests
rmosolgo Dec 17, 2018
62f62ed
Merge pull request #1961 from swalkinshaw/refactor-field-resolving-me…
Dec 17, 2018
4e6e0e7
Test hash_key with strange chars in schema/member/has_fields
dpkp Nov 29, 2018
7930ec5
Handle hash_key: values that are not valid ruby method_names in schem…
dpkp Nov 29, 2018
9d11f7a
Add end-to-end test for odd hash key
rmosolgo Dec 17, 2018
32cb740
Merge pull request #2016 from rmosolgo/1.9-hash_key_schema_fix
Dec 17, 2018
41c1eff
Add warning for proc-based visitors
rmosolgo Dec 17, 2018
ab936a3
Merge pull request #2017 from rmosolgo/deprecate-visitor-hooks
Dec 17, 2018
70cc52c
Allow code to be accessed outside of the errors
krider2010 Jan 10, 2019
211f23f
Merge pull request #2037 from krider2010/enhance-code
Jan 10, 2019
e22e165
Merge branch 'master' into 1.9-dev
rmosolgo Jan 10, 2019
89014bd
Fix merge
rmosolgo Jan 10, 2019
080cbf1
Update arg usage from merge
rmosolgo Jan 10, 2019
4d8ffc2
remove needless variable
rmosolgo Jan 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
get the simple case working
  • Loading branch information
Marc-Andre Giroux authored and rmosolgo committed Sep 13, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 891bc6a5b348b66b02be4c13b233acce18df1168
12 changes: 12 additions & 0 deletions Untitled
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Analyzer < Visitor
def initialize
end
end

class MyAnalyzer < Analyzer
def initial_state
end

def on_field(node, parent, defn)
end
def
117 changes: 86 additions & 31 deletions lib/graphql/static_validation/rules/fields_will_merge.rb
Original file line number Diff line number Diff line change
@@ -2,48 +2,103 @@
module GraphQL
module StaticValidation
module FieldsWillMerge
# Special handling for fields without arguments
NO_ARGS = {}.freeze

def initialize(*)
def on_operation_definition(node, _parent)
conflicts_within_selection_set(node, type_definition)
super
end

def on_field(node, _parent)
conflicts_within_selection_set(node, type_definition)
super
end

context.each_irep_node do |node|
if node.ast_nodes.size > 1
defn_names = Set.new(node.ast_nodes.map(&:name))
private

def conflicts_within_selection_set(node, type_definition)
fields = find_fields(node.selections, parent_type: type_definition)
fragment_names = find_fragment_names(node.selections)

# (A) Find find all conflicts "within" the fields of this selection set.
collect_conflicts_within(fields)
end

# Check for more than one GraphQL::Field backing this node:
if defn_names.size > 1
defn_names = defn_names.sort.join(" or ")
msg = "Field '#{node.name}' has a field conflict: #{defn_names}?"
context.errors << GraphQL::StaticValidation::Message.new(msg, nodes: node.ast_nodes.to_a)
def collect_conflicts_within(response_keys)
response_keys.each do |key, fields|
next if fields.size < 2
# find conflicts within nodes
for i in 0..fields.size-1
for j in i+1..fields.size-1
find_conflict(key, fields[i], fields[j])
end
end
end
end

def find_conflict(response_key, field1, field2, mutually_exclusive: false)
parent_type_1 = field1[:parent_type]
parent_type_2 = field2[:parent_type]

node1 = field1[:node]
node2 = field2[:node]

are_mutually_exclusive = mutually_exclusive ||
(parent_type_1 != parent_type_2 &&
parent_type_1.kind.object? &&
parent_type_2.kind.object?)

if !are_mutually_exclusive
if node1.name != node2.name
msg = "Field '#{response_key}' has a field conflict: #{node1.name} or #{node2.name}?"
context.errors << GraphQL::StaticValidation::Message.new(msg, nodes: [node1, node2])
end

args = possible_arguments(node1, node2)
if args.size > 1
msg = "Field '#{response_key}' has an argument conflict: #{args.map{ |arg| GraphQL::Language.serialize(arg) }.join(" or ")}?"
context.errors << GraphQL::StaticValidation::Message.new(msg, nodes: [node1, node2])
end
end
end

def find_fields(selections, parent_type:)
fields = selections.map do |node|
case node
when GraphQL::Language::Nodes::Field
{ node: node, parent_type: parent_type }
when GraphQL::Language::Nodes::InlineFragment
find_fields(node.selections, parent_type: node.type || parent_type)
end
end.flatten

# Check for incompatible / non-identical arguments on this node:
args = node.ast_nodes.map do |n|
if n.arguments.any?
n.arguments.reduce({}) do |memo, a|
arg_value = a.value
memo[a.name] = case arg_value
when GraphQL::Language::Nodes::AbstractNode
arg_value.to_query_string
else
GraphQL::Language.serialize(arg_value)
end
memo
end
fields.group_by { |f| f[:node].alias || f[:node].name }
end

def find_fragment_names(selections)
selections
.select { |s| s.is_a?(GraphQL::Language::Nodes::FragmentSpread) }
.map(&:name)
end

def possible_arguments(field1, field2)
# Check for incompatible / non-identical arguments on this node:
[field1, field2].map do |n|
if n.arguments.any?
n.arguments.reduce({}) do |memo, a|
arg_value = a.value
memo[a.name] = case arg_value
when GraphQL::Language::Nodes::AbstractNode
arg_value.to_query_string
else
NO_ARGS
GraphQL::Language.serialize(arg_value)
end
memo
end
args.uniq!

if args.length > 1
msg = "Field '#{node.name}' has an argument conflict: #{args.map{ |arg| GraphQL::Language.serialize(arg) }.join(" or ")}?"
context.errors << GraphQL::StaticValidation::Message.new(msg, nodes: node.ast_nodes.to_a)
end
else
NO_ARGS
end
end
end.uniq
end
end
end
10 changes: 1 addition & 9 deletions lib/graphql/static_validation/validation_context.rb
Original file line number Diff line number Diff line change
@@ -14,19 +14,15 @@ module StaticValidation
class ValidationContext
extend Forwardable


attr_reader :query, :errors, :visitor,
:on_dependency_resolve_handlers, :each_irep_node_handlers
:on_dependency_resolve_handlers

def_delegators :@query, :schema, :document, :fragments, :operations, :warden

def initialize(query, visitor_class)
@query = query
@literal_validator = LiteralValidator.new(context: query.context)
@errors = []
# TODO it will take some finegalling but I think all this state could
# be moved to `Visitor`
@each_irep_node_handlers = []
@on_dependency_resolve_handlers = []
@visitor = visitor_class.new(document, self)
end
@@ -39,10 +35,6 @@ def on_dependency_resolve(&handler)
@on_dependency_resolve_handlers << handler
end

def each_irep_node(&handler)
@each_irep_node_handlers << handler
end

def valid_literal?(ast_value, type)
@literal_validator.validate(ast_value, type)
end
1 change: 0 additions & 1 deletion lib/graphql/static_validation/validator.rb
Original file line number Diff line number Diff line change
@@ -39,7 +39,6 @@ def validate(query, validate: true)
context.visitor.visit
# Post-validation: allow validators to register handlers on rewritten query nodes
rewrite_result = context.visitor.rewrite_document
GraphQL::InternalRepresentation::Visit.visit_each_node(rewrite_result.operation_definitions, context.each_irep_node_handlers)

{
errors: context.errors,
Original file line number Diff line number Diff line change
@@ -246,6 +246,7 @@
}
|}

focus
it "fails rule" do
assert_equal ["Field 'fido' has a field conflict: name or nickname?"], error_messages
end
@@ -276,6 +277,7 @@
}
|}

focus
it "fails rule" do
assert_equal [%q(Field 'doesKnowCommand' has an argument conflict: {} or {dogCommand:"HEEL"}?)], error_messages
end
@@ -291,6 +293,7 @@
}
|}

focus
it "fails rule" do
assert_equal [%q(Field 'doesKnowCommand' has an argument conflict: {dogCommand:"SIT"} or {}?)], error_messages
end
@@ -306,6 +309,7 @@
}
|}

focus
it "fails rule" do
assert_equal [%q(Field 'doesKnowCommand' has an argument conflict: {dogCommand:"SIT"} or {dogCommand:"HEEL"}?)], error_messages
end
@@ -321,6 +325,7 @@
}
|}

focus
it "fails rule" do
assert_equal [%q(Field 'image' has an argument conflict: {maxWidth:"10"} or {maxWidth:"20"}?)], error_messages
end
@@ -354,6 +359,7 @@
end
end


describe "deep conflict" do
let(:query_string) {%|
{
@@ -429,6 +435,7 @@
end
end


describe "same aliases allowed on non-overlapping fields" do
let(:query_string) {%|
{