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

Fix nested fragments on relations #385

Merged
merged 2 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/selections.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export function buildCypherSelection({
// Fragments can have a different schemaType than the upper field definition due to interfaces.
subSelection = headSelectionSetSelections
.filter(({ kind }) => kind === 'FragmentSpread')
.reduce((acc, cur, index) => {
.reduce((acc, cur) => {
const fragmentSelections = extractSelections(
resolveInfo.fragments[cur.name.value].selectionSet.selections,
resolveInfo.fragments
Expand All @@ -251,7 +251,7 @@ export function buildCypherSelection({
);

return recurse({
initial: index === 0 || !acc[0] ? acc[0] : acc[0] + ',',
initial: !acc[0] ? acc[0] : acc[0] + ',',
selections: fragmentSelections,
variableName: nestedVariable,
schemaType: fragmentSchemaType,
Expand Down
3 changes: 2 additions & 1 deletion test/unit/cypherTest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1833,14 +1833,15 @@ test('nested fragments on relations', t => {
fragment Foo on Movie {
title
actors {
userId
...Bar
}
}

fragment Bar on Actor {
name
}`,
expectedCypherQuery = `MATCH (\`movie\`:\`Movie\`${ADDITIONAL_MOVIE_LABELS} {year:$year}) RETURN \`movie\` { .title ,actors: [(\`movie\`)<-[:\`ACTED_IN\`]-(\`movie_actors\`:\`Actor\`) | movie_actors { .name }] } AS \`movie\``;
expectedCypherQuery = `MATCH (\`movie\`:\`Movie\`${ADDITIONAL_MOVIE_LABELS} {year:$year}) RETURN \`movie\` { .title ,actors: [(\`movie\`)<-[:\`ACTED_IN\`]-(\`movie_actors\`:\`Actor\`) | movie_actors { .userId , .name }] } AS \`movie\``;

t.plan(3);
return Promise.all([
Expand Down