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

Use underscore instead of dash for query variables #107

Merged
merged 1 commit into from
Sep 19, 2018
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
2 changes: 1 addition & 1 deletion src/selections.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function buildCypherSelection({
);
const shallowFilterParams = Object.entries(filterParams).reduce(
(result, [key, value]) => {
result[`${value.index}-${key}`] = value.value;
result[`${value.index}_${key}`] = value.value;
return result;
},
{}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export function innerFilterParams(filters) {
.map(
([key, value]) =>
`${key}:$${
typeof value.index === 'undefined' ? key : `${value.index}-${key}`
typeof value.index === 'undefined' ? key : `${value.index}_${key}`
}`
)
.join(',')}}`
Expand Down
34 changes: 17 additions & 17 deletions test/cypherTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test('Cypher projection skip limit', t => {
return Promise.all([
cypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery, {
title: 'River Runs Through It, A',
'1-first': 3,
'1_first': 3,
first: -1,
offset: 0
}),
Expand Down Expand Up @@ -209,14 +209,14 @@ test('Deeply nested object query', t => {
}
}
}`,
expectedCypherQuery = `MATCH (movie:Movie {title:$title}) RETURN movie { .title ,actors: [(movie)<-[:ACTED_IN]-(movie_actors:Actor) | movie_actors { .name ,movies: [(movie_actors)-[:ACTED_IN]->(movie_actors_movies:Movie) | movie_actors_movies { .title ,actors: [(movie_actors_movies)<-[:ACTED_IN]-(movie_actors_movies_actors:Actor{name:$1-name}) | movie_actors_movies_actors { .name ,movies: [(movie_actors_movies_actors)-[:ACTED_IN]->(movie_actors_movies_actors_movies:Movie) | movie_actors_movies_actors_movies { .title , .year ,similar: [ movie_actors_movies_actors_movies_similar IN apoc.cypher.runFirstColumn("WITH {this} AS this MATCH (this)--(:Genre)--(o:Movie) RETURN o", {this: movie_actors_movies_actors_movies, first: 3, offset: 0}, true) | movie_actors_movies_actors_movies_similar { .title , .year }][..3] }] }] }] }] } AS movie SKIP $offset`;
expectedCypherQuery = `MATCH (movie:Movie {title:$title}) RETURN movie { .title ,actors: [(movie)<-[:ACTED_IN]-(movie_actors:Actor) | movie_actors { .name ,movies: [(movie_actors)-[:ACTED_IN]->(movie_actors_movies:Movie) | movie_actors_movies { .title ,actors: [(movie_actors_movies)<-[:ACTED_IN]-(movie_actors_movies_actors:Actor{name:$1_name}) | movie_actors_movies_actors { .name ,movies: [(movie_actors_movies_actors)-[:ACTED_IN]->(movie_actors_movies_actors_movies:Movie) | movie_actors_movies_actors_movies { .title , .year ,similar: [ movie_actors_movies_actors_movies_similar IN apoc.cypher.runFirstColumn("WITH {this} AS this MATCH (this)--(:Genre)--(o:Movie) RETURN o", {this: movie_actors_movies_actors_movies, first: 3, offset: 0}, true) | movie_actors_movies_actors_movies_similar { .title , .year }][..3] }] }] }] }] } AS movie SKIP $offset`;

t.plan(3);
return Promise.all([
cypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery, {
title: 'River Runs Through It, A',
'1-name': 'Tom Hanks',
'2-first': 3,
'1_name': 'Tom Hanks',
'2_first': 3,
first: -1,
offset: 0
}),
Expand Down Expand Up @@ -348,7 +348,7 @@ test('Pass @cypher directive params to sub-query', t => {
first: -1,
offset: 0,
title: 'River Runs Through It, A',
'1-scale': 10
'1_scale': 10
}),
augmentedSchemaCypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery)
]);
Expand Down Expand Up @@ -489,16 +489,16 @@ test('Cypher subquery filters', t => {
}
}`,
expectedCypherQuery =
'MATCH (movie:Movie {title:$title}) RETURN movie { .title ,actors: [(movie)<-[:ACTED_IN]-(movie_actors:Actor{name:$1-name}) | movie_actors { .name }] ,similar: [ movie_similar IN apoc.cypher.runFirstColumn("WITH {this} AS this MATCH (this)--(:Genre)--(o:Movie) RETURN o", {this: movie, first: 3, offset: 0}, true) | movie_similar { .title }][..3] } AS movie SKIP $offset';
'MATCH (movie:Movie {title:$title}) RETURN movie { .title ,actors: [(movie)<-[:ACTED_IN]-(movie_actors:Actor{name:$1_name}) | movie_actors { .name }] ,similar: [ movie_similar IN apoc.cypher.runFirstColumn("WITH {this} AS this MATCH (this)--(:Genre)--(o:Movie) RETURN o", {this: movie, first: 3, offset: 0}, true) | movie_similar { .title }][..3] } AS movie SKIP $offset';

t.plan(3);
return Promise.all([
cypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery, {
title: 'River Runs Through It, A',
first: -1,
offset: 0,
'1-name': 'Tom Hanks',
'3-first': 3
'1_name': 'Tom Hanks',
'3_first': 3
}),
augmentedSchemaCypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery)
]);
Expand All @@ -518,17 +518,17 @@ test('Cypher subquery filters with paging', t => {
}
}`,
expectedCypherQuery =
'MATCH (movie:Movie {title:$title}) RETURN movie { .title ,actors: [(movie)<-[:ACTED_IN]-(movie_actors:Actor{name:$1-name}) | movie_actors { .name }][..3] ,similar: [ movie_similar IN apoc.cypher.runFirstColumn("WITH {this} AS this MATCH (this)--(:Genre)--(o:Movie) RETURN o", {this: movie, first: 3, offset: 0}, true) | movie_similar { .title }][..3] } AS movie SKIP $offset';
'MATCH (movie:Movie {title:$title}) RETURN movie { .title ,actors: [(movie)<-[:ACTED_IN]-(movie_actors:Actor{name:$1_name}) | movie_actors { .name }][..3] ,similar: [ movie_similar IN apoc.cypher.runFirstColumn("WITH {this} AS this MATCH (this)--(:Genre)--(o:Movie) RETURN o", {this: movie, first: 3, offset: 0}, true) | movie_similar { .title }][..3] } AS movie SKIP $offset';

