Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Commit de1989a

Browse files
authoredJul 24, 2018
Merge pull request #79 from cooperka/relation-frags
Allow fragments within relations
2 parents 4f79afa + f29ce75 commit de1989a

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed
 

‎src/selections.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
innerType,
99
isArrayType,
1010
isGraphqlScalarType,
11+
extractSelections,
1112
relationDirective
1213
} from './utils';
1314

@@ -105,9 +106,14 @@ export function buildCypherSelection({
105106
const nestedVariable = variableName + '_' + fieldName;
106107
const skipLimit = computeSkipLimit(headSelection, resolveInfo.variableValues);
107108

109+
const subSelections = extractSelections(
110+
headSelection.selectionSet.selections,
111+
resolveInfo.fragments
112+
);
113+
108114
const subSelection = recurse({
109115
initial: '',
110-
selections: headSelection.selectionSet.selections,
116+
selections: subSelections,
111117
variableName: nestedVariable,
112118
schemaType: innerSchemaType,
113119
resolveInfo

‎test/cypherTest.js

+58
Original file line numberDiff line numberDiff line change
@@ -911,3 +911,61 @@ test('nested fragments', t => {
911911
augmentedSchemaCypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery)
912912
]);
913913
});
914+
915+
test('fragments on relations', t => {
916+
const graphQLQuery = `
917+
query movieItems {
918+
Movie(year:2010) {
919+
title
920+
actors {
921+
...Foo
922+
}
923+
}
924+
}
925+
926+
fragment Foo on Actor {
927+
name
928+
}`,
929+
expectedCypherQuery = `MATCH (movie:Movie {year:$year}) RETURN movie { .title ,actors: [(movie)<-[:ACTED_IN]-(movie_actors:Actor) | movie_actors { .name }] } AS movie SKIP $offset`;
930+
931+
t.plan(3);
932+
return Promise.all([
933+
cypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery, {
934+
year: 2010,
935+
first: -1,
936+
offset: 0
937+
}),
938+
augmentedSchemaCypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery)
939+
]);
940+
});
941+
942+
test('nested fragments on relations', t => {
943+
const graphQLQuery = `
944+
query movieItems {
945+
Movie(year:2010) {
946+
...Foo
947+
}
948+
}
949+
950+
fragment Foo on Movie {
951+
title
952+
actors {
953+
...Bar
954+
}
955+
}
956+
957+
fragment Bar on Actor {
958+
name
959+
}`,
960+
expectedCypherQuery = `MATCH (movie:Movie {year:$year}) RETURN movie { .title ,actors: [(movie)<-[:ACTED_IN]-(movie_actors:Actor) | movie_actors { .name }] } AS movie SKIP $offset`;
961+
962+
t.plan(3);
963+
return Promise.all([
964+
cypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery, {
965+
year: 2010,
966+
first: -1,
967+
offset: 0
968+
}),
969+
augmentedSchemaCypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery)
970+
]);
971+
});

0 commit comments

Comments
 (0)