Skip to content

Commit

Permalink
Merge cbaa175 into fb31516
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi committed Jul 30, 2018
2 parents fb31516 + cbaa175 commit 26105f1
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 2 deletions.
Expand Up @@ -267,8 +267,10 @@ def _expose_only_preferred_locations(match_query, location_types, coerced_locati
# we ensure that we again infer the same type bound.
eligible_location_types[current_step_location] = current_type_bound

if current_step_location not in coerced_locations:
# The type bound here is already implied by the GraphQL query structure.
if (current_step_location not in coerced_locations or
previous_type_bound is not None):
# The type bound here is already implied by the GraphQL query structure,
# or has already been applied at a previous occurrence of this location.
# We can simply delete the QueryRoot / CoerceType blocks that impart it.
if isinstance(match_step.root_block, QueryRoot):
new_root_block = None
Expand Down
51 changes: 51 additions & 0 deletions graphql_compiler/tests/test_compiler.py
Expand Up @@ -1964,6 +1964,57 @@ def test_filter_then_apply_fragment(self):

check_test_data(self, test_data, expected_match, expected_gremlin)

def test_filter_then_apply_fragment_with_multiple_traverses(self):
test_data = test_input_data.filter_then_apply_fragment_with_multiple_traverses()

expected_match = '''
SELECT
Species__out_Species_Eats__out_Entity_Related___1.name AS `entity_related_to_food`,
Species__out_Species_Eats___1.name AS `food_name`,
Species__out_Species_Eats__in_Entity_Related___1.name AS `food_related_to_entity`,
Species___1.name AS `species_name`
FROM (
MATCH {{
class: Species,
where: (({species} CONTAINS name)),
as: Species___1
}}.out('Species_Eats') {{
where: ((@this INSTANCEOF 'Food')),
as: Species__out_Species_Eats___1
}}.out('Entity_Related') {{
as: Species__out_Species_Eats__out_Entity_Related___1
}}, {{
as: Species__out_Species_Eats___1
}}.in('Entity_Related') {{
as: Species__out_Species_Eats__in_Entity_Related___1
}}
RETURN $matches
)
'''
expected_gremlin = '''
g.V('@class', 'Species')
.filter{it, m -> $species.contains(it.name)}
.as('Species___1')
.out('Species_Eats')
.filter{it, m -> ['Food'].contains(it['@class'])}
.as('Species__out_Species_Eats___1')
.out('Entity_Related')
.as('Species__out_Species_Eats__out_Entity_Related___1')
.back('Species__out_Species_Eats___1')
.in('Entity_Related')
.as('Species__out_Species_Eats__in_Entity_Related___1')
.back('Species__out_Species_Eats___1')
.back('Species___1')
.transform{it, m -> new com.orientechnologies.orient.core.record.impl.ODocument([
entity_related_to_food: m.Species__out_Species_Eats__out_Entity_Related___1.name,
food_name: m.Species__out_Species_Eats___1.name,
food_related_to_entity: m.Species__out_Species_Eats__in_Entity_Related___1.name,
species_name: m.Species___1.name
])}
'''

check_test_data(self, test_data, expected_match, expected_gremlin)

def test_filter_on_fragment_in_union(self):
test_data = test_input_data.filter_on_fragment_in_union()

Expand Down
35 changes: 35 additions & 0 deletions graphql_compiler/tests/test_input_data.py
Expand Up @@ -567,6 +567,41 @@ def filter_then_apply_fragment():
type_equivalence_hints=None)


def filter_then_apply_fragment_with_multiple_traverses():
graphql_input = '''{
Species {
name @filter(op_name: "in_collection", value: ["$species"])
@output(out_name: "species_name")
out_Species_Eats {
... on Food {
name @output(out_name: "food_name")
out_Entity_Related {
name @output(out_name: "entity_related_to_food")
}
in_Entity_Related {
name @output(out_name: "food_related_to_entity")
}
}
}
}
}'''
expected_output_metadata = {
'species_name': OutputMetadata(type=GraphQLString, optional=False),
'food_name': OutputMetadata(type=GraphQLString, optional=False),
'entity_related_to_food': OutputMetadata(type=GraphQLString, optional=False),
'food_related_to_entity': OutputMetadata(type=GraphQLString, optional=False),
}
expected_input_metadata = {
'species': GraphQLList(GraphQLString),
}

return CommonTestData(
graphql_input=graphql_input,
expected_output_metadata=expected_output_metadata,
expected_input_metadata=expected_input_metadata,
type_equivalence_hints=None)


def filter_on_fragment_in_union():
graphql_input = '''{
Species {
Expand Down
48 changes: 48 additions & 0 deletions graphql_compiler/tests/test_ir_generation.py
Expand Up @@ -976,6 +976,54 @@ def test_filter_then_apply_fragment(self):

check_test_data(self, test_data, expected_blocks, expected_location_types)

def test_filter_then_apply_fragment_with_multiple_traverses(self):
test_data = test_input_data.filter_then_apply_fragment_with_multiple_traverses()

base_location = helpers.Location(('Species',))
food_location = base_location.navigate_to_subpath('out_Species_Eats')
entity_related_location = food_location.navigate_to_subpath('out_Entity_Related')
food_related_location = food_location.navigate_to_subpath('in_Entity_Related')

expected_blocks = [
blocks.QueryRoot({'Species'}),
blocks.Filter(
expressions.BinaryComposition(
u'contains',
expressions.Variable('$species', GraphQLList(GraphQLString)),
expressions.LocalField('name')
)
),
blocks.MarkLocation(base_location),
blocks.Traverse('out', 'Species_Eats'),
blocks.CoerceType({'Food'}),
blocks.MarkLocation(food_location),
blocks.Traverse('out', 'Entity_Related'),
blocks.MarkLocation(entity_related_location),
blocks.Backtrack(food_location),
blocks.Traverse('in', 'Entity_Related'),
blocks.MarkLocation(food_related_location),
blocks.Backtrack(food_location),
blocks.Backtrack(base_location),
blocks.ConstructResult({
'species_name': expressions.OutputContextField(
base_location.navigate_to_field('name'), GraphQLString),
'food_name': expressions.OutputContextField(
food_location.navigate_to_field('name'), GraphQLString),
'entity_related_to_food': expressions.OutputContextField(
entity_related_location.navigate_to_field('name'), GraphQLString),
'food_related_to_entity': expressions.OutputContextField(
food_related_location.navigate_to_field('name'), GraphQLString),
}),
]
expected_location_types = {
base_location: 'Species',
food_location: 'Food',
entity_related_location: 'Entity',
food_related_location: 'Entity',
}

check_test_data(self, test_data, expected_blocks, expected_location_types)

def test_filter_on_fragment_in_union(self):
test_data = test_input_data.filter_on_fragment_in_union()

Expand Down

0 comments on commit 26105f1

Please sign in to comment.