Mirror: The small sibling of the graphql package, slimmed down for client-side libraries.

feat: Generate graphql import map dynamically (#20)

* Use generated import map

* Reformat input to be part of plugin

* Add graphql@15 to import map filtering

* Remove changelog generator (accidental commit)

+1 -1
alias/language/parser.mjs
···
-
export { parse, parseType, parseValue } from '@0no-co/graphql.web';
···
+
export { parse, parseType, parseValue, parseValue as parseConstValue } from '@0no-co/graphql.web';
+1
package.json
···
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-tsdoc": "^0.2.17",
"graphql": "~16.6.0",
"husky-v4": "^4.3.8",
"lint-staged": "^11.1.2",
···
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-tsdoc": "^0.2.17",
+
"graphql15": "npm:graphql@^15.8.0",
"graphql": "~16.6.0",
"husky-v4": "^4.3.8",
"lint-staged": "^11.1.2",
+7
pnpm-lock.yaml
···
eslint-plugin-prettier: ^4.2.1
eslint-plugin-tsdoc: ^0.2.17
graphql: ~16.6.0
husky-v4: ^4.3.8
lint-staged: ^11.1.2
npm-run-all: ^4.1.5
···
eslint-plugin-prettier: 4.2.1_i2qmqyy4fgpgq2h7f6vnil3crq
eslint-plugin-tsdoc: 0.2.17
graphql: 16.6.0
husky-v4: 4.3.8
lint-staged: 11.1.2
npm-run-all: 4.1.5
···
/grapheme-splitter/1.0.4:
resolution: {integrity: sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==}
dev: true
/graphql/16.6.0:
···
eslint-plugin-prettier: ^4.2.1
eslint-plugin-tsdoc: ^0.2.17
graphql: ~16.6.0
+
graphql15: npm:graphql@^15.8.0
husky-v4: ^4.3.8
lint-staged: ^11.1.2
npm-run-all: ^4.1.5
···
eslint-plugin-prettier: 4.2.1_i2qmqyy4fgpgq2h7f6vnil3crq
eslint-plugin-tsdoc: 0.2.17
graphql: 16.6.0
+
graphql15: /graphql/15.8.0
husky-v4: 4.3.8
lint-staged: 11.1.2
npm-run-all: 4.1.5
···
/grapheme-splitter/1.0.4:
resolution: {integrity: sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==}
+
dev: true
+
+
/graphql/15.8.0:
+
resolution: {integrity: sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==}
+
engines: {node: '>= 10.x'}
dev: true
/graphql/16.6.0:
+119 -107
scripts/rollup/config.mjs
···
import babelTransformDevAssert from '../babel/transformDevAssert.mjs';
import babelTransformObjectFreeze from '../babel/transformObjectFreeze.mjs';
-
import { importMap, packageMetadata, version } from './packageMetadata.mjs';
const cwd = process.cwd();
const graphqlModule = path.posix.join(cwd, 'node_modules/graphql/');
···
const externalModules = ['dns', 'fs', 'path', 'url'];
const externalPredicate = new RegExp(`^(${externalModules.join('|')})($|/)`);
-
const exports = {};
-
-
for (const key in importMap) {
-
const { from, local } = importMap[key];
-
if (/\/jsutils\//g.test(from)) continue;
-
-
const name = from.replace(/^graphql\//, '');
-
exports[name] = (exports[name] || '') + `export { ${key} } from '${EXTERNAL}'\n`;
-
-
const parts = name.split('/');
-
for (let i = parts.length - 1; i > 0; i--) {
-
const name = `${parts.slice(0, i).join('/')}/index`;
-
const from = `./${parts.slice(i).join('/')}`;
-
exports[name] = (exports[name] || '') + `export { ${local} } from '${from}'\n`;
-
}
-
-
const index = `export { ${local} } from './${name}'\n`;
-
exports.index = (exports.index || '') + index;
-
}
-
-
const manualChunks = (id, utils) => {
let chunk;
if (id.startsWith(graphqlModule)) {
chunk = id.slice(graphqlModule.length);
···
const { importers } = utils.getModuleInfo(id);
return importers.length === 1 ? manualChunks(importers[0], utils) : 'shared';
-
};
-
export default {
-
input: Object.keys(exports).reduce((input, key) => {
-
input[key] = path.posix.join('./virtual', key);
-
return input;
-
}, {}),
-
external(id) {
-
return externalPredicate.test(id);
-
},
-
treeshake: {
-
unknownGlobalSideEffects: false,
-
tryCatchDeoptimization: false,
-
moduleSideEffects: false,
-
},
-
plugins: [
-
{
-
async load(id) {
-
if (!id.startsWith(virtualModule)) return null;
-
const entry = path.posix.relative(virtualModule, id).replace(/\.m?js$/, '');
-
if (entry === 'version') return version;
-
return exports[entry] || null;
-
},
-
async resolveId(source, importer) {
-
if (!source.startsWith('.') && !source.startsWith('virtual/')) return null;
-
const target = path.posix.join(importer ? path.posix.dirname(importer) : cwd, source);
-
const virtualEntry = path.posix.relative(virtualModule, target);
-
if (!virtualEntry.startsWith('../')) {
-
const aliasSource = path.posix.join(aliasModule, virtualEntry);
-
const alias = await this.resolve(aliasSource, undefined, {
-
skipSelf: true,
-
});
-
return alias || target;
}
-
const graphqlEntry = path.posix.relative(graphqlModule, target);
-
if (!graphqlEntry.startsWith('../')) {
-
const aliasSource = path.posix.join(aliasModule, graphqlEntry);
-
const alias = await this.resolve(aliasSource, undefined, {
-
skipSelf: true,
-
});
-
return alias || target;
-
}
-
return null;
-
},
-
async renderStart() {
-
this.emitFile({
-
type: 'asset',
-
fileName: 'package.json',
-
source: packageMetadata,
-
});
-
this.emitFile({
-
type: 'asset',
-
fileName: 'README.md',
-
source: await fs.readFile('README.md'),
});
-
this.emitFile({
-
type: 'asset',
-
fileName: 'LICENSE',
-
source: await fs.readFile('./LICENSE.md'),
});
-
},
-
async renderChunk(_code, { fileName }) {
-
const name = fileName.replace(/\.m?js$/, '');
-
const getContents = async extension => {
-
try {
-
const name = fileName.replace(/\.m?js$/, '');
-
const contents = await fs.readFile(path.join(graphqlModule, name + extension));
-
return contents;
-
} catch (_error) {
-
return null;
-
}
-
};
-
const dts = await getContents('.d.ts');
-
const flow = await getContents('.js.flow');
-
if (dts) {
-
this.emitFile({
-
type: 'asset',
-
fileName: name + '.d.ts',
-
source: dts,
-
});
}
-
if (flow) {
-
this.emitFile({
-
type: 'asset',
-
fileName: name + '.js.flow',
-
source: flow,
-
});
-
}
-
return null;
-
},
},
resolve({
extensions: ['.mjs', '.js'],
···
import babelTransformDevAssert from '../babel/transformDevAssert.mjs';
import babelTransformObjectFreeze from '../babel/transformObjectFreeze.mjs';
+
import { packageMetadata, version } from './packageMetadata.mjs';
+
import { generateImportMap } from './importMap.mjs';
const cwd = process.cwd();
const graphqlModule = path.posix.join(cwd, 'node_modules/graphql/');
···
const externalModules = ['dns', 'fs', 'path', 'url'];
const externalPredicate = new RegExp(`^(${externalModules.join('|')})($|/)`);
+
function manualChunks(id, utils) {
let chunk;
if (id.startsWith(graphqlModule)) {
chunk = id.slice(graphqlModule.length);
···
const { importers } = utils.getModuleInfo(id);
return importers.length === 1 ? manualChunks(importers[0], utils) : 'shared';
+
}
+
function buildPlugin() {
+
const exports = {};
+
return {
+
async buildStart(options) {
+
const importMap = await generateImportMap();
+
for (const key in importMap) {
+
const { from, local } = importMap[key];
+
if (/\/jsutils\//g.test(from)) continue;
+
const name = from.replace(/^graphql\//, '');
+
exports[name] = (exports[name] || '') + `export { ${key} } from '${EXTERNAL}'\n`;
+
const parts = name.split('/');
+
for (let i = parts.length - 1; i > 0; i--) {
+
const name = `${parts.slice(0, i).join('/')}/index`;
+
const from = `./${parts.slice(i).join('/')}`;
+
if (from !== './index')
+
exports[name] = (exports[name] || '') + `export { ${local} } from '${from}'\n`;
}
+
const index = `export { ${local} } from './${name}'\n`;
+
exports.index = (exports.index || '') + index;
+
}
+
if (typeof options.input !== 'object') options.input = {};
+
for (const key in exports) {
+
options.input[key] = path.posix.join('./virtual', key);
+
}
+
},
+
async load(id) {
+
if (!id.startsWith(virtualModule)) return null;
+
const entry = path.posix.relative(virtualModule, id).replace(/\.m?js$/, '');
+
if (entry === 'version') return version;
+
return exports[entry] || null;
+
},
+
+
async resolveId(source, importer) {
+
if (!source.startsWith('.') && !source.startsWith('virtual/')) return null;
+
+
const target = path.posix.join(importer ? path.posix.dirname(importer) : cwd, source);
+
+
const virtualEntry = path.posix.relative(virtualModule, target);
+
if (!virtualEntry.startsWith('../')) {
+
const aliasSource = path.posix.join(aliasModule, virtualEntry);
+
const alias = await this.resolve(aliasSource, undefined, {
+
skipSelf: true,
});
+
return alias || target;
+
}
+
const graphqlEntry = path.posix.relative(graphqlModule, target);
+
if (!graphqlEntry.startsWith('../')) {
+
const aliasSource = path.posix.join(aliasModule, graphqlEntry);
+
const alias = await this.resolve(aliasSource, undefined, {
+
skipSelf: true,
});
+
return alias || target;
+
}
+
+
return null;
+
},
+
+
async renderStart() {
+
this.emitFile({
+
type: 'asset',
+
fileName: 'package.json',
+
source: packageMetadata,
+
});
+
this.emitFile({
+
type: 'asset',
+
fileName: 'README.md',
+
source: await fs.readFile('README.md'),
+
});
+
this.emitFile({
+
type: 'asset',
+
fileName: 'LICENSE',
+
source: await fs.readFile('./LICENSE.md'),
+
});
+
},
+
async renderChunk(_code, { fileName }) {
+
const name = fileName.replace(/\.m?js$/, '');
+
const getContents = async extension => {
+
try {
+
const name = fileName.replace(/\.m?js$/, '');
+
const contents = await fs.readFile(path.join(graphqlModule, name + extension));
+
return contents;
+
} catch (_error) {
+
return null;
}
+
};
+
const dts = await getContents('.d.ts');
+
const flow = await getContents('.js.flow');
+
if (dts) {
+
this.emitFile({
+
type: 'asset',
+
fileName: name + '.d.ts',
+
source: dts,
+
});
+
}
+
+
if (flow) {
+
this.emitFile({
+
type: 'asset',
+
fileName: name + '.js.flow',
+
source: flow,
+
});
+
}
+
+
return null;
},
+
};
+
}
+
+
export default {
+
input: {},
+
external(id) {
+
return externalPredicate.test(id);
+
},
+
treeshake: {
+
unknownGlobalSideEffects: false,
+
tryCatchDeoptimization: false,
+
moduleSideEffects: false,
+
},
+
plugins: [
+
buildPlugin(),
resolve({
extensions: ['.mjs', '.js'],
-730
scripts/rollup/importMap.json
···
-
{
-
"BREAK": {
-
"local": "BREAK",
-
"from": "graphql/language/visitor"
-
},
-
"BreakingChangeType": {
-
"local": "BreakingChangeType",
-
"from": "graphql/utilities/findBreakingChanges"
-
},
-
"DEFAULT_DEPRECATION_REASON": {
-
"local": "DEFAULT_DEPRECATION_REASON",
-
"from": "graphql/type/directives"
-
},
-
"DangerousChangeType": {
-
"local": "DangerousChangeType",
-
"from": "graphql/utilities/findBreakingChanges"
-
},
-
"DirectiveLocation": {
-
"local": "DirectiveLocation",
-
"from": "graphql/language/directiveLocation"
-
},
-
"ExecutableDefinitionsRule": {
-
"local": "ExecutableDefinitionsRule",
-
"from": "graphql/validation/rules/ExecutableDefinitionsRule"
-
},
-
"FieldsOnCorrectTypeRule": {
-
"local": "FieldsOnCorrectTypeRule",
-
"from": "graphql/validation/rules/FieldsOnCorrectTypeRule"
-
},
-
"FragmentsOnCompositeTypesRule": {
-
"local": "FragmentsOnCompositeTypesRule",
-
"from": "graphql/validation/rules/FragmentsOnCompositeTypesRule"
-
},
-
"GRAPHQL_MAX_INT": {
-
"local": "GRAPHQL_MAX_INT",
-
"from": "graphql/type/scalars"
-
},
-
"GRAPHQL_MIN_INT": {
-
"local": "GRAPHQL_MIN_INT",
-
"from": "graphql/type/scalars"
-
},
-
"GraphQLBoolean": {
-
"local": "GraphQLBoolean",
-
"from": "graphql/type/scalars"
-
},
-
"GraphQLDeprecatedDirective": {
-
"local": "GraphQLDeprecatedDirective",
-
"from": "graphql/type/directives"
-
},
-
"GraphQLDirective": {
-
"local": "GraphQLDirective",
-
"from": "graphql/type/directives"
-
},
-
"GraphQLEnumType": {
-
"local": "GraphQLEnumType",
-
"from": "graphql/type/definition"
-
},
-
"GraphQLError": {
-
"local": "GraphQLError",
-
"from": "graphql/error/GraphQLError"
-
},
-
"GraphQLFloat": {
-
"local": "GraphQLFloat",
-
"from": "graphql/type/scalars"
-
},
-
"GraphQLID": {
-
"local": "GraphQLID",
-
"from": "graphql/type/scalars"
-
},
-
"GraphQLIncludeDirective": {
-
"local": "GraphQLIncludeDirective",
-
"from": "graphql/type/directives"
-
},
-
"GraphQLInt": {
-
"local": "GraphQLInt",
-
"from": "graphql/type/scalars"
-
},
-
"GraphQLList": {
-
"local": "GraphQLList",
-
"from": "graphql/type/definition"
-
},
-
"GraphQLNonNull": {
-
"local": "GraphQLNonNull",
-
"from": "graphql/type/definition"
-
},
-
"GraphQLObjectType": {
-
"local": "GraphQLObjectType",
-
"from": "graphql/type/definition"
-
},
-
"GraphQLScalarType": {
-
"local": "GraphQLScalarType",
-
"from": "graphql/type/definition"
-
},
-
"GraphQLSchema": {
-
"local": "GraphQLSchema",
-
"from": "graphql/type/schema"
-
},
-
"GraphQLSkipDirective": {
-
"local": "GraphQLSkipDirective",
-
"from": "graphql/type/directives"
-
},
-
"GraphQLSpecifiedByDirective": {
-
"local": "GraphQLSpecifiedByDirective",
-
"from": "graphql/type/directives"
-
},
-
"GraphQLString": {
-
"local": "GraphQLString",
-
"from": "graphql/type/scalars"
-
},
-
"Kind": {
-
"local": "Kind",
-
"from": "graphql/language/kinds"
-
},
-
"KnownArgumentNamesRule": {
-
"local": "KnownArgumentNamesRule",
-
"from": "graphql/validation/rules/KnownArgumentNamesRule"
-
},
-
"KnownDirectivesRule": {
-
"local": "KnownDirectivesRule",
-
"from": "graphql/validation/rules/KnownDirectivesRule"
-
},
-
"KnownFragmentNamesRule": {
-
"local": "KnownFragmentNamesRule",
-
"from": "graphql/validation/rules/KnownFragmentNamesRule"
-
},
-
"KnownTypeNamesRule": {
-
"local": "KnownTypeNamesRule",
-
"from": "graphql/validation/rules/KnownTypeNamesRule"
-
},
-
"Location": {
-
"local": "Location",
-
"from": "graphql/language/ast"
-
},
-
"LoneAnonymousOperationRule": {
-
"local": "LoneAnonymousOperationRule",
-
"from": "graphql/validation/rules/LoneAnonymousOperationRule"
-
},
-
"LoneSchemaDefinitionRule": {
-
"local": "LoneSchemaDefinitionRule",
-
"from": "graphql/validation/rules/LoneSchemaDefinitionRule"
-
},
-
"NoDeprecatedCustomRule": {
-
"local": "NoDeprecatedCustomRule",
-
"from": "graphql/validation/rules/custom/NoDeprecatedCustomRule"
-
},
-
"NoFragmentCyclesRule": {
-
"local": "NoFragmentCyclesRule",
-
"from": "graphql/validation/rules/NoFragmentCyclesRule"
-
},
-
"NoSchemaIntrospectionCustomRule": {
-
"local": "NoSchemaIntrospectionCustomRule",
-
"from": "graphql/validation/rules/custom/NoSchemaIntrospectionCustomRule"
-
},
-
"NoUndefinedVariablesRule": {
-
"local": "NoUndefinedVariablesRule",
-
"from": "graphql/validation/rules/NoUndefinedVariablesRule"
-
},
-
"NoUnusedFragmentsRule": {
-
"local": "NoUnusedFragmentsRule",
-
"from": "graphql/validation/rules/NoUnusedFragmentsRule"
-
},
-
"NoUnusedVariablesRule": {
-
"local": "NoUnusedVariablesRule",
-
"from": "graphql/validation/rules/NoUnusedVariablesRule"
-
},
-
"OverlappingFieldsCanBeMergedRule": {
-
"local": "OverlappingFieldsCanBeMergedRule",
-
"from": "graphql/validation/rules/OverlappingFieldsCanBeMergedRule"
-
},
-
"PossibleFragmentSpreadsRule": {
-
"local": "PossibleFragmentSpreadsRule",
-
"from": "graphql/validation/rules/PossibleFragmentSpreadsRule"
-
},
-
"PossibleTypeExtensionsRule": {
-
"local": "PossibleTypeExtensionsRule",
-
"from": "graphql/validation/rules/PossibleTypeExtensionsRule"
-
},
-
"ProvidedRequiredArgumentsRule": {
-
"local": "ProvidedRequiredArgumentsRule",
-
"from": "graphql/validation/rules/ProvidedRequiredArgumentsRule"
-
},
-
"ScalarLeafsRule": {
-
"local": "ScalarLeafsRule",
-
"from": "graphql/validation/rules/ScalarLeafsRule"
-
},
-
"SchemaMetaFieldDef": {
-
"local": "SchemaMetaFieldDef",
-
"from": "graphql/type/introspection"
-
},
-
"SingleFieldSubscriptionsRule": {
-
"local": "SingleFieldSubscriptionsRule",
-
"from": "graphql/validation/rules/SingleFieldSubscriptionsRule"
-
},
-
"Source": {
-
"local": "Source",
-
"from": "graphql/language/source"
-
},
-
"TypeInfo": {
-
"local": "TypeInfo",
-
"from": "graphql/utilities/TypeInfo"
-
},
-
"TypeKind": {
-
"local": "TypeKind",
-
"from": "graphql/type/introspection"
-
},
-
"TypeMetaFieldDef": {
-
"local": "TypeMetaFieldDef",
-
"from": "graphql/type/introspection"
-
},
-
"TypeNameMetaFieldDef": {
-
"local": "TypeNameMetaFieldDef",
-
"from": "graphql/type/introspection"
-
},
-
"UniqueArgumentNamesRule": {
-
"local": "UniqueArgumentNamesRule",
-
"from": "graphql/validation/rules/UniqueArgumentNamesRule"
-
},
-
"UniqueDirectiveNamesRule": {
-
"local": "UniqueDirectiveNamesRule",
-
"from": "graphql/validation/rules/UniqueDirectiveNamesRule"
-
},
-
"UniqueDirectivesPerLocationRule": {
-
"local": "UniqueDirectivesPerLocationRule",
-
"from": "graphql/validation/rules/UniqueDirectivesPerLocationRule"
-
},
-
"UniqueEnumValueNamesRule": {
-
"local": "UniqueEnumValueNamesRule",
-
"from": "graphql/validation/rules/UniqueEnumValueNamesRule"
-
},
-
"UniqueFieldDefinitionNamesRule": {
-
"local": "UniqueFieldDefinitionNamesRule",
-
"from": "graphql/validation/rules/UniqueFieldDefinitionNamesRule"
-
},
-
"UniqueFragmentNamesRule": {
-
"local": "UniqueFragmentNamesRule",
-
"from": "graphql/validation/rules/UniqueFragmentNamesRule"
-
},
-
"UniqueInputFieldNamesRule": {
-
"local": "UniqueInputFieldNamesRule",
-
"from": "graphql/validation/rules/UniqueInputFieldNamesRule"
-
},
-
"UniqueOperationNamesRule": {
-
"local": "UniqueOperationNamesRule",
-
"from": "graphql/validation/rules/UniqueOperationNamesRule"
-
},
-
"UniqueOperationTypesRule": {
-
"local": "UniqueOperationTypesRule",
-
"from": "graphql/validation/rules/UniqueOperationTypesRule"
-
},
-
"UniqueTypeNamesRule": {
-
"local": "UniqueTypeNamesRule",
-
"from": "graphql/validation/rules/UniqueTypeNamesRule"
-
},
-
"UniqueVariableNamesRule": {
-
"local": "UniqueVariableNamesRule",
-
"from": "graphql/validation/rules/UniqueVariableNamesRule"
-
},
-
"ValidationContext": {
-
"local": "ValidationContext",
-
"from": "graphql/validation/ValidationContext"
-
},
-
"ValuesOfCorrectTypeRule": {
-
"local": "ValuesOfCorrectTypeRule",
-
"from": "graphql/validation/rules/ValuesOfCorrectTypeRule"
-
},
-
"VariablesAreInputTypesRule": {
-
"local": "VariablesAreInputTypesRule",
-
"from": "graphql/validation/rules/VariablesAreInputTypesRule"
-
},
-
"VariablesInAllowedPositionRule": {
-
"local": "VariablesInAllowedPositionRule",
-
"from": "graphql/validation/rules/VariablesInAllowedPositionRule"
-
},
-
"__Directive": {
-
"local": "__Directive",
-
"from": "graphql/type/introspection"
-
},
-
"__DirectiveLocation": {
-
"local": "__DirectiveLocation",
-
"from": "graphql/type/introspection"
-
},
-
"__EnumValue": {
-
"local": "__EnumValue",
-
"from": "graphql/type/introspection"
-
},
-
"__Field": {
-
"local": "__Field",
-
"from": "graphql/type/introspection"
-
},
-
"__InputValue": {
-
"local": "__InputValue",
-
"from": "graphql/type/introspection"
-
},
-
"__Schema": {
-
"local": "__Schema",
-
"from": "graphql/type/introspection"
-
},
-
"__Type": {
-
"local": "__Type",
-
"from": "graphql/type/introspection"
-
},
-
"__TypeKind": {
-
"local": "__TypeKind",
-
"from": "graphql/type/introspection"
-
},
-
"assertDirective": {
-
"local": "assertDirective",
-
"from": "graphql/type/directives"
-
},
-
"assertEnumType": {
-
"local": "assertEnumType",
-
"from": "graphql/type/definition"
-
},
-
"assertInputObjectType": {
-
"local": "assertInputObjectType",
-
"from": "graphql/type/definition"
-
},
-
"assertInputType": {
-
"local": "assertInputType",
-
"from": "graphql/type/definition"
-
},
-
"assertLeafType": {
-
"local": "assertLeafType",
-
"from": "graphql/type/definition"
-
},
-
"assertListType": {
-
"local": "assertListType",
-
"from": "graphql/type/definition"
-
},
-
"assertNamedType": {
-
"local": "assertNamedType",
-
"from": "graphql/type/definition"
-
},
-
"assertNonNullType": {
-
"local": "assertNonNullType",
-
"from": "graphql/type/definition"
-
},
-
"assertNullableType": {
-
"local": "assertNullableType",
-
"from": "graphql/type/definition"
-
},
-
"assertObjectType": {
-
"local": "assertObjectType",
-
"from": "graphql/type/definition"
-
},
-
"assertOutputType": {
-
"local": "assertOutputType",
-
"from": "graphql/type/definition"
-
},
-
"assertScalarType": {
-
"local": "assertScalarType",
-
"from": "graphql/type/definition"
-
},
-
"assertType": {
-
"local": "assertType",
-
"from": "graphql/type/definition"
-
},
-
"assertUnionType": {
-
"local": "assertUnionType",
-
"from": "graphql/type/definition"
-
},
-
"assertValidName": {
-
"local": "assertValidName",
-
"from": "graphql/utilities/assertValidName"
-
},
-
"assertValidSchema": {
-
"local": "assertValidSchema",
-
"from": "graphql/type/validate"
-
},
-
"assertWrappingType": {
-
"local": "assertWrappingType",
-
"from": "graphql/type/definition"
-
},
-
"astFromValue": {
-
"local": "astFromValue",
-
"from": "graphql/utilities/astFromValue"
-
},
-
"buildClientSchema": {
-
"local": "buildClientSchema",
-
"from": "graphql/utilities/buildClientSchema"
-
},
-
"coerceInputValue": {
-
"local": "coerceInputValue",
-
"from": "graphql/utilities/coerceInputValue"
-
},
-
"concatAST": {
-
"local": "concatAST",
-
"from": "graphql/utilities/concatAST"
-
},
-
"createSourceEventStream": {
-
"local": "createSourceEventStream",
-
"from": "graphql/execution/subscribe"
-
},
-
"defaultFieldResolver": {
-
"local": "defaultFieldResolver",
-
"from": "graphql/execution/execute"
-
},
-
"defaultTypeResolver": {
-
"local": "defaultTypeResolver",
-
"from": "graphql/execution/execute"
-
},
-
"doTypesOverlap": {
-
"local": "doTypesOverlap",
-
"from": "graphql/utilities/typeComparators"
-
},
-
"execute": {
-
"local": "execute",
-
"from": "graphql/execution/execute"
-
},
-
"executeSync": {
-
"local": "executeSync",
-
"from": "graphql/execution/execute"
-
},
-
"extendSchema": {
-
"local": "extendSchema",
-
"from": "graphql/utilities/extendSchema"
-
},
-
"findBreakingChanges": {
-
"local": "findBreakingChanges",
-
"from": "graphql/utilities/findBreakingChanges"
-
},
-
"findDangerousChanges": {
-
"local": "findDangerousChanges",
-
"from": "graphql/utilities/findBreakingChanges"
-
},
-
"formatError": {
-
"local": "formatError",
-
"from": "graphql/error/formatError"
-
},
-
"getDirectiveValues": {
-
"local": "getDirectiveValues",
-
"from": "graphql/execution/values"
-
},
-
"getArgumentValues": {
-
"local": "getArgumentValues",
-
"from": "graphql/execution/values"
-
},
-
"getVariableValues": {
-
"local": "getVariableValues",
-
"from": "graphql/execution/values"
-
},
-
"getIntrospectionQuery": {
-
"local": "getIntrospectionQuery",
-
"from": "graphql/utilities/getIntrospectionQuery"
-
},
-
"getLocation": {
-
"local": "getLocation",
-
"from": "graphql/language/location"
-
},
-
"getNamedType": {
-
"local": "getNamedType",
-
"from": "graphql/type/definition"
-
},
-
"getNullableType": {
-
"local": "getNullableType",
-
"from": "graphql/type/definition"
-
},
-
"resolveObjMapThunk": {
-
"local": "resolveObjMapThunk",
-
"from": "graphql/type/definition"
-
},
-
"resolveReadonlyArrayThunk": {
-
"local": "resolveReadonlyArrayThunk",
-
"from": "graphql/type/definition"
-
},
-
"getOperationAST": {
-
"local": "getOperationAST",
-
"from": "graphql/utilities/getOperationAST"
-
},
-
"getOperationRootType": {
-
"local": "getOperationRootType",
-
"from": "graphql/utilities/getOperationRootType"
-
},
-
"getVisitFn": {
-
"local": "getVisitFn",
-
"from": "graphql/language/visitor"
-
},
-
"graphql": {
-
"local": "graphql",
-
"from": "graphql/graphql"
-
},
-
"graphqlSync": {
-
"local": "graphqlSync",
-
"from": "graphql/graphql"
-
},
-
"introspectionFromSchema": {
-
"local": "introspectionFromSchema",
-
"from": "graphql/utilities/introspectionFromSchema"
-
},
-
"introspectionTypes": {
-
"local": "introspectionTypes",
-
"from": "graphql/type/introspection"
-
},
-
"isAbstractType": {
-
"local": "isAbstractType",
-
"from": "graphql/type/definition"
-
},
-
"isCompositeType": {
-
"local": "isCompositeType",
-
"from": "graphql/type/definition"
-
},
-
"isDefinitionNode": {
-
"local": "isDefinitionNode",
-
"from": "graphql/language/predicates"
-
},
-
"isDirective": {
-
"local": "isDirective",
-
"from": "graphql/type/directives"
-
},
-
"isEnumType": {
-
"local": "isEnumType",
-
"from": "graphql/type/definition"
-
},
-
"isEqualType": {
-
"local": "isEqualType",
-
"from": "graphql/utilities/typeComparators"
-
},
-
"isExecutableDefinitionNode": {
-
"local": "isExecutableDefinitionNode",
-
"from": "graphql/language/predicates"
-
},
-
"isInputObjectType": {
-
"local": "isInputObjectType",
-
"from": "graphql/type/definition"
-
},
-
"isInputType": {
-
"local": "isInputType",
-
"from": "graphql/type/definition"
-
},
-
"isIntrospectionType": {
-
"local": "isIntrospectionType",
-
"from": "graphql/type/introspection"
-
},
-
"isLeafType": {
-
"local": "isLeafType",
-
"from": "graphql/type/definition"
-
},
-
"isListType": {
-
"local": "isListType",
-
"from": "graphql/type/definition"
-
},
-
"isNamedType": {
-
"local": "isNamedType",
-
"from": "graphql/type/definition"
-
},
-
"isNonNullType": {
-
"local": "isNonNullType",
-
"from": "graphql/type/definition"
-
},
-
"isNullableType": {
-
"local": "isNullableType",
-
"from": "graphql/type/definition"
-
},
-
"isObjectType": {
-
"local": "isObjectType",
-
"from": "graphql/type/definition"
-
},
-
"isOutputType": {
-
"local": "isOutputType",
-
"from": "graphql/type/definition"
-
},
-
"isRequiredArgument": {
-
"local": "isRequiredArgument",
-
"from": "graphql/type/definition"
-
},
-
"isRequiredInputField": {
-
"local": "isRequiredInputField",
-
"from": "graphql/type/definition"
-
},
-
"isScalarType": {
-
"local": "isScalarType",
-
"from": "graphql/type/definition"
-
},
-
"isSelectionNode": {
-
"local": "isSelectionNode",
-
"from": "graphql/language/predicates"
-
},
-
"isSpecifiedDirective": {
-
"local": "isSpecifiedDirective",
-
"from": "graphql/type/directives"
-
},
-
"isSpecifiedScalarType": {
-
"local": "isSpecifiedScalarType",
-
"from": "graphql/type/scalars"
-
},
-
"isType": {
-
"local": "isType",
-
"from": "graphql/type/definition"
-
},
-
"isTypeDefinitionNode": {
-
"local": "isTypeDefinitionNode",
-
"from": "graphql/language/predicates"
-
},
-
"isTypeExtensionNode": {
-
"local": "isTypeExtensionNode",
-
"from": "graphql/language/predicates"
-
},
-
"isTypeNode": {
-
"local": "isTypeNode",
-
"from": "graphql/language/predicates"
-
},
-
"isTypeSubTypeOf": {
-
"local": "isTypeSubTypeOf",
-
"from": "graphql/utilities/typeComparators"
-
},
-
"isTypeSystemDefinitionNode": {
-
"local": "isTypeSystemDefinitionNode",
-
"from": "graphql/language/predicates"
-
},
-
"isTypeSystemExtensionNode": {
-
"local": "isTypeSystemExtensionNode",
-
"from": "graphql/language/predicates"
-
},
-
"isUnionType": {
-
"local": "isUnionType",
-
"from": "graphql/type/definition"
-
},
-
"isValidNameError": {
-
"local": "isValidNameError",
-
"from": "graphql/utilities/assertValidName"
-
},
-
"isValueNode": {
-
"local": "isValueNode",
-
"from": "graphql/language/predicates"
-
},
-
"isWrappingType": {
-
"local": "isWrappingType",
-
"from": "graphql/type/definition"
-
},
-
"locatedError": {
-
"local": "locatedError",
-
"from": "graphql/error/locatedError"
-
},
-
"parse": {
-
"local": "parse",
-
"from": "graphql/language/parser"
-
},
-
"parseType": {
-
"local": "parseType",
-
"from": "graphql/language/parser"
-
},
-
"parseValue": {
-
"local": "parseValue",
-
"from": "graphql/language/parser"
-
},
-
"print": {
-
"local": "print",
-
"from": "graphql/language/printer"
-
},
-
"printError": {
-
"local": "printError",
-
"from": "graphql/error/GraphQLError"
-
},
-
"printLocation": {
-
"local": "printLocation",
-
"from": "graphql/language/printLocation"
-
},
-
"printSourceLocation": {
-
"local": "printSourceLocation",
-
"from": "graphql/language/printLocation"
-
},
-
"responsePathAsArray": {
-
"local": "pathToArray",
-
"from": "graphql/jsutils/Path"
-
},
-
"separateOperations": {
-
"local": "separateOperations",
-
"from": "graphql/utilities/separateOperations"
-
},
-
"specifiedDirectives": {
-
"local": "specifiedDirectives",
-
"from": "graphql/type/directives"
-
},
-
"specifiedRules": {
-
"local": "specifiedRules",
-
"from": "graphql/validation/specifiedRules"
-
},
-
"specifiedScalarTypes": {
-
"local": "specifiedScalarTypes",
-
"from": "graphql/type/scalars"
-
},
-
"stripIgnoredCharacters": {
-
"local": "stripIgnoredCharacters",
-
"from": "graphql/utilities/stripIgnoredCharacters"
-
},
-
"subscribe": {
-
"local": "subscribe",
-
"from": "graphql/subscription/subscribe"
-
},
-
"typeFromAST": {
-
"local": "typeFromAST",
-
"from": "graphql/utilities/typeFromAST"
-
},
-
"validate": {
-
"local": "validate",
-
"from": "graphql/validation/validate"
-
},
-
"validateSchema": {
-
"local": "validateSchema",
-
"from": "graphql/type/validate"
-
},
-
"valueFromAST": {
-
"local": "valueFromAST",
-
"from": "graphql/utilities/valueFromAST"
-
},
-
"valueFromASTUntyped": {
-
"local": "valueFromASTUntyped",
-
"from": "graphql/utilities/valueFromASTUntyped"
-
},
-
"version": {
-
"local": "version",
-
"from": "graphql/version"
-
},
-
"versionInfo": {
-
"local": "versionInfo",
-
"from": "graphql/version"
-
},
-
"visit": {
-
"local": "visit",
-
"from": "graphql/language/visitor"
-
},
-
"visitInParallel": {
-
"local": "visitInParallel",
-
"from": "graphql/language/visitor"
-
},
-
"visitWithTypeInfo": {
-
"local": "visitWithTypeInfo",
-
"from": "graphql/utilities/TypeInfo"
-
}
-
}
···
+136
scripts/rollup/importMap.mjs
···
···
+
import * as path from 'path';
+
import { nodeResolve } from '@rollup/plugin-node-resolve';
+
import { rollup } from 'rollup';
+
+
/** Generates a map of exports from a given graphql package to list of import locations. */
+
async function traceImports(moduleName) {
+
const basepath = path.resolve(process.cwd(), 'node_modules/', moduleName);
+
const exportMap = {};
+
+
const resolveFile = (to, relative = '.') => {
+
const dirname = path.join('graphql/', relative, path.dirname(to));
+
const filename = path.basename(to, '.mjs');
+
return path.join(dirname, filename);
+
};
+
+
const bundle = await rollup({
+
// This contains all top-level "sub-modules" of graphql too, since not all exports of
+
// them may be exposed in the main index.mjs file.
+
input: {
+
graphql: path.join(basepath, 'index.mjs'),
+
'graphql/error': path.join(basepath, 'error/index.mjs'),
+
'graphql/execution': path.join(basepath, 'execution/index.mjs'),
+
'graphql/language': path.join(basepath, 'language/index.mjs'),
+
'graphql/subscription': path.join(basepath, 'subscription/index.mjs'),
+
'graphql/type': path.join(basepath, 'type/index.mjs'),
+
'graphql/utilities': path.join(basepath, 'utilities/index.mjs'),
+
'graphql/validation': path.join(basepath, 'validation/index.mjs'),
+
},
+
shimMissingExports: false,
+
preserveEntrySignatures: 'allow-extension',
+
preserveSymlinks: true,
+
external: id => !/^\.{0,2}\//.test(id),
+
plugins: [
+
nodeResolve(),
+
{
+
transform(code, id) {
+
const relative = path.relative(basepath, id);
+
const dirname = path.dirname(relative);
+
const exports = {};
+
+
this.parse(code)
+
.body.filter(x => x.type === 'ExportNamedDeclaration')
+
.forEach(node => {
+
const from = node.source
+
? resolveFile(node.source.value, dirname)
+
: resolveFile(relative);
+
+
node.specifiers.forEach(specifier => {
+
const { name: local } = specifier.exported;
+
exports[local] = { local, from };
+
});
+
+
if (node.declaration) {
+
(node.declaration.declarations || [node.declaration]).forEach(declaration => {
+
if (declaration && declaration.id) {
+
const { name: local } = declaration.id;
+
exports[local] = { local, from };
+
}
+
});
+
}
+
});
+
+
exportMap[resolveFile(relative)] = exports;
+
return null;
+
},
+
},
+
],
+
});
+
+
await bundle.generate({});
+
return exportMap;
+
}
+
+
function isDeclarationEqual(a, b) {
+
return a.local === b.local && a.from === b.from;
+
}
+
+
function mergeTraces(traces) {
+
const trace = {};
+
+
// Iterate over all known filenames in all traces
+
const ids = new Set(
+
traces.map(trace => Object.keys(trace)).reduce((acc, names) => acc.concat(names), [])
+
);
+
for (const id of ids) {
+
// Each file must exist in all traces
+
if (!traces.every(trace => !!trace[id])) continue;
+
+
const exports = {};
+
+
// Iterate over all known exports in each trace's set of exports for this file
+
const exportNames = new Set(
+
traces.map(trace => Object.keys(trace[id])).reduce((acc, names) => acc.concat(names), [])
+
);
+
for (const name of exportNames) {
+
// Each export must exist in all traces
+
if (traces.every(trace => !!trace[id][name])) {
+
// Collect known declarations and deduplicate
+
exports[name] = traces
+
.map(trace => trace[id][name])
+
.filter((val, index, all) => {
+
const firstIndex = all.findIndex(item => isDeclarationEqual(item, val));
+
return firstIndex === index;
+
});
+
}
+
}
+
+
if (Object.keys(exports).length) trace[id] = exports;
+
}
+
+
// For a given declaration, find the first deepest one that works for the trace
+
// NOTE: This doesn't find the absolute deepest one, since it assumes that each
+
// export only has one functional trace
+
const resolveDeclaration = declaration => {
+
const declarations = trace[declaration.from];
+
if (!declarations || !declarations[declaration.local]) return null;
+
for (const childDeclaration of declarations[declaration.local]) {
+
if (childDeclaration.from === declaration.from) continue;
+
const resolved = resolveDeclaration(childDeclaration);
+
if (resolved && resolved.from !== declaration.from) return resolved;
+
}
+
+
return declaration;
+
};
+
+
// Resolve all known (and consistent) exports to a common, deepest declaration
+
const ROOT_MODULE = 'graphql/index';
+
const exports = {};
+
for (const local in trace[ROOT_MODULE])
+
exports[local] = resolveDeclaration({ local, from: ROOT_MODULE });
+
return exports;
+
}
+
+
export async function generateImportMap() {
+
return mergeTraces(await Promise.all([traceImports('graphql'), traceImports('graphql15')]));
+
}
-5
scripts/rollup/packageMetadata.mjs
···
import semver from 'semver';
-
import * as url from 'url';
-
import * as path from 'path';
import { createRequire } from 'node:module';
-
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
const require = createRequire(import.meta.url);
const rootPkg = require('../../package.json');
···
null,
2
);
-
-
export const importMap = require('./importMap.json');
···
import semver from 'semver';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const rootPkg = require('../../package.json');
···
null,
2
);