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

Commit

Permalink
allow cypher properties in schema to be multiline
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Aug 20, 2020
1 parent dd74242 commit 056b06f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,32 @@ describe('graphql def creation', () => {
expect(generated).toMatch(new RegExp(`prop: String`));
});
});
describe('@cypher', () => {
it(`Outputs valid graphQL when @cypher directive invoked`, () => {
const schema = {
types: [
{
name: 'Fake',
description: 'Fake type description',
properties: {
prop: {
type: 'Fake',
description: 'a description',
cypher: `Multi
line with
"quotes"`,
},
},
},
],
enums: {},
stringPatterns,
primitiveTypes: {},
};
const generated = [].concat(...graphqlFromRawData(schema)).join('');
expect(generated).toMatch(
'prop: Fake @cypher(statement: "Multi\\nline with\\n\\"quotes\\"")',
);
});
});
});
5 changes: 4 additions & 1 deletion packages/tc-schema-sdk/data-accessors/graphql-defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ const maybePaginate = ({ hasMany, isRelationship }) =>

const maybeDirective = def => {
if (def.cypher) {
return `@cypher(statement: "${def.cypher}")`;
return `@cypher(statement: "${def.cypher
.replace(/"/g, '\\"')
.split(/\n/)
.join('\\n')}")`;
}
if (def.relationship) {
return `@relation(name: "${def.relationship}", direction: "${
Expand Down

0 comments on commit 056b06f

Please sign in to comment.