From d504d44b4fe0ed0ad0188c1c8bbd46eeebe7ee03 Mon Sep 17 00:00:00 2001 From: Victor Cordova Date: Thu, 13 Dec 2018 01:51:12 +0100 Subject: [PATCH] fix(gatsby): fix extracting StaticQuery nested in shorthand fragment (#10443) --- packages/gatsby/package.json | 1 - .../src/bootstrap/resolve-module-exports.js | 2 +- .../__snapshots__/file-parser.js.snap | 112 ++++++++++++++++++ .../query-runner/__tests__/file-parser.js | 21 ++++ .../query-runner/file-parser.js | 2 +- yarn.lock | 2 +- 6 files changed, 136 insertions(+), 4 deletions(-) diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index 3a6f19079a4be..78531cd05e013 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -27,7 +27,6 @@ "babel-plugin-dynamic-import-node": "^1.2.0", "babel-plugin-remove-graphql-queries": "^2.5.2", "babel-preset-gatsby": "^0.1.6", - "babel-traverse": "6.26.0", "better-queue": "^3.8.6", "bluebird": "^3.5.0", "browserslist": "3.2.8", diff --git a/packages/gatsby/src/bootstrap/resolve-module-exports.js b/packages/gatsby/src/bootstrap/resolve-module-exports.js index 30057db5361fe..f6367f740e76e 100644 --- a/packages/gatsby/src/bootstrap/resolve-module-exports.js +++ b/packages/gatsby/src/bootstrap/resolve-module-exports.js @@ -1,6 +1,6 @@ // @flow const fs = require(`fs`) -const traverse = require(`babel-traverse`).default +const traverse = require(`@babel/traverse`).default const get = require(`lodash/get`) const { codeFrameColumns } = require(`@babel/code-frame`) const { babelParseToAst } = require(`../utils/babel-parse-to-ast`) diff --git a/packages/gatsby/src/internal-plugins/query-runner/__tests__/__snapshots__/file-parser.js.snap b/packages/gatsby/src/internal-plugins/query-runner/__tests__/__snapshots__/file-parser.js.snap index d1c34627e3d77..d009d33559ca9 100644 --- a/packages/gatsby/src/internal-plugins/query-runner/__tests__/__snapshots__/file-parser.js.snap +++ b/packages/gatsby/src/internal-plugins/query-runner/__tests__/__snapshots__/file-parser.js.snap @@ -590,6 +590,118 @@ Map { ], "kind": "Document", }, + "fragment-shorthand.js" => Object { + "definitions": Array [ + Object { + "directives": Array [], + "hash": 1097489062, + "isStaticQuery": true, + "kind": "OperationDefinition", + "loc": Object { + "end": 74, + "start": 3, + }, + "name": Object { + "kind": "Name", + "value": "fragmentShorthandJs1097489062", + }, + "operation": "query", + "selectionSet": Object { + "kind": "SelectionSet", + "loc": Object { + "end": 74, + "start": 9, + }, + "selections": Array [ + Object { + "alias": undefined, + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "loc": Object { + "end": 70, + "start": 15, + }, + "name": Object { + "kind": "Name", + "loc": Object { + "end": 19, + "start": 15, + }, + "value": "site", + }, + "selectionSet": Object { + "kind": "SelectionSet", + "loc": Object { + "end": 70, + "start": 20, + }, + "selections": Array [ + Object { + "alias": undefined, + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "loc": Object { + "end": 64, + "start": 28, + }, + "name": Object { + "kind": "Name", + "loc": Object { + "end": 40, + "start": 28, + }, + "value": "siteMetadata", + }, + "selectionSet": Object { + "kind": "SelectionSet", + "loc": Object { + "end": 64, + "start": 41, + }, + "selections": Array [ + Object { + "alias": undefined, + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "loc": Object { + "end": 56, + "start": 51, + }, + "name": Object { + "kind": "Name", + "loc": Object { + "end": 56, + "start": 51, + }, + "value": "title", + }, + "selectionSet": undefined, + }, + ], + }, + }, + ], + }, + }, + ], + }, + "text": " + query { + site { + siteMetadata { + title + } + } + } +", + "variableDefinitions": Array [], + }, + ], + "kind": "Document", + }, "query-in-separate-variable.js" => Object { "definitions": Array [ Object { diff --git a/packages/gatsby/src/internal-plugins/query-runner/__tests__/file-parser.js b/packages/gatsby/src/internal-plugins/query-runner/__tests__/file-parser.js index 680373ccf423e..707de4a2cd9ec 100644 --- a/packages/gatsby/src/internal-plugins/query-runner/__tests__/file-parser.js +++ b/packages/gatsby/src/internal-plugins/query-runner/__tests__/file-parser.js @@ -80,6 +80,27 @@ export const fragment3 = graphql\` } \` `, + "fragment-shorthand.js": `import React from "react" +import { StaticQuery, graphql } from "gatsby" + +const query = graphql\` + query { + site { + siteMetadata { + title + } + } + } +\` + +export default () => ( + <> +
{data.title}
} + /> + +)`, "query-in-separate-variable.js": `import React from "react" import { StaticQuery, graphql } from "gatsby" diff --git a/packages/gatsby/src/internal-plugins/query-runner/file-parser.js b/packages/gatsby/src/internal-plugins/query-runner/file-parser.js index e13d818001d13..997b3c5290a29 100644 --- a/packages/gatsby/src/internal-plugins/query-runner/file-parser.js +++ b/packages/gatsby/src/internal-plugins/query-runner/file-parser.js @@ -4,7 +4,7 @@ const crypto = require(`crypto`) const _ = require(`lodash`) // Traverse is a es6 module... -import traverse from "babel-traverse" +import traverse from "@babel/traverse" const getGraphQLTag = require(`babel-plugin-remove-graphql-queries`) .getGraphQLTag const report = require(`gatsby-cli/lib/reporter`) diff --git a/yarn.lock b/yarn.lock index 14adac823fefc..0693dd16be6e8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3701,7 +3701,7 @@ babel-template@^6.16.0, babel-template@^6.24.1, babel-template@^6.26.0, babel-te babylon "^6.18.0" lodash "^4.17.4" -babel-traverse@6.26.0, babel-traverse@^6.0.0, babel-traverse@^6.18.0, babel-traverse@^6.24.1, babel-traverse@^6.26.0: +babel-traverse@^6.0.0, babel-traverse@^6.18.0, babel-traverse@^6.24.1, babel-traverse@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee" integrity sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4=