Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/spotty-bulldogs-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphiql/react': patch
'graphiql': patch
---

- prefer `location` over `window.location`
- prefer `navigator` over `window.navigator`
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ module.exports = {
property: 'localStorage',
message: 'Use `localStorage` instead',
},
{
object: 'window',
property: 'location',
message: 'Use `location` instead',
},
{
object: 'window',
property: 'navigator',
message: 'Use `navigator` instead',
},
],
'no-return-assign': 'error',
'no-return-await': 'error',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"scripts": {
"build": "yarn build-clean && yarn tsc && yarn build:nontsc",
"build-bundles": "yarn prebuild-bundles && yarn wsrun:noexamples --stages build-bundles",
"build-bundles-clean": "rimraf '{packages,examples,plugins}/**/{bundle,cdn,webpack}'",
"build-bundles-clean": "rimraf '{packages,examples}/**/{bundle,cdn,webpack}'",
"build-clean": "yarn tsc --clean",
"build-docs": "rimraf packages/graphiql/typedoc && typedoc packages",
"build:nontsc": "yarn wsrun:noexamples --exclude-missing --serial build",
Expand Down
12 changes: 5 additions & 7 deletions packages/graphiql-react/src/editor/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { KeyMap } from './types';
export const DEFAULT_EDITOR_THEME = 'graphiql';
export const DEFAULT_KEY_MAP: KeyMap = 'sublime';

let isMacOs = false;

if (typeof window === 'object') {
isMacOs = window.navigator.platform.toLowerCase().indexOf('mac') === 0;
}
const isMacOs =
typeof navigator !== 'undefined' &&
navigator.platform.toLowerCase().indexOf('mac') === 0;

export const commonKeys = {
// Persistent search box in Query Editor
Expand All @@ -30,10 +28,10 @@ export async function importCodeMirror(
addons: Promise<any>[],
options?: { useCommonAddons?: boolean },
) {
const CodeMirror = await import('codemirror').then(c =>
const CodeMirror = await import('codemirror').then(mod =>
// Depending on bundler and settings the dynamic import either returns a
// function (e.g. parcel) or an object containing a `default` property
typeof c === 'function' ? c : c.default,
typeof mod === 'function' ? mod : mod.default,
);
await Promise.all(
options?.useCommonAddons === false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ function tokenToURL(token: Token) {
const value = token.string.slice(1).slice(0, -1).trim();

try {
const { location } = window;
return new URL(value, location.protocol + '//' + location.host);
} catch {
return;
}
} catch {}
}

function isImageURL(url: URL) {
Expand Down
30 changes: 15 additions & 15 deletions packages/graphiql/resources/renderExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// Parse the search string to get url parameters.
const parameters = {};
for (const entry of window.location.search.slice(1).split('&')) {
for (const entry of location.search.slice(1).split('&')) {
const eq = entry.indexOf('=');
if (eq >= 0) {
parameters[decodeURIComponent(entry.slice(0, eq))] = decodeURIComponent(
Expand Down Expand Up @@ -60,22 +60,22 @@ function updateURL() {
}

function getSchemaUrl() {
const isDev = window.location.hostname.match(/localhost$/);
const isDev = /localhost$/.test(location.hostname);

if (isDev) {
// This supports an e2e test which ensures that invalid schemas do not load.
if (parameters.bad === 'true') {
return '/bad/graphql';
}
if (parameters['http-error'] === 'true') {
return '/http-error/graphql';
}
if (parameters['graphql-error'] === 'true') {
return '/graphql-error/graphql';
}
return '/graphql';
if (!isDev) {
return '/.netlify/functions/graphql';
}
return '/.netlify/functions/graphql';
// This supports an e2e test which ensures that invalid schemas do not load.
if (parameters.bad === 'true') {
return '/bad/graphql';
}
if (parameters['http-error'] === 'true') {
return '/http-error/graphql';
}
if (parameters['graphql-error'] === 'true') {
return '/graphql-error/graphql';
}
return '/graphql';
}

// Render <GraphiQL /> into the body.
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql/src/components/GraphiQL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,8 @@ export function GraphiQLInterface(props: GraphiQLInterfaceProps) {
}

const modifier =
typeof window !== 'undefined' &&
window.navigator.platform.toLowerCase().indexOf('mac') === 0
typeof navigator !== 'undefined' &&
navigator.platform.toLowerCase().indexOf('mac') === 0
? 'Cmd'
: 'Ctrl';

Expand Down
22 changes: 5 additions & 17 deletions packages/graphiql/test/images/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.