Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby): support node: protocol when bundling engines #36506

Merged
merged 4 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions e2e-tests/production-runtime/cypress/integration/ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,15 @@ describe(`500 status`, () => {
.should(`exist`)
})
})

describe(`"node:" protocol`, () => {
it.only(`engines work when bundled code contains node:path import`, () => {
pieh marked this conversation as resolved.
Show resolved Hide resolved
cy.visit(`/ssr/using-node-protocol/`).waitForRouteChange()

// validating that this page was rendered with SSR mode
cy.getTestElement(`is-ssr`).contains(`true`)

// content of field is generated using `node:path` import
cy.getTestElement(`field-result`).contains(`"foo/bar"`)
})
})
1 change: 1 addition & 0 deletions e2e-tests/production-runtime/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
},
`gatsby-plugin-local-worker`,
`gatsby-ssr-tsx`,
`gatsby-plugin-node-protocol-test`,
`gatsby-plugin-image`,
`gatsby-plugin-sharp`,
`gatsby-plugin-sass`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const path = require(`node:path`)

exports.createResolvers = ({ createResolvers }) => {
createResolvers({
Query: {
fieldWithResolverThatMakeUseOfImportWithNodeProtocol: {
type: `String`,
args: {
left: `String!`,
right: `String!`,
},
resolve: (_, args) => {
return path.posix.join(args.left, args.right)
},
},
},
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// noop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
35 changes: 35 additions & 0 deletions e2e-tests/production-runtime/src/pages/ssr/using-node-protocol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from "react"
import { graphql } from "gatsby"

export default function StaticPath({ data, serverData }) {
return (
<>
<pre data-testid="field-result">
{JSON.stringify(
data?.fieldWithResolverThatMakeUseOfImportWithNodeProtocol
)}
</pre>
<pre data-testid="is-ssr">
{JSON.stringify(serverData?.usingEngines ?? false)}
</pre>
</>
)
}

// just mark it as page that will use engine
export async function getServerData() {
return {
props: {
usingEngines: true,
},
}
}

export const q = graphql`
{
fieldWithResolverThatMakeUseOfImportWithNodeProtocol(
left: "foo"
right: "bar"
)
}
`
2 changes: 2 additions & 0 deletions packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ export async function createGraphqlEngineBundle(
mod.builtinModules.reduce((acc, builtinModule) => {
if (builtinModule === `fs`) {
acc[builtinModule] = `global _actualFsWrapper`
acc[`node:${builtinModule}`] = `global _actualFsWrapper`
} else {
acc[builtinModule] = `commonjs ${builtinModule}`
acc[`node:${builtinModule}`] = `commonjs ${builtinModule}`
}

return acc
Expand Down