Skip to content

Commit 397e804

Browse files
committed
Use DirectiveChecks in SerialExecution
1 parent d883d55 commit 397e804

File tree

4 files changed

+30
-36
lines changed

4 files changed

+30
-36
lines changed

lib/graphql/execution/deferred_execution.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,14 @@ def resolve_value(scope, thread, frame, value, type_defn)
361361
case type_defn.kind
362362
when GraphQL::TypeKinds::SCALAR, GraphQL::TypeKinds::ENUM
363363
type_defn.coerce_result(value)
364+
when GraphQL::TypeKinds::INTERFACE, GraphQL::TypeKinds::UNION
365+
resolved_type = type_defn.resolve_type(value, scope)
366+
367+
if !resolved_type.is_a?(GraphQL::ObjectType)
368+
raise GraphQL::ObjectType::UnresolvedTypeError.new(type_defn, value)
369+
else
370+
resolve_value(scope, thread, frame, value, resolved_type)
371+
end
364372
when GraphQL::TypeKinds::NON_NULL
365373
wrapped_type = type_defn.of_type
366374
resolve_value(scope, thread, frame, value, wrapped_type)
@@ -387,14 +395,6 @@ def resolve_value(scope, thread, frame, value, type_defn)
387395
end
388396
resolved_values
389397
end
390-
when GraphQL::TypeKinds::INTERFACE, GraphQL::TypeKinds::UNION
391-
resolved_type = type_defn.resolve_type(value, scope)
392-
393-
if !resolved_type.is_a?(GraphQL::ObjectType)
394-
raise GraphQL::ObjectType::UnresolvedTypeError.new(type_defn, value)
395-
else
396-
resolve_value(scope, thread, frame, value, resolved_type)
397-
end
398398
when GraphQL::TypeKinds::OBJECT
399399
inner_frame = ExecFrame.new(
400400
node: frame.node,

lib/graphql/execution/directive_checks.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def stream?(ast_node)
2020
ast_node.directives.any? { |dir| dir.name == STREAM }
2121
end
2222

23+
# This covers `@include(if:)` & `@skip(if:)`
2324
# @return [Boolean] Should this AST node be skipped altogether?
2425
def skip?(ast_node, query)
2526
ast_node.directives.each do |ast_directive|

lib/graphql/query/directive_resolution.rb

Lines changed: 0 additions & 16 deletions
This file was deleted.

lib/graphql/query/serial_execution/selection_resolution.rb

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,20 @@ def flatten_field(ast_node)
4141
end
4242

4343
def flatten_inline_fragment(ast_node)
44-
return {} unless GraphQL::Query::DirectiveResolution.include_node?(ast_node, execution_context.query)
45-
flatten_fragment(ast_node)
44+
if GraphQL::Execution::DirectiveChecks.skip?(ast_node, execution_context.query)
45+
{}
46+
else
47+
flatten_fragment(ast_node)
48+
end
4649
end
4750

4851
def flatten_fragment_spread(ast_node)
49-
return {} unless GraphQL::Query::DirectiveResolution.include_node?(ast_node, execution_context.query)
50-
ast_fragment_defn = execution_context.get_fragment(ast_node.name)
51-
flatten_fragment(ast_fragment_defn)
52+
if GraphQL::Execution::DirectiveChecks.skip?(ast_node, execution_context.query)
53+
{}
54+
else
55+
ast_fragment_defn = execution_context.get_fragment(ast_node.name)
56+
flatten_fragment(ast_fragment_defn)
57+
end
5258
end
5359

5460
def flatten_fragment(ast_fragment)
@@ -89,13 +95,16 @@ def merge_fields(field1, field2)
8995
end
9096

9197
def resolve_field(ast_node)
92-
return {} unless GraphQL::Query::DirectiveResolution.include_node?(ast_node, execution_context.query)
93-
execution_context.strategy.field_resolution.new(
94-
ast_node,
95-
type,
96-
target,
97-
execution_context
98-
).result
98+
if GraphQL::Execution::DirectiveChecks.skip?(ast_node, execution_context.query)
99+
{}
100+
else
101+
execution_context.strategy.field_resolution.new(
102+
ast_node,
103+
type,
104+
target,
105+
execution_context
106+
).result
107+
end
99108
end
100109

101110
def merge_into_result(memo, selection)

0 commit comments

Comments
 (0)