Socket
Socket
Sign inDemoInstall

@graphiql/toolkit

Package Overview
Dependencies
Maintainers
5
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphiql/toolkit - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

src/graphql-helpers/__tests__/__queries__/mergedQuery.graphql

6

CHANGELOG.md
# @graphiql/toolkit
## 0.9.1
### Patch Changes
- [#3298](https://github.com/graphql/graphiql/pull/3298) [`4cbdf183`](https://github.com/graphql/graphiql/commit/4cbdf18385d34ef9bc095c376936f92a62eb9e9b) Thanks [@esquevin](https://github.com/esquevin)! - Prevent OOM on merging complex queries
## 0.9.0

@@ -4,0 +10,0 @@

14

dist/graphql-helpers/merge-ast.js

@@ -163,3 +163,3 @@ "use strict";

}
var visitors = {
var flattenVisitors = {
SelectionSet: function (node) {

@@ -169,2 +169,12 @@ var selectionSetType = typeInfo ? typeInfo.getParentType() : null;

selections = inlineRelevantFragmentSpreads(fragmentDefinitions, selections, selectionSetType);
return __assign(__assign({}, node), { selections: selections });
},
FragmentDefinition: function () {
return null;
},
};
var flattenedAST = (0, graphql_1.visit)(documentAST, typeInfo ? (0, graphql_1.visitWithTypeInfo)(typeInfo, flattenVisitors) : flattenVisitors);
var deduplicateVisitors = {
SelectionSet: function (node) {
var selections = node.selections;
selections = uniqueBy(selections, function (selection) {

@@ -179,5 +189,5 @@ return selection.alias ? selection.alias.value : selection.name.value;

};
return (0, graphql_1.visit)(documentAST, typeInfo ? (0, graphql_1.visitWithTypeInfo)(typeInfo, visitors) : visitors);
return (0, graphql_1.visit)(flattenedAST, deduplicateVisitors);
}
exports.mergeAst = mergeAst;
//# sourceMappingURL=merge-ast.js.map

@@ -83,3 +83,3 @@ import { TypeInfo, getNamedType, visit, visitWithTypeInfo, Kind, } from 'graphql';

}
const visitors = {
const flattenVisitors = {
SelectionSet(node) {

@@ -89,2 +89,12 @@ const selectionSetType = typeInfo ? typeInfo.getParentType() : null;

selections = inlineRelevantFragmentSpreads(fragmentDefinitions, selections, selectionSetType);
return Object.assign(Object.assign({}, node), { selections });
},
FragmentDefinition() {
return null;
},
};
const flattenedAST = visit(documentAST, typeInfo ? visitWithTypeInfo(typeInfo, flattenVisitors) : flattenVisitors);
const deduplicateVisitors = {
SelectionSet(node) {
let { selections } = node;
selections = uniqueBy(selections, selection => selection.alias ? selection.alias.value : selection.name.value);

@@ -97,4 +107,4 @@ return Object.assign(Object.assign({}, node), { selections });

};
return visit(documentAST, typeInfo ? visitWithTypeInfo(typeInfo, visitors) : visitors);
return visit(flattenedAST, deduplicateVisitors);
}
//# sourceMappingURL=merge-ast.js.map

2

package.json
{
"name": "@graphiql/toolkit",
"version": "0.9.0",
"version": "0.9.1",
"description": "Utility to build a fetcher for GraphiQL",

@@ -5,0 +5,0 @@ "contributors": [

@@ -5,2 +5,3 @@ import {

GraphQLSchema,
buildSchema,
parse,

@@ -11,3 +12,4 @@ print,

import { mergeAst } from '../merge-ast';
import fs from 'node:fs';
import path from 'node:path';
const schema = new GraphQLSchema({

@@ -172,2 +174,35 @@ query: new GraphQLObjectType({

});
it('handles very complex query without crashing', async () => {
// graphQLVersion = pkg.version;
const schemaIDL = fs.readFileSync(
path.join(__dirname, '__schema__/sorareSchema.graphql'),
'utf8',
);
const sorareSchema = buildSchema(schemaIDL);
// graphQLVersion = pkg.version;
const query = fs.readFileSync(
path.join(__dirname, '__queries__/testQuery.graphql'),
'utf8',
);
// graphQLVersion = pkg.version;
const mergedQuery = stripWhitespace(
fs.readFileSync(
path.join(__dirname, '__queries__/mergedQuery.graphql'),
'utf8',
),
);
// graphQLVersion = pkg.version;
const mergedQueryWithSchema = stripWhitespace(
fs.readFileSync(
path.join(__dirname, '__queries__/mergedQueryWithSchema.graphql'),
'utf8',
),
);
expect(removeParametersCommas(parseMergeAndPrint(query))).toBe(mergedQuery);
expect(parseMergeAndPrint(query, sorareSchema)).toBe(mergedQueryWithSchema);
});
});

@@ -182,1 +217,5 @@

}
function removeParametersCommas(str: string) {
return str.replaceAll(',', '');
}

@@ -127,3 +127,3 @@ import {

const visitors: ASTVisitor = {
const flattenVisitors: ASTVisitor = {
SelectionSet(node: any) {

@@ -139,2 +139,21 @@ const selectionSetType = typeInfo ? typeInfo.getParentType() : null;

return {
...node,
selections,
};
},
FragmentDefinition() {
return null;
},
};
const flattenedAST = visit(
documentAST,
typeInfo ? visitWithTypeInfo(typeInfo, flattenVisitors) : flattenVisitors,
);
const deduplicateVisitors: ASTVisitor = {
SelectionSet(node: any) {
let { selections } = node;
selections = uniqueBy(selections, selection =>

@@ -154,6 +173,3 @@ selection.alias ? selection.alias.value : selection.name.value,

return visit(
documentAST,
typeInfo ? visitWithTypeInfo(typeInfo, visitors) : visitors,
);
return visit(flattenedAST, deduplicateVisitors);
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc