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

fix(gatsby): Remove GATSBY_BUILD_STAGE & warn against ___NODE #33501

Merged
merged 7 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/babel-preset-gatsby/src/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export default (_?: unknown, options: IPresetOptions = {}) => {
require.resolve(`@babel/runtime/package.json`)
)

// TODO(v3): Remove process.env.GATSBY_BUILD_STAGE, needs to be passed as an option
const stage = options.stage || process.env.GATSBY_BUILD_STAGE || `test`
const stage = options.stage || `test`
const pluginBabelConfig = loadCachedConfig()
const targets = pluginBabelConfig.browserslist

Expand Down
18 changes: 16 additions & 2 deletions packages/gatsby/src/schema/infer/add-inferred-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const report = require(`gatsby-cli/lib/reporter`)
import { isFile } from "./is-file"
import { isDate } from "../types/date"
import { addDerivedType } from "../types/derived-types"
import { warnOnce } from "../../utils/warn-once"
import { is32BitInteger } from "../../utils/is-32-bit-integer"
const { getDataStore } = require(`../../datastore`)

Expand All @@ -32,6 +33,14 @@ const addInferredFields = ({
typeMapping,
config,
})

if (deprecatedNodeKeys.size > 0) {
warnOnce(
`The ___NODE convention is deprecated. Please use the @link directive instead.\nType: ${typeComposer.getTypeName()}, Keys: ${Array.from(
deprecatedNodeKeys
).join(`, `)}\nMigration: https://gatsby.dev/node-convention-deprecation`
)
}
}

module.exports = {
Expand Down Expand Up @@ -98,6 +107,8 @@ const addInferredFieldsImpl = ({
return typeComposer
}

const deprecatedNodeKeys = new Set()

const getFieldConfig = ({
schemaComposer,
typeComposer,
Expand Down Expand Up @@ -125,12 +136,17 @@ const getFieldConfig = ({
// i.e. does the config contain sanitized field names?
fieldConfig = getFieldConfigFromMapping({ typeMapping, selector })
} else if (unsanitizedKey.includes(`___NODE`)) {
// TODO(v5): Remove ability to use foreign keys like this (e.g. author___NODE___contact___email)
// and recommend using schema customization instead

fieldConfig = getFieldConfigFromFieldNameConvention({
schemaComposer,
value: exampleValue,
key: unsanitizedKey,
})
arrays = arrays + (value.multiple ? 1 : 0)

deprecatedNodeKeys.add(unsanitizedKey)
} else {
fieldConfig = getSimpleFieldConfig({
schemaComposer,
Expand Down Expand Up @@ -214,8 +230,6 @@ const getFieldConfigFromFieldNameConvention = ({
const linkedTypesSet = new Set()

if (foreignKey) {
// TODO: deprecate foreign keys like this (e.g. author___NODE___contact___email)
// and recommend using schema customization instead
const linkedValues = new Set(value.linkedNodes)
getDataStore()
.iterateNodes()
Expand Down
2 changes: 0 additions & 2 deletions packages/gatsby/src/schema/types/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ export const getFilterInput = ({
)
const inputTypeComposer = typeComposer.getInputTypeComposer()

// TODO: In Gatsby v2, the NodeInput.id field is of type String, not ID.
// Remove this workaround for v3.
if (
inputTypeComposer?.hasField(`id`) &&
getNamedType(inputTypeComposer.getFieldType(`id`)).name === `ID`
Expand Down
3 changes: 1 addition & 2 deletions packages/gatsby/src/schema/types/node-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ const getOrCreateNodeInterface = <TSource, TArgs>(
},
internal: internalTC.getTypeNonNull(),
})
// TODO: In Gatsby v2, the NodeInput.id field is of type String, not ID.
// Remove this workaround for v3.

const nodeInputTC = tc.getInputTypeComposer()
nodeInputTC.extendField(`id`, { type: `String` })
})
Expand Down
1 change: 0 additions & 1 deletion packages/gatsby/src/utils/__tests__/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ describe(`environment variables`, () => {
[
`__PATH_PREFIX__`,
`process.env.BUILD_STAGE`,
`process.env.GATSBY_BUILD_STAGE`,
`process.env.NODE_ENV`,
`process.env.PUBLIC_DIR`,
].reduce((merged, key) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby/src/utils/warn-once.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import reporter from "gatsby-cli/lib/reporter"
import { isWorker } from "gatsby-worker"

const displayedWarnings = new Set<string>()

export const warnOnce = (message: string, key?: string): void => {
const messageId = key ?? message
if (!displayedWarnings.has(messageId)) {
if (!displayedWarnings.has(messageId) && !isWorker) {
displayedWarnings.add(messageId)
reporter.warn(message)
}
Expand Down
4 changes: 0 additions & 4 deletions packages/gatsby/src/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ module.exports = async (
const modulesThatUseGatsby = await getGatsbyDependents()
const directoryPath = withBasePath(directory)

// we will converge to build-html later on but for now this was the fastest way to get SSR to work
// TODO remove in v4 - we deprecated this in v3
process.env.GATSBY_BUILD_STAGE = suppliedStage

// We combine develop & develop-html stages for purposes of generating the
// webpack config.
const stage = suppliedStage
Expand Down