Skip to content

Commit

Permalink
Merge pull request #1934 from rmosolgo/fix-lookahead-invalid
Browse files Browse the repository at this point in the history
Support lookahead on invalid queries
  • Loading branch information
Robert Mosolgo authored Oct 30, 2018
2 parents de70c58 + 6bb3a6e commit 4fa45fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/graphql/execution/lookahead.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,14 @@ def flatten_ast_value(query, v)
module FieldHelpers
module_function

def get_field(schema, owner_type, field_name )
def get_field(schema, owner_type, field_name)
field_defn = owner_type.get_field(field_name)
field_defn ||= if owner_type == schema.query.metadata[:type_class] && (entry_point_field = schema.introspection_system.entry_point(name: field_name))
entry_point_field.metadata[:type_class]
elsif (dynamic_field = schema.introspection_system.dynamic_field(name: field_name))
dynamic_field.metadata[:type_class]
else
raise "Invariant: no field for #{owner_type}.#{field_name}"
nil
end

field_defn
Expand Down
7 changes: 7 additions & 0 deletions spec/graphql/execution/lookahead_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ class Schema < GraphQL::Schema
assert_equal 2, context[:lookahead_latin_name]
assert_equal [:find_bird_species], context[:root_lookahead_names]
end

it "works for invalid queries" do
context = {lookahead_latin_name: 0}
res = LookaheadTest::Schema.execute("{ doesNotExist }", context: context)
assert res.key?("errors")
assert_equal 0, context[:lookahead_latin_name]
end
end

describe '#selections' do
Expand Down

0 comments on commit 4fa45fe

Please sign in to comment.