feat(mutliparser): add react-relay and graphql-tag parsing (#2092)

master
Lucas Azzola 2017-06-11 01:59:27 +10:00 committed by Christopher Chedeau
parent d1b94c540c
commit b4f0ff346e
6 changed files with 100 additions and 2 deletions

View File

@ -149,10 +149,12 @@ function massageAST(ast) {
quasis.forEach(q => delete q.value);
}
// styled-components
// styled-components and graphql
if (
ast.type === "TaggedTemplateExpression" &&
ast.tag.type === "MemberExpression"
(ast.tag.type === "MemberExpression" ||
(ast.tag.type === "Identifier" &&
(ast.tag.name === "gql" || ast.tag.name === "graphql")))
) {
newObj.quasi.quasis.forEach(quasi => delete quasi.value);
}

View File

@ -83,6 +83,29 @@ function fromBabylonFlowOrTypeScript(path) {
};
}
/*
* react-relay and graphql-tag
* graphql`...`
* gql`...`
*/
if (
parentParent &&
parentParent.type === "TaggedTemplateExpression" &&
parent.quasis.length === 1 &&
// ((parentParent.tag.type === "MemberExpression" &&
// parentParent.tag.object.name === "Relay" &&
// parentParent.tag.property.name === "QL") ||
(parentParent.tag.type === "Identifier" &&
(parentParent.tag.name === "gql" ||
parentParent.tag.name === "graphql"))
) {
return {
parser: "graphql",
wrap: doc => concat([indent(concat([softline, doc])), softline]),
text: parent.quasis[0].value.raw
};
}
break;
}
}

View File

@ -0,0 +1,52 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`graphql-tag.js 1`] = `
import gql from "graphql-tag";
const query = gql\`
{
user( id : 5 ) {
firstName
lastName
}
}
\`;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import gql from "graphql-tag";
const query = gql\`
{
user(id: 5) {
firstName
lastName
}
}
\`;
`;
exports[`react-relay.js 1`] = `
const { graphql } = require("react-relay");
graphql\`
mutation MarkReadNotificationMutation(
$input
: MarkReadNotificationData!
)
{ markReadNotification(data: $input ) { notification {seenState} } }
\`;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const { graphql } = require("react-relay");
graphql\`
mutation MarkReadNotificationMutation($input: MarkReadNotificationData!) {
markReadNotification(data: $input) {
notification {
seenState
}
}
}
\`;
`;

View File

@ -0,0 +1,11 @@
import gql from "graphql-tag";
const query = gql`
{
user( id : 5 ) {
firstName
lastName
}
}
`;

View File

@ -0,0 +1 @@
run_spec(__dirname, { parser: "babylon" });

View File

@ -0,0 +1,9 @@
const { graphql } = require("react-relay");
graphql`
mutation MarkReadNotificationMutation(
$input
: MarkReadNotificationData!
)
{ markReadNotification(data: $input ) { notification {seenState} } }
`;