mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix: handle GraphQL errors in createPages (#66642)
This commit is contained in:
+20
-6
@@ -1,4 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */
|
||||
|
||||
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
|
||||
const webpack = require('webpack');
|
||||
|
||||
@@ -34,9 +35,7 @@ exports.createPages = async function createPages({
|
||||
|
||||
const { createPage } = actions;
|
||||
|
||||
const {
|
||||
data: { allSuperBlockStructure }
|
||||
} = await graphql(`
|
||||
const result = await graphql(`
|
||||
{
|
||||
allSuperBlockStructure {
|
||||
nodes {
|
||||
@@ -46,9 +45,18 @@ exports.createPages = async function createPages({
|
||||
}
|
||||
`);
|
||||
|
||||
if (result.errors) {
|
||||
reporter.panic('createPages GraphQL query failed', result.errors);
|
||||
}
|
||||
|
||||
const {
|
||||
data: { allSuperBlockStructure }
|
||||
} = result;
|
||||
|
||||
const superBlocks = allSuperBlockStructure.nodes.map(
|
||||
(node: { superBlock: string }) => node.superBlock
|
||||
);
|
||||
|
||||
superBlocks.forEach((superBlock: string) => {
|
||||
createSuperBlockIntroPages(createPage)({ superBlock });
|
||||
});
|
||||
@@ -64,14 +72,19 @@ exports.onCreateWebpackConfig = ({ stage, actions }: any) => {
|
||||
process: 'process/browser'
|
||||
})
|
||||
];
|
||||
|
||||
// The monaco editor relies on some browser only globals so should not be
|
||||
// involved in SSR. Also, if the plugin is used during the 'build-html' or
|
||||
// 'develop-html' stage it overwrites the minfied files with ordinary ones.
|
||||
|
||||
if (stage !== 'build-html' && stage !== 'develop-html') {
|
||||
newPlugins.push(
|
||||
new MonacoWebpackPlugin({ filename: '[name].worker-[contenthash].js' })
|
||||
new MonacoWebpackPlugin({
|
||||
filename: '[name].worker-[contenthash].js'
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
actions.setWebpackConfig({
|
||||
resolve: {
|
||||
fallback: {
|
||||
@@ -103,6 +116,7 @@ exports.onCreateBabelConfig = ({ actions }: any) => {
|
||||
actions.setBabelPlugin({
|
||||
name: '@babel/plugin-proposal-function-bind'
|
||||
});
|
||||
|
||||
actions.setBabelPlugin({
|
||||
name: '@babel/plugin-proposal-export-default-from'
|
||||
});
|
||||
@@ -110,6 +124,7 @@ exports.onCreateBabelConfig = ({ actions }: any) => {
|
||||
|
||||
exports.createSchemaCustomization = ({ actions }: any) => {
|
||||
const { createTypes } = actions;
|
||||
|
||||
// This hook is supported by the test runner, but is not currently used by the
|
||||
// client, so we have to tell Gatsby that it exists.
|
||||
const typeDefs = `
|
||||
@@ -117,7 +132,6 @@ exports.createSchemaCustomization = ({ actions }: any) => {
|
||||
afterEach: String
|
||||
}
|
||||
`;
|
||||
|
||||
createTypes(typeDefs);
|
||||
};
|
||||
|
||||
export {};
|
||||
|
||||
Reference in New Issue
Block a user