diff --git a/package-lock.json b/package-lock.json index 00364e7746f..152fd9f7852 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7866,6 +7866,14 @@ "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" }, + "json-stable-stringify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz", + "integrity": "sha1-mnWdOcXy/1A/1TAGRu1EX4jE+a8=", + "requires": { + "jsonify": "~0.0.0" + } + }, "json-stable-stringify-without-jsonify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", @@ -7895,6 +7903,11 @@ "graceful-fs": "^4.1.6" } }, + "jsonify": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", + "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=" + }, "jsonwebtoken": { "version": "8.5.1", "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz", diff --git a/package.json b/package.json index ed690875e57..4b1a85b51fd 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "graphql-tag": "2.12.5", "graphql-upload": "11.0.0", "intersect": "1.0.1", + "json-stable-stringify": "1.0.1", "jsonwebtoken": "8.5.1", "jwks-rsa": "1.12.3", "ldapjs": "2.3.1", diff --git a/src/GraphQL/ParseGraphQLSchema.js b/src/GraphQL/ParseGraphQLSchema.js index 2babb84b0db..efd4af786b4 100644 --- a/src/GraphQL/ParseGraphQLSchema.js +++ b/src/GraphQL/ParseGraphQLSchema.js @@ -1,6 +1,7 @@ import Parse from 'parse/node'; import { GraphQLSchema, GraphQLObjectType, DocumentNode, GraphQLNamedType } from 'graphql'; import { stitchSchemas } from '@graphql-tools/stitch'; +import stableStringify from 'json-stable-stringify'; import { SchemaDirectiveVisitor } from '@graphql-tools/utils'; import requiredParameter from '../requiredParameter'; import * as defaultGraphQLTypes from './loaders/defaultGraphQLTypes'; @@ -93,15 +94,12 @@ class ParseGraphQLSchema { async load() { const { parseGraphQLConfig } = await this._initializeSchemaAndConfig(); const parseClasses = await this._getClassesForSchema(parseGraphQLConfig); - const parseClassesString = JSON.stringify(parseClasses); const functionNames = await this._getFunctionNames(); const functionNamesString = JSON.stringify(functionNames); if ( - this.graphQLSchema && !this._hasSchemaInputChanged({ parseClasses, - parseClassesString, parseGraphQLConfig, functionNamesString, }) @@ -110,7 +108,6 @@ class ParseGraphQLSchema { } this.parseClasses = parseClasses; - this.parseClassesString = parseClassesString; this.parseGraphQLConfig = parseGraphQLConfig; this.functionNames = functionNames; this.functionNamesString = functionNamesString; @@ -497,26 +494,35 @@ class ParseGraphQLSchema { */ _hasSchemaInputChanged(params: { parseClasses: any, - parseClassesString: string, parseGraphQLConfig: ?ParseGraphQLConfig, functionNamesString: string, }): boolean { - const { parseClasses, parseClassesString, parseGraphQLConfig, functionNamesString } = params; + const { parseClasses, parseGraphQLConfig, functionNamesString } = params; + + // First init + if (!this.parseClassesString || !this.graphQLSchema) { + const thisParseClassesObj = parseClasses.reduce((acc, clzz) => { + acc[clzz.className] = clzz; + return acc; + }, {}); + this.parseClassesString = stableStringify(thisParseClassesObj); + return true; + } + const parseClassesObj = parseClasses.reduce((acc, clzz) => { + acc[clzz.className] = clzz; + return acc; + }, {}); + const newParseClassesString = stableStringify(parseClassesObj); if ( JSON.stringify(this.parseGraphQLConfig) === JSON.stringify(parseGraphQLConfig) && - this.functionNamesString === functionNamesString + this.functionNamesString === functionNamesString && + this.parseClassesString === newParseClassesString ) { - if (this.parseClasses === parseClasses) { - return false; - } - - if (this.parseClassesString === parseClassesString) { - this.parseClasses = parseClasses; - return false; - } + return false; } + this.parseClassesString = newParseClassesString; return true; } }