Skip to content

Commit

Permalink
fix(graphql): handle all long aliases (#272)
Browse files Browse the repository at this point in the history
Fixes #268; previously only long aliases whose sha1sum began with a letter passed 馃槼
  • Loading branch information
benjie committed Aug 16, 2018
1 parent 0fce134 commit 92d82da
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/graphile-build-pg/src/QueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class QueryBuilder {
// https://github.com/graphql/graphql-js/blob/680685dd14bd52c6475305e150e5f295ead2aa7e/src/language/lexer.js#L551-L581
//
// so this should not cause any issues in practice.
if (/^@*[_A-Za-z][_0-9A-Za-z]*$/.test(alias) !== true) {
if (/^(@+|[_A-Za-z])[_0-9A-Za-z]*$/.test(alias) !== true) {
throw new Error(`Disallowed alias '${alias}'.`);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
query {
person: personByEmail(email: "sara.smith@email.com") {
nodeId
email

# safe alias: @@25fa9871b4d4d16ffd41359c88e7e851739819c6
aVeryLongAliasInOrderToTestThatThingsGoThroughPostgresJustFineAndWeDontGetAnyIssuesDueToAliasLength: friends {
totalCount
}

# safe alias: @@e82261e340b3c5fc784bd0d54ec53541f5a4e2fe
anotherLongAliasInOrderToTestThatThingsGoThroughPostgresJustFineAndWeDontGetAnyIssuesDueToAliasLength: friends {
totalCount
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,23 @@ Object {
}
`;

exports[`longAliases.graphql 1`] = `
Object {
"data": Object {
"person": Object {
"aVeryLongAliasInOrderToTestThatThingsGoThroughPostgresJustFineAndWeDontGetAnyIssuesDueToAliasLength": Object {
"totalCount": 2,
},
"anotherLongAliasInOrderToTestThatThingsGoThroughPostgresJustFineAndWeDontGetAnyIssuesDueToAliasLength": Object {
"totalCount": 2,
},
"email": "sara.smith@email.com",
"nodeId": "WyJwZW9wbGUiLDJd",
},
},
}
`;

exports[`node.graphql 1`] = `
Object {
"data": Object {
Expand Down

0 comments on commit 92d82da

Please sign in to comment.