t.plan(3);
return Promise.all([
cypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery, {
title: 'River Runs Through It, A',
first: -1,
offset: 0,
'1-first': 3,
'1-name': 'Tom Hanks',
'3-first': 3
'1_first': 3,
'1_name': 'Tom Hanks',
'3_first': 3
}),
augmentedSchemaCypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery)
]);
Expand All @@ -554,7 +554,7 @@ test('Handle @cypher directive on Query Type', t => {
substring: 'Action',
first: -1,
offset: 0,
'1-first': 3
'1_first': 3
}),
augmentedSchemaCypherTestRunner(t, graphQLQuery, {}, expectedCypherQuery)
]);
Expand Down Expand Up @@ -744,7 +744,7 @@ test('Handle GraphQL variables in nested selection - first/offset', t => {
{ year: 2016, first: 3 },
expectedCypherQuery,
{
'1-first': 3,
'1_first': 3,
year: 2016,
first: -1,
offset: 0
Expand Down Expand Up @@ -785,8 +785,8 @@ test('Handle GraphQL variables in nest selection - @cypher param (not first/offs
year: 2016,
first: -1,
offset: 0,
'1-first': 3,
'2-scale': 5
'1_first': 3,
'2_scale': 5
}
),
augmentedSchemaCypherTestRunner(
Expand Down Expand Up @@ -1056,7 +1056,7 @@ test('orderBy test - descending, top level - augmented schema', t => {
offset: 0,
first: 10,
year: 2010,
'1-first': 3
'1_first': 3
}
);
});