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

Commit

Permalink
Merge pull request #79 from cooperka/relation-frags
Browse files Browse the repository at this point in the history
Allow fragments within relations
  • Loading branch information
johnymontana authored Jul 24, 2018
2 parents 4f79afa + f29ce75 commit de1989a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/selections.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
innerType,
isArrayType,
isGraphqlScalarType,
extractSelections,
relationDirective
} from './utils';

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

const subSelections = extractSelections(
headSelection.selectionSet.selections,
resolveInfo.fragments
);

const subSelection = recurse({
initial: '',
selections: headSelection.selectionSet.selections,
selections: subSelections,
variableName: nestedVariable,
schemaType: innerSchemaType,
resolveInfo
Expand Down
58 changes: 58 additions & 0 deletions test/cypherTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,3 +911,61 @@ test('nested fragments', t => {
augmentedSchemaCypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery)
]);
});

test('fragments on relations', t => {
const graphQLQuery = `
query movieItems {
Movie(year:2010) {
title
actors {
...Foo
}
}
}
fragment Foo on Actor {
name
}`,
expectedCypherQuery = `MATCH (movie:Movie {year:$year}) RETURN movie { .title ,actors: [(movie)<-[:ACTED_IN]-(movie_actors:Actor) | movie_actors { .name }] } AS movie SKIP $offset`;

t.plan(3);
return Promise.all([
cypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery, {
year: 2010,
first: -1,
offset: 0
}),
augmentedSchemaCypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery)
]);
});

test('nested fragments on relations', t => {
const graphQLQuery = `
query movieItems {
Movie(year:2010) {
...Foo
}
}
fragment Foo on Movie {
title
actors {
...Bar
}
}
fragment Bar on Actor {
name
}`,
expectedCypherQuery = `MATCH (movie:Movie {year:$year}) RETURN movie { .title ,actors: [(movie)<-[:ACTED_IN]-(movie_actors:Actor) | movie_actors { .name }] } AS movie SKIP $offset`;

t.plan(3);
return Promise.all([
cypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery, {
year: 2010,
first: -1,
offset: 0
}),
augmentedSchemaCypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery)
]);
});

0 comments on commit de1989a

Please sign in to comment.