Skip to content

Commit

Permalink
feat(gatsby): remove unused exports from query-engine
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Oct 11, 2021
1 parent eafb2e1 commit ea2a625
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export async function createGraphqlEngineBundle(

const compiler = webpack({
name: `Query Engine`,
// mode: `production`,
mode: `none`,
entry: path.join(__dirname, `entry.js`),
output: {
Expand Down Expand Up @@ -101,6 +100,9 @@ export async function createGraphqlEngineBundle(
process.env.GATSBY_WEBPACK_LOGGING?.includes(`query-engine`) &&
new WebpackLoggingPlugin(rootDir, reporter, isVerbose),
].filter(Boolean) as Array<webpack.WebpackPluginInstance>,
optimization: {
minimize: false,
},
})

return new Promise((resolve, reject) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/src/schema/graphql-engine/print-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { store } from "../../redux"
import { IGatsbyState } from "../../redux/types"
import { requireGatsbyPlugin } from "../../utils/require-gatsby-plugin"

const schemaCustomizationAPIs = new Set([
export const schemaCustomizationAPIs = new Set([
`setFieldsOnGraphQLNodeType`,
`createSchemaCustomization`,
`createResolvers`,
Expand Down Expand Up @@ -73,7 +73,7 @@ function render(
const imports: Array<string> = [
...uniqGatsbyNode.map(
(plugin, i) =>
`import * as pluginGatsbyNode${i} from "${relativePluginPath(
`import * as pluginGatsbyNode${i} from "gatsby/dist/schema/graphql-engine/webpack-remove-apis-loader!${relativePluginPath(
plugin.resolve
)}/gatsby-node"`
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { transformSync } from "@babel/core"
import { GatsbyNodeAPI } from "../../redux/types"
import * as nodeApis from "../../utils/api-node-docs"
import { schemaCustomizationAPIs } from "./print-plugins"

module.exports = function loader(source: string): string | null | undefined {
const result = transformSync(source, {
babelrc: false,
configFile: false,
plugins: [
[
require.resolve(`../../utils/babel/babel-plugin-remove-api`),
{
apis: (Object.keys(nodeApis) as Array<GatsbyNodeAPI>).filter(
api => !schemaCustomizationAPIs.has(api)
),
},
],
],
})

return result?.code
}

0 comments on commit ea2a625

Please sign in to comment.