Prevent formatting GQL template literals with expressions (#2975)

* Prevent formatting GQL template literals with expressions

* Remove unnecessary check

* Change quasis check to expression check
master
Lucas Duailibe 2017-10-04 21:23:57 -03:00 committed by Lucas Azzola
parent 2fed6c873b
commit f82fcbc98e
3 changed files with 67 additions and 1 deletions

View File

@ -67,9 +67,10 @@ function fromBabylonFlowOrTypeScript(path) {
* gql`...`
*/
if (
// We currently don't support expression inside GraphQL template literals
parent.expressions.length === 0 &&
parentParent &&
((parentParent.type === "TaggedTemplateExpression" &&
parent.quasis.length === 1 &&
((parentParent.tag.type === "MemberExpression" &&
parentParent.tag.object.name === "graphql" &&
parentParent.tag.property.name === "experimental") ||

View File

@ -1,5 +1,52 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`expressions.js 1`] = `
// We currently don't support expressions in GraphQL template literals so these templates
// should not change.
graphql(schema, \`
query allPartsByManufacturerName($name: String!) {
allParts(filter:{manufacturer: {name: $name}}) {
... PartAll
}}
\${fragments.all}
\`)
const veryLongVariableNameToMakeTheLineBreak = graphql(schema, \`
query allPartsByManufacturerName($name: String!) {
allParts(filter:{manufacturer: {name: $name}}) {
... PartAll
}}
\${fragments.all}
\`)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// We currently don't support expressions in GraphQL template literals so these templates
// should not change.
graphql(
schema,
\`
query allPartsByManufacturerName($name: String!) {
allParts(filter:{manufacturer: {name: $name}}) {
... PartAll
}}
\${fragments.all}
\`
);
const veryLongVariableNameToMakeTheLineBreak = graphql(
schema,
\`
query allPartsByManufacturerName($name: String!) {
allParts(filter:{manufacturer: {name: $name}}) {
... PartAll
}}
\${fragments.all}
\`
);
`;
exports[`graphql.js 1`] = `
graphql(schema, \`
mutation MarkReadNotificationMutation(

View File

@ -0,0 +1,18 @@
// We currently don't support expressions in GraphQL template literals so these templates
// should not change.
graphql(schema, `
query allPartsByManufacturerName($name: String!) {
allParts(filter:{manufacturer: {name: $name}}) {
... PartAll
}}
${fragments.all}
`)
const veryLongVariableNameToMakeTheLineBreak = graphql(schema, `
query allPartsByManufacturerName($name: String!) {
allParts(filter:{manufacturer: {name: $name}}) {
... PartAll
}}
${fragments.all}
`)