From 467600f2c5f1ff1389cce9888de4241be08e016d Mon Sep 17 00:00:00 2001 From: Coby Sher <63015754+CobyPear@users.noreply.github.com> Date: Wed, 8 Sep 2021 13:24:16 -0500 Subject: [PATCH 1/3] Fix update-graphql-fragment-data react sample --- samples/react/package.json | 2 +- samples/react/scripts/update-graphql-fragment-data.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/react/package.json b/samples/react/package.json index 46ece09ce3..07beda8ed9 100644 --- a/samples/react/package.json +++ b/samples/react/package.json @@ -108,7 +108,7 @@ "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", - "graphql:update": "node -r babel-register ./scripts/update-graphql-fragment-data.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", "eject": "react-scripts eject", diff --git a/samples/react/scripts/update-graphql-fragment-data.js b/samples/react/scripts/update-graphql-fragment-data.js index 46a9b36c85..8f45194252 100644 --- a/samples/react/scripts/update-graphql-fragment-data.js +++ b/samples/react/scripts/update-graphql-fragment-data.js @@ -1,8 +1,8 @@ /* eslint-disable no-console, no-underscore-dangle */ -import fetch from 'cross-fetch'; -import fs from 'fs'; -import generateConfig from './generate-config'; +const fetch = require('cross-fetch'); +const fs = require('fs'); +const generateConfig = require('./generate-config'); // Apollo Client supports caching GraphQL responses, which can greatly reduce network traffic needs. // In order to work correctly with interfaces in GraphQL, it needs to know some basic information about @@ -17,7 +17,7 @@ let jssConfig; try { // eslint-disable-next-line global-require - jssConfig = require('../src/temp/config').default; + jssConfig = require('../src/temp/config'); } catch (e) { console.error( 'Unable to require JSS config. Ensure `jss setup` has been run, and the app has been started at least once after setup.' @@ -30,7 +30,7 @@ console.log(`Updating GraphQL fragment type data from ${jssConfig.graphQLEndpoin fetch(jssConfig.graphQLEndpoint, { method: 'POST', - headers: { 'Content-Type': 'application/json' }, + headers: { 'Content-Type': 'application/json', sc_apikey: jssConfig.sitecoreApiKey }, body: JSON.stringify({ query: ` { From db55035022f391ef4eb49cd3ac071b394f8d6c83 Mon Sep 17 00:00:00 2001 From: Coby Sher <63015754+CobyPear@users.noreply.github.com> Date: Wed, 8 Sep 2021 14:16:08 -0500 Subject: [PATCH 2/3] Fix vue graphql:update --- samples/vue/scripts/update-graphql-fragment-data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/vue/scripts/update-graphql-fragment-data.js b/samples/vue/scripts/update-graphql-fragment-data.js index 46a9b36c85..51c702018e 100644 --- a/samples/vue/scripts/update-graphql-fragment-data.js +++ b/samples/vue/scripts/update-graphql-fragment-data.js @@ -30,7 +30,7 @@ console.log(`Updating GraphQL fragment type data from ${jssConfig.graphQLEndpoin fetch(jssConfig.graphQLEndpoint, { method: 'POST', - headers: { 'Content-Type': 'application/json' }, + headers: { 'Content-Type': 'application/json', sc_apikey: jssConfig.sitecoreApiKey }, body: JSON.stringify({ query: ` { From e666f9f818d0f0ee62671c77483e6a7a1d24fcf4 Mon Sep 17 00:00:00 2001 From: Coby Sher <63015754+CobyPear@users.noreply.github.com> Date: Wed, 8 Sep 2021 15:58:45 -0500 Subject: [PATCH 3/3] Fix angular graphql:update --- samples/angular/package-lock.json | 6 ++++++ samples/angular/package.json | 1 + samples/angular/scripts/update-graphql-fragment-data.ts | 6 +++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/samples/angular/package-lock.json b/samples/angular/package-lock.json index e92549d649..908aa0def2 100644 --- a/samples/angular/package-lock.json +++ b/samples/angular/package-lock.json @@ -4560,6 +4560,12 @@ "@types/node": "*" } }, + "@types/isomorphic-fetch": { + "version": "0.0.35", + "resolved": "https://registry.npmjs.org/@types/isomorphic-fetch/-/isomorphic-fetch-0.0.35.tgz", + "integrity": "sha512-DaZNUvLDCAnCTjgwxgiL1eQdxIKEpNLOlTNtAgnZc50bG2copGhRrFN9/PxPBuJe+tZVLCbQ7ls0xveXVRPkvw==", + "dev": true + }, "@types/jasmine": { "version": "3.6.7", "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-3.6.7.tgz", diff --git a/samples/angular/package.json b/samples/angular/package.json index 2758d844aa..28ea4416cd 100644 --- a/samples/angular/package.json +++ b/samples/angular/package.json @@ -93,6 +93,7 @@ "@sitecore-jss/sitecore-jss-cli": "^19.0.0-canary.56", "@sitecore-jss/sitecore-jss-dev-tools": "^19.0.0-canary.56", "@sitecore-jss/sitecore-jss-manifest": "^19.0.0-canary.56", + "@types/isomorphic-fetch": "0.0.35", "@types/jasmine": "~3.6.7", "@types/jasminewd2": "~2.0.8", "@types/node": "~12.7.9", diff --git a/samples/angular/scripts/update-graphql-fragment-data.ts b/samples/angular/scripts/update-graphql-fragment-data.ts index f965304f30..99da18259e 100644 --- a/samples/angular/scripts/update-graphql-fragment-data.ts +++ b/samples/angular/scripts/update-graphql-fragment-data.ts @@ -27,7 +27,7 @@ console.log(`Updating GraphQL fragment type data from ${jssConfig.graphQLEndpoin fetch(jssConfig.graphQLEndpoint, { method: 'POST', - headers: { 'Content-Type': 'application/json' }, + headers: { 'Content-Type': 'application/json', sc_apikey: jssConfig.sitecoreApiKey }, body: JSON.stringify({ query: ` { @@ -44,10 +44,10 @@ fetch(jssConfig.graphQLEndpoint, { `, }), }) - .then((result: unknown) => result.json()) + .then((result) => result.json()) .then((result) => { // here we're filtering out any type information unrelated to unions or interfaces - const filteredData = result.data.__schema.types.filter((type) => type.possibleTypes !== null); + const filteredData = result.data.__schema.types.filter((type: { possibleTypes: Array; }) => type.possibleTypes !== null); const filteredResult = { ...result }; filteredResult.data.__schema.types = filteredData;