Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: graphql/graphql-js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v15.5.0
Choose a base ref
...
head repository: graphql/graphql-js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v15.5.1
Choose a head ref
  • 3 commits
  • 9 files changed
  • 2 contributors

Commits on Jun 20, 2021

  1. Backport instanceOf Error Check Improvements (#3186)

    Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
    tubbo and IvanGoncharov authored Jun 20, 2021

    Partially verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
    Copy the full SHA
    b5dfb4c View commit details
  2. Remove deprecated rmdirSync usage from internal scripts (#3191)

    Backport of #2972 to 15.x.x branch
    IvanGoncharov authored Jun 20, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    38c2d57 View commit details
  3. 15.5.1

    IvanGoncharov committed Jun 20, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    IvanGoncharov Ivan Goncharov
    Copy the full SHA
    d2d8458 View commit details
Showing with 88 additions and 21 deletions.
  1. +4 −5 benchmark/benchmark.js
  2. +1 −1 integrationTests/integration-test.js
  3. +2 −2 package-lock.json
  4. +1 −1 package.json
  5. +1 −1 resources/build-deno.js
  6. +1 −1 resources/build-npm.js
  7. +64 −3 src/jsutils/__tests__/instanceOf-test.js
  8. +12 −5 src/jsutils/instanceOf.js
  9. +2 −2 src/version.js
9 changes: 4 additions & 5 deletions benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -31,17 +31,16 @@ function exec(command, options = {}) {
// and returns path to its 'dist' directory.
function prepareBenchmarkProjects(revisionList) {
const tmpDir = path.join(os.tmpdir(), 'graphql-js-benchmark');
fs.rmdirSync(tmpDir, { recursive: true, force: true });
fs.rmSync(tmpDir, { recursive: true, force: true });
fs.mkdirSync(tmpDir);

const setupDir = path.join(tmpDir, 'setup');
fs.rmdirSync(setupDir, { recursive: true, force: true });
fs.mkdirSync(setupDir);

return revisionList.map((revision) => {
console.log(`🍳 Preparing ${revision}...`);
const projectPath = path.join(setupDir, revision);
fs.rmdirSync(projectPath, { recursive: true });
fs.rmSync(projectPath, { recursive: true, force: true });
fs.mkdirSync(projectPath);

fs.writeFileSync(
@@ -73,12 +72,12 @@ function prepareBenchmarkProjects(revisionList) {
}

const repoDir = path.join(tmpDir, hash);
fs.rmdirSync(repoDir, { recursive: true, force: true });
fs.rmSync(repoDir, { recursive: true, force: true });
fs.mkdirSync(repoDir);
exec(`git archive "${hash}" | tar -xC "${repoDir}"`);
exec('npm --quiet ci', { cwd: repoDir });
fs.renameSync(buildNPMArchive(repoDir), archivePath);
fs.rmdirSync(repoDir, { recursive: true, force: true });
fs.rmSync(repoDir, { recursive: true });
return archivePath;
}

2 changes: 1 addition & 1 deletion integrationTests/integration-test.js
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ function exec(command, options = {}) {

describe('Integration Tests', () => {
const tmpDir = path.join(os.tmpdir(), 'graphql-js-integrationTmp');
fs.rmdirSync(tmpDir, { recursive: true, force: true });
fs.rmSync(tmpDir, { recursive: true, force: true });
fs.mkdirSync(tmpDir);

const distDir = path.resolve('./npmDist');
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql",
"version": "15.5.0",
"version": "15.5.1",
"description": "A Query Language and Runtime which can target any service.",
"license": "MIT",
"private": true,
2 changes: 1 addition & 1 deletion resources/build-deno.js
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ const babel = require('@babel/core');
const { readdirRecursive, showDirStats } = require('./utils');

if (require.main === module) {
fs.rmdirSync('./denoDist', { recursive: true, force: true });
fs.rmSync('./denoDist', { recursive: true, force: true });
fs.mkdirSync('./denoDist');

const srcFiles = readdirRecursive('./src', { ignoreDir: /^__.*__$/ });
2 changes: 1 addition & 1 deletion resources/build-npm.js
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ const babel = require('@babel/core');
const { readdirRecursive, showDirStats } = require('./utils');

if (require.main === module) {
fs.rmdirSync('./npmDist', { recursive: true, force: true });
fs.rmSync('./npmDist', { recursive: true, force: true });
fs.mkdirSync('./npmDist');

const srcFiles = readdirRecursive('./src', { ignoreDir: /^__.*__$/ });
67 changes: 64 additions & 3 deletions src/jsutils/__tests__/instanceOf-test.js
Original file line number Diff line number Diff line change
@@ -4,19 +4,80 @@ import { describe, it } from 'mocha';
import instanceOf from '../instanceOf';

describe('instanceOf', () => {
it('do not throw on values without prototype', () => {
class Foo {
// $FlowFixMe[unsupported-syntax]
get [Symbol.toStringTag]() {
return 'Foo';
}
}

expect(instanceOf(true, Foo)).to.equal(false);
expect(instanceOf(null, Foo)).to.equal(false);
expect(instanceOf(Object.create(null), Foo)).to.equal(false);
});

it('detect name clashes with older versions of this lib', () => {
function oldVersion() {
class Foo {}
return Foo;
}

function newVersion() {
class Foo {
// $FlowFixMe[unsupported-syntax]
get [Symbol.toStringTag]() {
return 'Foo';
}
}
return Foo;
}

const NewClass = newVersion();
const OldClass = oldVersion();
expect(instanceOf(new NewClass(), NewClass)).to.equal(true);
expect(() => instanceOf(new OldClass(), NewClass)).to.throw();
});

it('allows instances to have share the same constructor name', () => {
function getMinifiedClass(tag: string) {
class SomeNameAfterMinification {
// $FlowFixMe[unsupported-syntax]
get [Symbol.toStringTag]() {
return tag;
}
}
return SomeNameAfterMinification;
}

const Foo = getMinifiedClass('Foo');
const Bar = getMinifiedClass('Bar');
expect(instanceOf(new Foo(), Bar)).to.equal(false);
expect(instanceOf(new Bar(), Foo)).to.equal(false);

const DuplicateOfFoo = getMinifiedClass('Foo');
expect(() => instanceOf(new DuplicateOfFoo(), Foo)).to.throw();
expect(() => instanceOf(new Foo(), DuplicateOfFoo)).to.throw();
});

it('fails with descriptive error message', () => {
function getFoo() {
class Foo {}
class Foo {
// $FlowFixMe[unsupported-syntax]
get [Symbol.toStringTag]() {
return 'Foo';
}
}
return Foo;
}
const Foo1 = getFoo();
const Foo2 = getFoo();

expect(() => instanceOf(new Foo1(), Foo2)).to.throw(
/^Cannot use Foo "\[object Object\]" from another module or realm./m,
/^Cannot use Foo "{}" from another module or realm./m,
);
expect(() => instanceOf(new Foo2(), Foo1)).to.throw(
/^Cannot use Foo "\[object Object\]" from another module or realm./m,
/^Cannot use Foo "{}" from another module or realm./m,
);
});
});
17 changes: 12 additions & 5 deletions src/jsutils/instanceOf.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import inspect from './inspect';

/**
* A replacement for instanceof which includes an error warning when multi-realm
* constructors are detected.
@@ -20,12 +22,17 @@ export default process.env.NODE_ENV === 'production'
if (value instanceof constructor) {
return true;
}
if (value) {
const valueClass = value.constructor;
const className = constructor.name;
if (className && valueClass && valueClass.name === className) {
if (typeof value === 'object' && value !== null) {
const className = constructor.prototype[Symbol.toStringTag];
const valueClassName =
// We still need to support constructor's name to detect conflicts with older versions of this library.
Symbol.toStringTag in value
? value[Symbol.toStringTag]
: value.constructor?.name;
if (className === valueClassName) {
const stringifiedValue = inspect(value);
throw new Error(
`Cannot use ${className} "${value}" from another module or realm.
`Cannot use ${className} "${stringifiedValue}" from another module or realm.
Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
4 changes: 2 additions & 2 deletions src/version.js
Original file line number Diff line number Diff line change
@@ -6,14 +6,14 @@
/**
* A string containing the version of the GraphQL.js library
*/
export const version = '15.5.0';
export const version = '15.5.1';

/**
* An object containing the components of the GraphQL.js version string
*/
export const versionInfo = Object.freeze({
major: 15,
minor: 5,
patch: 0,
patch: 1,
preReleaseTag: null,
});