Skip to content

Commit

Permalink
Throw error when run jss start using FETCH_WITH=GraphQL (#920)
Browse files Browse the repository at this point in the history
* added error for running disconnected mode with graphql

* added constant for fetchWith, added cross-env-shell to bootstrap script in package.json

* updated tsconfig
  • Loading branch information
addy-pathania authored Feb 4, 2022
1 parent a287cd6 commit 15f004e
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"build:client": "cross-env-shell ng build --prod --deploy-url $npm_package_config_sitecoreDistPath/browser/ --output-path=$npm_package_config_buildArtifactsPath/browser/",
"build:server": "cross-env-shell ng run <%- appName %>:server:production --output-path=$npm_package_config_buildArtifactsPath/server --output-hashing=none --bundle-dependencies true",
"postbuild:server": "move-cli ./dist/server/main.js ./dist/server.bundle.js && del-cli ./dist/server",
"bootstrap": "ts-node --project src/tsconfig.webpack-server.json scripts/bootstrap.ts",
"bootstrap": "cross-env-shell FETCH_WITH=<%- fetchWith %> \"ts-node --project src/tsconfig.webpack-server.json scripts/bootstrap.ts\"",
"graphql:update": "ts-node --project src/tsconfig.webpack-server.json ./scripts/update-graphql-fragment-data.ts"
},
"private": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const projects = require('../angular.json').projects;

const disconnected = process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED;

if (disconnected && process.env.FETCH_WITH === constants.FETCH_WITH.GRAPHQL) {
throw new Error("GraphQL requests to Dictionary and Layout service are not supported in disconnected mode.")
}

/*
CONFIG GENERATION
Generates the /src/environments/environment.ts file which contains runtime configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const disconnected = process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED;
const port = process.env.PORT || 3000;
const configOverride: { [key: string]: string } = {};
if (disconnected) {
if (process.env.FETCH_WITH === constants.FETCH_WITH.GRAPHQL) {
throw new Error('GraphQL requests to Dictionary and Layout service are not supported in disconnected mode.')
}
configOverride.sitecoreApiHost = `http://localhost:${port}`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"build:client": "cross-env-shell PUBLIC_URL=$npm_package_config_sitecoreDistPath \"react-scripts build\"",
"build:client:rendering-host": "cross-env-shell PUBLIC_URL=$npm_package_config_tunnelUrl \"react-scripts build\"",
"build:server": "cross-env-shell NODE_ENV=production \"webpack --config server/server.webpack.config.js\"",
"bootstrap": "node scripts/bootstrap.js",
"bootstrap": "cross-env-shell FETCH_WITH=<%- fetchWith %> \"node scripts/bootstrap.js\"",
"graphql:update": "node -r @babel/register ./scripts/update-graphql-fragment-data.js",
"test": "react-scripts test --env=jsdom",
"lint": "eslint ./src/**/*.js ./sitecore/definitions/**/*.js ./scripts/**/*.js ./server/**/*.js ./data/**/*.yml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const configGenerator = require('./generate-config');

const disconnected = process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED;

if (disconnected && process.env.FETCH_WITH === constants.FETCH_WITH.GRAPHQL) {
throw new Error("GraphQL requests to Dictionary and Layout service are not supported in disconnected mode.")
}

/*
CONFIG GENERATION
Generates the /src/temp/config.js file which contains runtime configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"start:watch-components": "node scripts/generate-component-factory.js --watch",
"build:client": "cross-env-shell BUILD_TARGET_ENV=client PUBLIC_URL=$npm_package_config_sitecoreDistPath \"vue-cli-service build\"",
"build:server": "cross-env-shell BUILD_TARGET_ENV=server \"vue-cli-service build --no-clean\"",
"bootstrap": "node scripts/bootstrap.js",
"bootstrap": "cross-env-shell FETCH_WITH=<%- fetchWith %> \"node scripts/bootstrap.js\"",
"graphql:update": "cross-env-shell VUE_CLI_BABEL_TRANSPILE_MODULES=true VUE_CLI_BABEL_TARGET_NODE=true \"node -r @babel/register ./scripts/update-graphql-fragment-data.js\"",
"lint": "vue-cli-service lint ./src/**/*.vue ./src/**/*.js ./sitecore/definitions/**/*.js ./scripts/**/*.js ./server/**/*.js ./data/**/*.yml"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const vueConfig = require('../vue.config');

const disconnected = process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED;

if (disconnected && process.env.FETCH_WITH === constants.FETCH_WITH.GRAPHQL) {
throw new Error("GraphQL requests to Dictionary and Layout service are not supported in disconnected mode.")
}

/*
CONFIG GENERATION
Generates the /src/temp/config.js file which contains runtime configuration
Expand Down
5 changes: 5 additions & 0 deletions packages/sitecore-jss/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export enum SitecoreTemplateId {
DictionaryEntry = '6d1cd89719364a3aa511289a94c2a7b1',
}

export const FETCH_WITH = {
GRAPHQL: 'GraphQL',
REST: 'Rest',
};

export const JSS_MODE = {
CONNECTED: 'connected',
DISCONNECTED: 'disconnected',
Expand Down

0 comments on commit 15f004e

Please sign in to comment.