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

Commit c9b8b1a

Browse files
committed
Don't use string for relationship direction in relation directive
Instead use the _RelationDirections enum
1 parent 6e7a357 commit c9b8b1a

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"test-all": "nyc ava --verbose",
2323
"test-isolated": "nyc ava test/**/*.test.js --verbose --match='!*not-isolated*'",
2424
"test-gateway": "nyc --reporter=lcov ava --fail-fast test/integration/gateway.test.js",
25+
"test-infer": "nyc --reporter=lcov ava --fail-fast test/unit/neo4j-schema/*.js",
2526
"debug": "nodemon ./example/apollo-server/movies.js --exec babel-node --inspect-brk=9229 --nolazy",
2627
"debug-typedefs": "nodemon ./example/apollo-server/movies-typedefs.js --exec babel-node --inspect-brk=9229 --nolazy",
2728
"debug-interface": "nodemon ./example/apollo-server/interfaceError.js --exec babel-node --inspect-brk=9229 --nolazy",

src/inferSchema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const generateGraphQLTypeForTreeEntry = (tree, key) => {
5757

5858
const tag = `@relation(name: "${extractRelationshipType(
5959
relId
60-
)}", direction: "OUT")`;
60+
)}", direction: OUT)`;
6161
const targetTypeName = allTargetLabels[0];
6262

6363
return ` ${targetTypeName.toLowerCase()}s: [${targetTypeName}] ${tag}\n`;

src/neo4j-schema/graphQLMapper.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Debug from 'debug';
66
const debug = Debug('neo4j-graphql-js');
77

88
const relationDirective = (relType, direction) =>
9-
`@relation(name: "${relType}", direction: "${direction}")`;
9+
`@relation(name: "${relType}", direction: ${direction})`;
1010

1111
const mapOutboundRels = (tree, node, config) => {
1212
const labels = node.getLabels();
@@ -25,9 +25,7 @@ const mapOutboundRels = (tree, node, config) => {
2525
// (:Customer)-[:BUYS]->(:Service)
2626
// In this case, without type unions the destination type for :BUYS is ambiguous.
2727
console.warn(
28-
`RelID ${
29-
rel.id
30-
} for label set ${labels} has > 1 target type (${targetLabels}); skipping`
28+
`RelID ${rel.id} for label set ${labels} has > 1 target type (${targetLabels}); skipping`
3129
);
3230
return null;
3331
}
@@ -79,9 +77,7 @@ const mapInboundRels = (tree, node, config) => {
7977

8078
if (originLabels.length > 1) {
8179
console.warn(
82-
`RelID ${
83-
rel.id
84-
} for label set ${labels} has > 1 origin type (${originLabels}); skipping`
80+
`RelID ${rel.id} for label set ${labels} has > 1 origin type (${originLabels}); skipping`
8581
);
8682
return null;
8783
}

test/unit/neo4j-schema/graphQLMapperTest.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ test('Defines properties with correct types', t => {
107107
test('Defines relationships BOTH WAYS with right order and @relation directive', t => {
108108
t.true(
109109
typeDefs.indexOf(
110-
'lives_in: [State] @relation(name: "LIVES_IN", direction: "OUT")'
110+
'lives_in: [State] @relation(name: "LIVES_IN", direction: OUT)'
111111
) > -1
112112
);
113113
t.true(
114114
typeDefs.indexOf(
115-
'customers: [Customer] @relation(name: "LIVES_IN", direction: "IN")'
115+
'customers: [Customer] @relation(name: "LIVES_IN", direction: IN)'
116116
) > -1
117117
);
118118
});
@@ -123,13 +123,13 @@ test('Deconflicts names for multi-targeted relationships by using relationship l
123123
// conflict. This tests that the module has worked around this.
124124
t.true(
125125
typeDefs.indexOf(
126-
'customers_buys: [Customer] @relation(name: "BUYS", direction: "IN")'
126+
'customers_buys: [Customer] @relation(name: "BUYS", direction: IN)'
127127
) > -1
128128
);
129129

130130
t.true(
131131
typeDefs.indexOf(
132-
'customers_reviewed: [Customer] @relation(name: "REVIEWED", direction: "IN")'
132+
'customers_reviewed: [Customer] @relation(name: "REVIEWED", direction: IN)'
133133
) > -1
134134
);
135135
});

0 commit comments

Comments
 (0)