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

Commit

Permalink
Don't use string for relationship direction in relation directive
Browse files Browse the repository at this point in the history
Instead use the _RelationDirections enum
  • Loading branch information
johnymontana committed Jul 8, 2020
1 parent 6e7a357 commit c9b8b1a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"test-all": "nyc ava --verbose",
"test-isolated": "nyc ava test/**/*.test.js --verbose --match='!*not-isolated*'",
"test-gateway": "nyc --reporter=lcov ava --fail-fast test/integration/gateway.test.js",
"test-infer": "nyc --reporter=lcov ava --fail-fast test/unit/neo4j-schema/*.js",
"debug": "nodemon ./example/apollo-server/movies.js --exec babel-node --inspect-brk=9229 --nolazy",
"debug-typedefs": "nodemon ./example/apollo-server/movies-typedefs.js --exec babel-node --inspect-brk=9229 --nolazy",
"debug-interface": "nodemon ./example/apollo-server/interfaceError.js --exec babel-node --inspect-brk=9229 --nolazy",
Expand Down
2 changes: 1 addition & 1 deletion src/inferSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const generateGraphQLTypeForTreeEntry = (tree, key) => {

const tag = `@relation(name: "${extractRelationshipType(
relId
)}", direction: "OUT")`;
)}", direction: OUT)`;

This comment has been minimized.

Copy link
@SebSaveBySolar

SebSaveBySolar Jan 7, 2021

Please change the docs accordingly, there's a few issues up regarding this and I spent a bit of time working this out.

const targetTypeName = allTargetLabels[0];

return ` ${targetTypeName.toLowerCase()}s: [${targetTypeName}] ${tag}\n`;
Expand Down
10 changes: 3 additions & 7 deletions src/neo4j-schema/graphQLMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Debug from 'debug';
const debug = Debug('neo4j-graphql-js');

const relationDirective = (relType, direction) =>
`@relation(name: "${relType}", direction: "${direction}")`;
`@relation(name: "${relType}", direction: ${direction})`;

const mapOutboundRels = (tree, node, config) => {
const labels = node.getLabels();
Expand All @@ -25,9 +25,7 @@ const mapOutboundRels = (tree, node, config) => {
// (:Customer)-[:BUYS]->(:Service)
// In this case, without type unions the destination type for :BUYS is ambiguous.
console.warn(
`RelID ${
rel.id
} for label set ${labels} has > 1 target type (${targetLabels}); skipping`
`RelID ${rel.id} for label set ${labels} has > 1 target type (${targetLabels}); skipping`
);
return null;
}
Expand Down Expand Up @@ -79,9 +77,7 @@ const mapInboundRels = (tree, node, config) => {

if (originLabels.length > 1) {
console.warn(
`RelID ${
rel.id
} for label set ${labels} has > 1 origin type (${originLabels}); skipping`
`RelID ${rel.id} for label set ${labels} has > 1 origin type (${originLabels}); skipping`
);
return null;
}
Expand Down
8 changes: 4 additions & 4 deletions test/unit/neo4j-schema/graphQLMapperTest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ test('Defines properties with correct types', t => {
test('Defines relationships BOTH WAYS with right order and @relation directive', t => {
t.true(
typeDefs.indexOf(
'lives_in: [State] @relation(name: "LIVES_IN", direction: "OUT")'
'lives_in: [State] @relation(name: "LIVES_IN", direction: OUT)'
) > -1
);
t.true(
typeDefs.indexOf(
'customers: [Customer] @relation(name: "LIVES_IN", direction: "IN")'
'customers: [Customer] @relation(name: "LIVES_IN", direction: IN)'
) > -1
);
});
Expand All @@ -123,13 +123,13 @@ test('Deconflicts names for multi-targeted relationships by using relationship l
// conflict. This tests that the module has worked around this.
t.true(
typeDefs.indexOf(
'customers_buys: [Customer] @relation(name: "BUYS", direction: "IN")'
'customers_buys: [Customer] @relation(name: "BUYS", direction: IN)'
) > -1
);

t.true(
typeDefs.indexOf(
'customers_reviewed: [Customer] @relation(name: "REVIEWED", direction: "IN")'
'customers_reviewed: [Customer] @relation(name: "REVIEWED", direction: IN)'
) > -1
);
});
Expand Down

0 comments on commit c9b8b1a

Please sign in to comment.