Socket
Socket
Sign inDemoInstall

@graphql-tools/import

Package Overview
Dependencies
Maintainers
3
Versions
849
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-tools/import - npm Package Compare versions

Comparing version 5.0.1-alpha-f709763.0 to 6.0.0-alpha.1

100

index.cjs.js

@@ -47,5 +47,2 @@ 'use strict';

if (!visitedFiles.has(filePath)) {
const fileDefinitionMap = new Map();
// To prevent circular dependency
visitedFiles.set(filePath, fileDefinitionMap);
const fileContent = filePath in predefinedImports ? predefinedImports[filePath] : fsExtra.readFileSync(filePath, 'utf8');

@@ -66,2 +63,5 @@ const importLines = [];

if (otherLines) {
const fileDefinitionMap = new Map();
// To prevent circular dependency
visitedFiles.set(filePath, fileDefinitionMap);
const document = graphql.parse(new graphql.Source(otherLines, filePath));

@@ -151,4 +151,20 @@ for (const definition of document.definitions) {

}
for (const [definitionName, definitions] of definitionsByName) {
if (!fileDefinitionMap.has(definitionName)) {
fileDefinitionMap.set(definitionName, new Set());
}
const definitionsWithDependencies = fileDefinitionMap.get(definitionName);
for (const definition of definitions) {
definitionsWithDependencies.add(definition);
}
const dependenciesOfDefinition = dependenciesByDefinitionName.get(definitionName);
for (const dependencyName of dependenciesOfDefinition) {
const dependencyDefinitions = definitionsByName.get(dependencyName);
dependencyDefinitions === null || dependencyDefinitions === void 0 ? void 0 : dependencyDefinitions.forEach(dependencyDefinition => {
definitionsWithDependencies.add(dependencyDefinition);
});
}
}
}
const importedDefinitionsMap = new Map();
const allImportedDefinitionsMap = new Map();
for (const line of importLines) {

@@ -159,11 +175,10 @@ const { imports, from } = parseImportLine(line.replace('#', '').trim());

for (const [importedDefinitionName, importedDefinitions] of importFileDefinitionMap) {
// Don't need to add field specific definitions
if (!importedDefinitionName.includes('.')) {
if (!importedDefinitionsMap.has(importedDefinitionName)) {
importedDefinitionsMap.set(importedDefinitionName, new Set());
}
for (const importedDefinition of importedDefinitions) {
importedDefinitionsMap.get(importedDefinitionName).add(importedDefinition);
}
const [importedDefinitionTypeName] = importedDefinitionName.split('.');
if (!allImportedDefinitionsMap.has(importedDefinitionTypeName)) {
allImportedDefinitionsMap.set(importedDefinitionTypeName, new Set());
}
const allImportedDefinitions = allImportedDefinitionsMap.get(importedDefinitionTypeName);
for (const importedDefinition of importedDefinitions) {
allImportedDefinitions.add(importedDefinition);
}
}

@@ -177,11 +192,13 @@ }

}
const importDefinitions = importFileDefinitionMap.get(importedDefinitionName);
if (!definitionsByName.has(importedDefinitionName)) {
definitionsByName.set(importedDefinitionName, new Set());
const [importedDefinitionTypeName] = importedDefinitionName.split('.');
if (!allImportedDefinitionsMap.has(importedDefinitionTypeName)) {
allImportedDefinitionsMap.set(importedDefinitionTypeName, new Set());
}
for (const importDefinition of importDefinitions) {
definitionsByName.get(importedDefinitionName).add(importDefinition);
const allImportedDefinitions = allImportedDefinitionsMap.get(importedDefinitionTypeName);
const importedDefinitions = importFileDefinitionMap.get(importedDefinitionName);
if (!importedDefinitions) {
throw new Error(`${importedDefinitionName} is not exported by ${from} imported by ${filePath}`);
}
if (!dependenciesByDefinitionName.has(importedDefinitionName)) {
dependenciesByDefinitionName.set(importedDefinitionName, new Set());
for (const importedDefinition of importedDefinitions) {
allImportedDefinitions.add(importedDefinition);
}

@@ -191,23 +208,42 @@ }

}
for (const [definitionName, definitions] of definitionsByName) {
if (!fileDefinitionMap.has(definitionName)) {
const definitionsWithDependencies = new Set();
for (const definition of definitions) {
if (!otherLines) {
visitedFiles.set(filePath, allImportedDefinitionsMap);
}
else {
const fileDefinitionMap = visitedFiles.get(filePath);
for (const [definitionName] of definitionsByName) {
const addDefinition = (definition) => {
definitionsWithDependencies.add(definition);
}
// Regenerate field exports if some fields are imported after visitor
if ('fields' in definition) {
for (const field of definition.fields) {
const fieldName = field.name.value;
const fieldDefinitionName = definition.name.value + '.' + fieldName;
const allImportedDefinitions = allImportedDefinitionsMap.get(definitionName);
allImportedDefinitions === null || allImportedDefinitions === void 0 ? void 0 : allImportedDefinitions.forEach(importedDefinition => {
if (!fileDefinitionMap.has(fieldDefinitionName)) {
fileDefinitionMap.set(fieldDefinitionName, new Set());
}
const definitionsWithDeps = fileDefinitionMap.get(fieldDefinitionName);
definitionsWithDeps.add(importedDefinition);
});
}
}
};
const definitionsWithDependencies = fileDefinitionMap.get(definitionName);
const allImportedDefinitions = allImportedDefinitionsMap.get(definitionName);
allImportedDefinitions === null || allImportedDefinitions === void 0 ? void 0 : allImportedDefinitions.forEach(importedDefinition => {
addDefinition(importedDefinition);
});
const dependenciesOfDefinition = dependenciesByDefinitionName.get(definitionName);
for (const dependencyName of dependenciesOfDefinition) {
const dependencyDefinitions = definitionsByName.get(dependencyName);
const dependencyDefinitionsFromImports = importedDefinitionsMap.get(dependencyName);
if (!dependencyDefinitions && !dependencyDefinitionsFromImports) {
// If that dependency cannot be found both in imports and this file, throw an error
if (!allImportedDefinitionsMap.has(dependencyName) && !definitionsByName.has(dependencyName)) {
throw new Error(`Couldn't find type ${dependencyName} in any of the schemas.`);
}
dependencyDefinitions === null || dependencyDefinitions === void 0 ? void 0 : dependencyDefinitions.forEach(dependencyDefinition => {
definitionsWithDependencies.add(dependencyDefinition);
});
const dependencyDefinitionsFromImports = allImportedDefinitionsMap.get(dependencyName);
dependencyDefinitionsFromImports === null || dependencyDefinitionsFromImports === void 0 ? void 0 : dependencyDefinitionsFromImports.forEach(dependencyDefinition => {
definitionsWithDependencies.add(dependencyDefinition);
addDefinition(dependencyDefinition);
});
}
fileDefinitionMap.set(definitionName, definitionsWithDependencies);
}

@@ -214,0 +250,0 @@ }

@@ -41,5 +41,2 @@ import { Kind, parse, Source } from 'graphql';

if (!visitedFiles.has(filePath)) {
const fileDefinitionMap = new Map();
// To prevent circular dependency
visitedFiles.set(filePath, fileDefinitionMap);
const fileContent = filePath in predefinedImports ? predefinedImports[filePath] : readFileSync(filePath, 'utf8');

@@ -60,2 +57,5 @@ const importLines = [];

if (otherLines) {
const fileDefinitionMap = new Map();
// To prevent circular dependency
visitedFiles.set(filePath, fileDefinitionMap);
const document = parse(new Source(otherLines, filePath));

@@ -145,4 +145,20 @@ for (const definition of document.definitions) {

}
for (const [definitionName, definitions] of definitionsByName) {
if (!fileDefinitionMap.has(definitionName)) {
fileDefinitionMap.set(definitionName, new Set());
}
const definitionsWithDependencies = fileDefinitionMap.get(definitionName);
for (const definition of definitions) {
definitionsWithDependencies.add(definition);
}
const dependenciesOfDefinition = dependenciesByDefinitionName.get(definitionName);
for (const dependencyName of dependenciesOfDefinition) {
const dependencyDefinitions = definitionsByName.get(dependencyName);
dependencyDefinitions === null || dependencyDefinitions === void 0 ? void 0 : dependencyDefinitions.forEach(dependencyDefinition => {
definitionsWithDependencies.add(dependencyDefinition);
});
}
}
}
const importedDefinitionsMap = new Map();
const allImportedDefinitionsMap = new Map();
for (const line of importLines) {

@@ -153,11 +169,10 @@ const { imports, from } = parseImportLine(line.replace('#', '').trim());

for (const [importedDefinitionName, importedDefinitions] of importFileDefinitionMap) {
// Don't need to add field specific definitions
if (!importedDefinitionName.includes('.')) {
if (!importedDefinitionsMap.has(importedDefinitionName)) {
importedDefinitionsMap.set(importedDefinitionName, new Set());
}
for (const importedDefinition of importedDefinitions) {
importedDefinitionsMap.get(importedDefinitionName).add(importedDefinition);
}
const [importedDefinitionTypeName] = importedDefinitionName.split('.');
if (!allImportedDefinitionsMap.has(importedDefinitionTypeName)) {
allImportedDefinitionsMap.set(importedDefinitionTypeName, new Set());
}
const allImportedDefinitions = allImportedDefinitionsMap.get(importedDefinitionTypeName);
for (const importedDefinition of importedDefinitions) {
allImportedDefinitions.add(importedDefinition);
}
}

@@ -171,11 +186,13 @@ }

}
const importDefinitions = importFileDefinitionMap.get(importedDefinitionName);
if (!definitionsByName.has(importedDefinitionName)) {
definitionsByName.set(importedDefinitionName, new Set());
const [importedDefinitionTypeName] = importedDefinitionName.split('.');
if (!allImportedDefinitionsMap.has(importedDefinitionTypeName)) {
allImportedDefinitionsMap.set(importedDefinitionTypeName, new Set());
}
for (const importDefinition of importDefinitions) {
definitionsByName.get(importedDefinitionName).add(importDefinition);
const allImportedDefinitions = allImportedDefinitionsMap.get(importedDefinitionTypeName);
const importedDefinitions = importFileDefinitionMap.get(importedDefinitionName);
if (!importedDefinitions) {
throw new Error(`${importedDefinitionName} is not exported by ${from} imported by ${filePath}`);
}
if (!dependenciesByDefinitionName.has(importedDefinitionName)) {
dependenciesByDefinitionName.set(importedDefinitionName, new Set());
for (const importedDefinition of importedDefinitions) {
allImportedDefinitions.add(importedDefinition);
}

@@ -185,23 +202,42 @@ }

}
for (const [definitionName, definitions] of definitionsByName) {
if (!fileDefinitionMap.has(definitionName)) {
const definitionsWithDependencies = new Set();
for (const definition of definitions) {
if (!otherLines) {
visitedFiles.set(filePath, allImportedDefinitionsMap);
}
else {
const fileDefinitionMap = visitedFiles.get(filePath);
for (const [definitionName] of definitionsByName) {
const addDefinition = (definition) => {
definitionsWithDependencies.add(definition);
}
// Regenerate field exports if some fields are imported after visitor
if ('fields' in definition) {
for (const field of definition.fields) {
const fieldName = field.name.value;
const fieldDefinitionName = definition.name.value + '.' + fieldName;
const allImportedDefinitions = allImportedDefinitionsMap.get(definitionName);
allImportedDefinitions === null || allImportedDefinitions === void 0 ? void 0 : allImportedDefinitions.forEach(importedDefinition => {
if (!fileDefinitionMap.has(fieldDefinitionName)) {
fileDefinitionMap.set(fieldDefinitionName, new Set());
}
const definitionsWithDeps = fileDefinitionMap.get(fieldDefinitionName);
definitionsWithDeps.add(importedDefinition);
});
}
}
};
const definitionsWithDependencies = fileDefinitionMap.get(definitionName);
const allImportedDefinitions = allImportedDefinitionsMap.get(definitionName);
allImportedDefinitions === null || allImportedDefinitions === void 0 ? void 0 : allImportedDefinitions.forEach(importedDefinition => {
addDefinition(importedDefinition);
});
const dependenciesOfDefinition = dependenciesByDefinitionName.get(definitionName);
for (const dependencyName of dependenciesOfDefinition) {
const dependencyDefinitions = definitionsByName.get(dependencyName);
const dependencyDefinitionsFromImports = importedDefinitionsMap.get(dependencyName);
if (!dependencyDefinitions && !dependencyDefinitionsFromImports) {
// If that dependency cannot be found both in imports and this file, throw an error
if (!allImportedDefinitionsMap.has(dependencyName) && !definitionsByName.has(dependencyName)) {
throw new Error(`Couldn't find type ${dependencyName} in any of the schemas.`);
}
dependencyDefinitions === null || dependencyDefinitions === void 0 ? void 0 : dependencyDefinitions.forEach(dependencyDefinition => {
definitionsWithDependencies.add(dependencyDefinition);
});
const dependencyDefinitionsFromImports = allImportedDefinitionsMap.get(dependencyName);
dependencyDefinitionsFromImports === null || dependencyDefinitionsFromImports === void 0 ? void 0 : dependencyDefinitionsFromImports.forEach(dependencyDefinition => {
definitionsWithDependencies.add(dependencyDefinition);
addDefinition(dependencyDefinition);
});
}
fileDefinitionMap.set(definitionName, definitionsWithDependencies);
}

@@ -208,0 +244,0 @@ }

{
"name": "@graphql-tools/import",
"version": "5.0.1-alpha-f709763.0",
"version": "6.0.0-alpha.1",
"description": "A set of utils for faster development of GraphQL tools",

@@ -21,2 +21,5 @@ "peerDependencies": {

},
"devDependencies": {
"@types/fs-extra": "8.1.0"
},
"publishConfig": {

@@ -23,0 +26,0 @@ "access": "public"

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