Skip to content

Commit

Permalink
[RAV][Regression] jss graphql:update throws errors (#806)
Browse files Browse the repository at this point in the history
* Fix update-graphql-fragment-data react sample

* Fix vue graphql:update

* Fix angular graphql:update

Co-authored-by: Adam Brauer <[email protected]>
  • Loading branch information
CobyPear and ambrauer authored Sep 8, 2021
1 parent eb2b922 commit 83e63e0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
6 changes: 6 additions & 0 deletions samples/angular/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions samples/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"@sitecore-jss/sitecore-jss-cli": "^19.0.0-canary.57",
"@sitecore-jss/sitecore-jss-dev-tools": "^19.0.0-canary.57",
"@sitecore-jss/sitecore-jss-manifest": "^19.0.0-canary.57",
"@types/isomorphic-fetch": "0.0.35",
"@types/jasmine": "~3.6.7",
"@types/jasminewd2": "~2.0.8",
"@types/node": "~12.7.9",
Expand Down
6 changes: 3 additions & 3 deletions samples/angular/scripts/update-graphql-fragment-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
{
Expand All @@ -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<string>; }) => type.possibleTypes !== null);

const filteredResult = { ...result };
filteredResult.data.__schema.types = filteredData;
Expand Down
2 changes: 1 addition & 1 deletion samples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions samples/react/scripts/update-graphql-fragment-data.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.'
Expand All @@ -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: `
{
Expand Down
2 changes: 1 addition & 1 deletion samples/vue/scripts/update-graphql-fragment-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
{
Expand Down

0 comments on commit 83e63e0

Please sign in to comment.