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

Configure Feed

Select the types of activity you want to include in your feed.

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)

authored by kitten.sh and committed by

GitHub 509d1232 b5115c42

+264 -843
+1 -1
alias/language/parser.mjs
··· 1 - export { parse, parseType, parseValue } from '@0no-co/graphql.web'; 1 + export { parse, parseType, parseValue, parseValue as parseConstValue } from '@0no-co/graphql.web';
+1
package.json
··· 51 51 "eslint-config-prettier": "^8.7.0", 52 52 "eslint-plugin-prettier": "^4.2.1", 53 53 "eslint-plugin-tsdoc": "^0.2.17", 54 + "graphql15": "npm:graphql@^15.8.0", 54 55 "graphql": "~16.6.0", 55 56 "husky-v4": "^4.3.8", 56 57 "lint-staged": "^11.1.2",
+7
pnpm-lock.yaml
··· 23 23 eslint-plugin-prettier: ^4.2.1 24 24 eslint-plugin-tsdoc: ^0.2.17 25 25 graphql: ~16.6.0 26 + graphql15: npm:graphql@^15.8.0 26 27 husky-v4: ^4.3.8 27 28 lint-staged: ^11.1.2 28 29 npm-run-all: ^4.1.5 ··· 49 50 eslint-plugin-prettier: 4.2.1_i2qmqyy4fgpgq2h7f6vnil3crq 50 51 eslint-plugin-tsdoc: 0.2.17 51 52 graphql: 16.6.0 53 + graphql15: /graphql/15.8.0 52 54 husky-v4: 4.3.8 53 55 lint-staged: 11.1.2 54 56 npm-run-all: 4.1.5 ··· 2388 2390 2389 2391 /grapheme-splitter/1.0.4: 2390 2392 resolution: {integrity: sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==} 2393 + dev: true 2394 + 2395 + /graphql/15.8.0: 2396 + resolution: {integrity: sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==} 2397 + engines: {node: '>= 10.x'} 2391 2398 dev: true 2392 2399 2393 2400 /graphql/16.6.0:
+119 -107
scripts/rollup/config.mjs
··· 12 12 import babelTransformDevAssert from '../babel/transformDevAssert.mjs'; 13 13 import babelTransformObjectFreeze from '../babel/transformObjectFreeze.mjs'; 14 14 15 - import { importMap, packageMetadata, version } from './packageMetadata.mjs'; 15 + import { packageMetadata, version } from './packageMetadata.mjs'; 16 + import { generateImportMap } from './importMap.mjs'; 16 17 17 18 const cwd = process.cwd(); 18 19 const graphqlModule = path.posix.join(cwd, 'node_modules/graphql/'); ··· 23 24 const externalModules = ['dns', 'fs', 'path', 'url']; 24 25 const externalPredicate = new RegExp(`^(${externalModules.join('|')})($|/)`); 25 26 26 - const exports = {}; 27 - 28 - for (const key in importMap) { 29 - const { from, local } = importMap[key]; 30 - if (/\/jsutils\//g.test(from)) continue; 31 - 32 - const name = from.replace(/^graphql\//, ''); 33 - exports[name] = (exports[name] || '') + `export { ${key} } from '${EXTERNAL}'\n`; 34 - 35 - const parts = name.split('/'); 36 - for (let i = parts.length - 1; i > 0; i--) { 37 - const name = `${parts.slice(0, i).join('/')}/index`; 38 - const from = `./${parts.slice(i).join('/')}`; 39 - exports[name] = (exports[name] || '') + `export { ${local} } from '${from}'\n`; 40 - } 41 - 42 - const index = `export { ${local} } from './${name}'\n`; 43 - exports.index = (exports.index || '') + index; 44 - } 45 - 46 - const manualChunks = (id, utils) => { 27 + function manualChunks(id, utils) { 47 28 let chunk; 48 29 if (id.startsWith(graphqlModule)) { 49 30 chunk = id.slice(graphqlModule.length); ··· 59 40 60 41 const { importers } = utils.getModuleInfo(id); 61 42 return importers.length === 1 ? manualChunks(importers[0], utils) : 'shared'; 62 - }; 43 + } 63 44 64 - export default { 65 - input: Object.keys(exports).reduce((input, key) => { 66 - input[key] = path.posix.join('./virtual', key); 67 - return input; 68 - }, {}), 69 - external(id) { 70 - return externalPredicate.test(id); 71 - }, 72 - treeshake: { 73 - unknownGlobalSideEffects: false, 74 - tryCatchDeoptimization: false, 75 - moduleSideEffects: false, 76 - }, 77 - plugins: [ 78 - { 79 - async load(id) { 80 - if (!id.startsWith(virtualModule)) return null; 81 - const entry = path.posix.relative(virtualModule, id).replace(/\.m?js$/, ''); 82 - if (entry === 'version') return version; 83 - return exports[entry] || null; 84 - }, 45 + function buildPlugin() { 46 + const exports = {}; 47 + return { 48 + async buildStart(options) { 49 + const importMap = await generateImportMap(); 85 50 86 - async resolveId(source, importer) { 87 - if (!source.startsWith('.') && !source.startsWith('virtual/')) return null; 51 + for (const key in importMap) { 52 + const { from, local } = importMap[key]; 53 + if (/\/jsutils\//g.test(from)) continue; 88 54 89 - const target = path.posix.join(importer ? path.posix.dirname(importer) : cwd, source); 55 + const name = from.replace(/^graphql\//, ''); 56 + exports[name] = (exports[name] || '') + `export { ${key} } from '${EXTERNAL}'\n`; 90 57 91 - const virtualEntry = path.posix.relative(virtualModule, target); 92 - if (!virtualEntry.startsWith('../')) { 93 - const aliasSource = path.posix.join(aliasModule, virtualEntry); 94 - const alias = await this.resolve(aliasSource, undefined, { 95 - skipSelf: true, 96 - }); 97 - return alias || target; 58 + const parts = name.split('/'); 59 + for (let i = parts.length - 1; i > 0; i--) { 60 + const name = `${parts.slice(0, i).join('/')}/index`; 61 + const from = `./${parts.slice(i).join('/')}`; 62 + if (from !== './index') 63 + exports[name] = (exports[name] || '') + `export { ${local} } from '${from}'\n`; 98 64 } 99 65 100 - const graphqlEntry = path.posix.relative(graphqlModule, target); 101 - if (!graphqlEntry.startsWith('../')) { 102 - const aliasSource = path.posix.join(aliasModule, graphqlEntry); 103 - const alias = await this.resolve(aliasSource, undefined, { 104 - skipSelf: true, 105 - }); 106 - return alias || target; 107 - } 66 + const index = `export { ${local} } from './${name}'\n`; 67 + exports.index = (exports.index || '') + index; 68 + } 108 69 109 - return null; 110 - }, 70 + if (typeof options.input !== 'object') options.input = {}; 111 71 112 - async renderStart() { 113 - this.emitFile({ 114 - type: 'asset', 115 - fileName: 'package.json', 116 - source: packageMetadata, 117 - }); 72 + for (const key in exports) { 73 + options.input[key] = path.posix.join('./virtual', key); 74 + } 75 + }, 118 76 119 - this.emitFile({ 120 - type: 'asset', 121 - fileName: 'README.md', 122 - source: await fs.readFile('README.md'), 77 + async load(id) { 78 + if (!id.startsWith(virtualModule)) return null; 79 + const entry = path.posix.relative(virtualModule, id).replace(/\.m?js$/, ''); 80 + if (entry === 'version') return version; 81 + return exports[entry] || null; 82 + }, 83 + 84 + async resolveId(source, importer) { 85 + if (!source.startsWith('.') && !source.startsWith('virtual/')) return null; 86 + 87 + const target = path.posix.join(importer ? path.posix.dirname(importer) : cwd, source); 88 + 89 + const virtualEntry = path.posix.relative(virtualModule, target); 90 + if (!virtualEntry.startsWith('../')) { 91 + const aliasSource = path.posix.join(aliasModule, virtualEntry); 92 + const alias = await this.resolve(aliasSource, undefined, { 93 + skipSelf: true, 123 94 }); 95 + return alias || target; 96 + } 124 97 125 - this.emitFile({ 126 - type: 'asset', 127 - fileName: 'LICENSE', 128 - source: await fs.readFile('./LICENSE.md'), 98 + const graphqlEntry = path.posix.relative(graphqlModule, target); 99 + if (!graphqlEntry.startsWith('../')) { 100 + const aliasSource = path.posix.join(aliasModule, graphqlEntry); 101 + const alias = await this.resolve(aliasSource, undefined, { 102 + skipSelf: true, 129 103 }); 130 - }, 104 + return alias || target; 105 + } 106 + 107 + return null; 108 + }, 109 + 110 + async renderStart() { 111 + this.emitFile({ 112 + type: 'asset', 113 + fileName: 'package.json', 114 + source: packageMetadata, 115 + }); 131 116 132 - async renderChunk(_code, { fileName }) { 133 - const name = fileName.replace(/\.m?js$/, ''); 117 + this.emitFile({ 118 + type: 'asset', 119 + fileName: 'README.md', 120 + source: await fs.readFile('README.md'), 121 + }); 134 122 135 - const getContents = async extension => { 136 - try { 137 - const name = fileName.replace(/\.m?js$/, ''); 138 - const contents = await fs.readFile(path.join(graphqlModule, name + extension)); 139 - return contents; 140 - } catch (_error) { 141 - return null; 142 - } 143 - }; 123 + this.emitFile({ 124 + type: 'asset', 125 + fileName: 'LICENSE', 126 + source: await fs.readFile('./LICENSE.md'), 127 + }); 128 + }, 144 129 145 - const dts = await getContents('.d.ts'); 146 - const flow = await getContents('.js.flow'); 130 + async renderChunk(_code, { fileName }) { 131 + const name = fileName.replace(/\.m?js$/, ''); 147 132 148 - if (dts) { 149 - this.emitFile({ 150 - type: 'asset', 151 - fileName: name + '.d.ts', 152 - source: dts, 153 - }); 133 + const getContents = async extension => { 134 + try { 135 + const name = fileName.replace(/\.m?js$/, ''); 136 + const contents = await fs.readFile(path.join(graphqlModule, name + extension)); 137 + return contents; 138 + } catch (_error) { 139 + return null; 154 140 } 141 + }; 155 142 156 - if (flow) { 157 - this.emitFile({ 158 - type: 'asset', 159 - fileName: name + '.js.flow', 160 - source: flow, 161 - }); 162 - } 143 + const dts = await getContents('.d.ts'); 144 + const flow = await getContents('.js.flow'); 163 145 164 - return null; 165 - }, 146 + if (dts) { 147 + this.emitFile({ 148 + type: 'asset', 149 + fileName: name + '.d.ts', 150 + source: dts, 151 + }); 152 + } 153 + 154 + if (flow) { 155 + this.emitFile({ 156 + type: 'asset', 157 + fileName: name + '.js.flow', 158 + source: flow, 159 + }); 160 + } 161 + 162 + return null; 166 163 }, 164 + }; 165 + } 166 + 167 + export default { 168 + input: {}, 169 + external(id) { 170 + return externalPredicate.test(id); 171 + }, 172 + treeshake: { 173 + unknownGlobalSideEffects: false, 174 + tryCatchDeoptimization: false, 175 + moduleSideEffects: false, 176 + }, 177 + plugins: [ 178 + buildPlugin(), 167 179 168 180 resolve({ 169 181 extensions: ['.mjs', '.js'],
-730
scripts/rollup/importMap.json
··· 1 - { 2 - "BREAK": { 3 - "local": "BREAK", 4 - "from": "graphql/language/visitor" 5 - }, 6 - "BreakingChangeType": { 7 - "local": "BreakingChangeType", 8 - "from": "graphql/utilities/findBreakingChanges" 9 - }, 10 - "DEFAULT_DEPRECATION_REASON": { 11 - "local": "DEFAULT_DEPRECATION_REASON", 12 - "from": "graphql/type/directives" 13 - }, 14 - "DangerousChangeType": { 15 - "local": "DangerousChangeType", 16 - "from": "graphql/utilities/findBreakingChanges" 17 - }, 18 - "DirectiveLocation": { 19 - "local": "DirectiveLocation", 20 - "from": "graphql/language/directiveLocation" 21 - }, 22 - "ExecutableDefinitionsRule": { 23 - "local": "ExecutableDefinitionsRule", 24 - "from": "graphql/validation/rules/ExecutableDefinitionsRule" 25 - }, 26 - "FieldsOnCorrectTypeRule": { 27 - "local": "FieldsOnCorrectTypeRule", 28 - "from": "graphql/validation/rules/FieldsOnCorrectTypeRule" 29 - }, 30 - "FragmentsOnCompositeTypesRule": { 31 - "local": "FragmentsOnCompositeTypesRule", 32 - "from": "graphql/validation/rules/FragmentsOnCompositeTypesRule" 33 - }, 34 - "GRAPHQL_MAX_INT": { 35 - "local": "GRAPHQL_MAX_INT", 36 - "from": "graphql/type/scalars" 37 - }, 38 - "GRAPHQL_MIN_INT": { 39 - "local": "GRAPHQL_MIN_INT", 40 - "from": "graphql/type/scalars" 41 - }, 42 - "GraphQLBoolean": { 43 - "local": "GraphQLBoolean", 44 - "from": "graphql/type/scalars" 45 - }, 46 - "GraphQLDeprecatedDirective": { 47 - "local": "GraphQLDeprecatedDirective", 48 - "from": "graphql/type/directives" 49 - }, 50 - "GraphQLDirective": { 51 - "local": "GraphQLDirective", 52 - "from": "graphql/type/directives" 53 - }, 54 - "GraphQLEnumType": { 55 - "local": "GraphQLEnumType", 56 - "from": "graphql/type/definition" 57 - }, 58 - "GraphQLError": { 59 - "local": "GraphQLError", 60 - "from": "graphql/error/GraphQLError" 61 - }, 62 - "GraphQLFloat": { 63 - "local": "GraphQLFloat", 64 - "from": "graphql/type/scalars" 65 - }, 66 - "GraphQLID": { 67 - "local": "GraphQLID", 68 - "from": "graphql/type/scalars" 69 - }, 70 - "GraphQLIncludeDirective": { 71 - "local": "GraphQLIncludeDirective", 72 - "from": "graphql/type/directives" 73 - }, 74 - "GraphQLInt": { 75 - "local": "GraphQLInt", 76 - "from": "graphql/type/scalars" 77 - }, 78 - "GraphQLList": { 79 - "local": "GraphQLList", 80 - "from": "graphql/type/definition" 81 - }, 82 - "GraphQLNonNull": { 83 - "local": "GraphQLNonNull", 84 - "from": "graphql/type/definition" 85 - }, 86 - "GraphQLObjectType": { 87 - "local": "GraphQLObjectType", 88 - "from": "graphql/type/definition" 89 - }, 90 - "GraphQLScalarType": { 91 - "local": "GraphQLScalarType", 92 - "from": "graphql/type/definition" 93 - }, 94 - "GraphQLSchema": { 95 - "local": "GraphQLSchema", 96 - "from": "graphql/type/schema" 97 - }, 98 - "GraphQLSkipDirective": { 99 - "local": "GraphQLSkipDirective", 100 - "from": "graphql/type/directives" 101 - }, 102 - "GraphQLSpecifiedByDirective": { 103 - "local": "GraphQLSpecifiedByDirective", 104 - "from": "graphql/type/directives" 105 - }, 106 - "GraphQLString": { 107 - "local": "GraphQLString", 108 - "from": "graphql/type/scalars" 109 - }, 110 - "Kind": { 111 - "local": "Kind", 112 - "from": "graphql/language/kinds" 113 - }, 114 - "KnownArgumentNamesRule": { 115 - "local": "KnownArgumentNamesRule", 116 - "from": "graphql/validation/rules/KnownArgumentNamesRule" 117 - }, 118 - "KnownDirectivesRule": { 119 - "local": "KnownDirectivesRule", 120 - "from": "graphql/validation/rules/KnownDirectivesRule" 121 - }, 122 - "KnownFragmentNamesRule": { 123 - "local": "KnownFragmentNamesRule", 124 - "from": "graphql/validation/rules/KnownFragmentNamesRule" 125 - }, 126 - "KnownTypeNamesRule": { 127 - "local": "KnownTypeNamesRule", 128 - "from": "graphql/validation/rules/KnownTypeNamesRule" 129 - }, 130 - "Location": { 131 - "local": "Location", 132 - "from": "graphql/language/ast" 133 - }, 134 - "LoneAnonymousOperationRule": { 135 - "local": "LoneAnonymousOperationRule", 136 - "from": "graphql/validation/rules/LoneAnonymousOperationRule" 137 - }, 138 - "LoneSchemaDefinitionRule": { 139 - "local": "LoneSchemaDefinitionRule", 140 - "from": "graphql/validation/rules/LoneSchemaDefinitionRule" 141 - }, 142 - "NoDeprecatedCustomRule": { 143 - "local": "NoDeprecatedCustomRule", 144 - "from": "graphql/validation/rules/custom/NoDeprecatedCustomRule" 145 - }, 146 - "NoFragmentCyclesRule": { 147 - "local": "NoFragmentCyclesRule", 148 - "from": "graphql/validation/rules/NoFragmentCyclesRule" 149 - }, 150 - "NoSchemaIntrospectionCustomRule": { 151 - "local": "NoSchemaIntrospectionCustomRule", 152 - "from": "graphql/validation/rules/custom/NoSchemaIntrospectionCustomRule" 153 - }, 154 - "NoUndefinedVariablesRule": { 155 - "local": "NoUndefinedVariablesRule", 156 - "from": "graphql/validation/rules/NoUndefinedVariablesRule" 157 - }, 158 - "NoUnusedFragmentsRule": { 159 - "local": "NoUnusedFragmentsRule", 160 - "from": "graphql/validation/rules/NoUnusedFragmentsRule" 161 - }, 162 - "NoUnusedVariablesRule": { 163 - "local": "NoUnusedVariablesRule", 164 - "from": "graphql/validation/rules/NoUnusedVariablesRule" 165 - }, 166 - "OverlappingFieldsCanBeMergedRule": { 167 - "local": "OverlappingFieldsCanBeMergedRule", 168 - "from": "graphql/validation/rules/OverlappingFieldsCanBeMergedRule" 169 - }, 170 - "PossibleFragmentSpreadsRule": { 171 - "local": "PossibleFragmentSpreadsRule", 172 - "from": "graphql/validation/rules/PossibleFragmentSpreadsRule" 173 - }, 174 - "PossibleTypeExtensionsRule": { 175 - "local": "PossibleTypeExtensionsRule", 176 - "from": "graphql/validation/rules/PossibleTypeExtensionsRule" 177 - }, 178 - "ProvidedRequiredArgumentsRule": { 179 - "local": "ProvidedRequiredArgumentsRule", 180 - "from": "graphql/validation/rules/ProvidedRequiredArgumentsRule" 181 - }, 182 - "ScalarLeafsRule": { 183 - "local": "ScalarLeafsRule", 184 - "from": "graphql/validation/rules/ScalarLeafsRule" 185 - }, 186 - "SchemaMetaFieldDef": { 187 - "local": "SchemaMetaFieldDef", 188 - "from": "graphql/type/introspection" 189 - }, 190 - "SingleFieldSubscriptionsRule": { 191 - "local": "SingleFieldSubscriptionsRule", 192 - "from": "graphql/validation/rules/SingleFieldSubscriptionsRule" 193 - }, 194 - "Source": { 195 - "local": "Source", 196 - "from": "graphql/language/source" 197 - }, 198 - "TypeInfo": { 199 - "local": "TypeInfo", 200 - "from": "graphql/utilities/TypeInfo" 201 - }, 202 - "TypeKind": { 203 - "local": "TypeKind", 204 - "from": "graphql/type/introspection" 205 - }, 206 - "TypeMetaFieldDef": { 207 - "local": "TypeMetaFieldDef", 208 - "from": "graphql/type/introspection" 209 - }, 210 - "TypeNameMetaFieldDef": { 211 - "local": "TypeNameMetaFieldDef", 212 - "from": "graphql/type/introspection" 213 - }, 214 - "UniqueArgumentNamesRule": { 215 - "local": "UniqueArgumentNamesRule", 216 - "from": "graphql/validation/rules/UniqueArgumentNamesRule" 217 - }, 218 - "UniqueDirectiveNamesRule": { 219 - "local": "UniqueDirectiveNamesRule", 220 - "from": "graphql/validation/rules/UniqueDirectiveNamesRule" 221 - }, 222 - "UniqueDirectivesPerLocationRule": { 223 - "local": "UniqueDirectivesPerLocationRule", 224 - "from": "graphql/validation/rules/UniqueDirectivesPerLocationRule" 225 - }, 226 - "UniqueEnumValueNamesRule": { 227 - "local": "UniqueEnumValueNamesRule", 228 - "from": "graphql/validation/rules/UniqueEnumValueNamesRule" 229 - }, 230 - "UniqueFieldDefinitionNamesRule": { 231 - "local": "UniqueFieldDefinitionNamesRule", 232 - "from": "graphql/validation/rules/UniqueFieldDefinitionNamesRule" 233 - }, 234 - "UniqueFragmentNamesRule": { 235 - "local": "UniqueFragmentNamesRule", 236 - "from": "graphql/validation/rules/UniqueFragmentNamesRule" 237 - }, 238 - "UniqueInputFieldNamesRule": { 239 - "local": "UniqueInputFieldNamesRule", 240 - "from": "graphql/validation/rules/UniqueInputFieldNamesRule" 241 - }, 242 - "UniqueOperationNamesRule": { 243 - "local": "UniqueOperationNamesRule", 244 - "from": "graphql/validation/rules/UniqueOperationNamesRule" 245 - }, 246 - "UniqueOperationTypesRule": { 247 - "local": "UniqueOperationTypesRule", 248 - "from": "graphql/validation/rules/UniqueOperationTypesRule" 249 - }, 250 - "UniqueTypeNamesRule": { 251 - "local": "UniqueTypeNamesRule", 252 - "from": "graphql/validation/rules/UniqueTypeNamesRule" 253 - }, 254 - "UniqueVariableNamesRule": { 255 - "local": "UniqueVariableNamesRule", 256 - "from": "graphql/validation/rules/UniqueVariableNamesRule" 257 - }, 258 - "ValidationContext": { 259 - "local": "ValidationContext", 260 - "from": "graphql/validation/ValidationContext" 261 - }, 262 - "ValuesOfCorrectTypeRule": { 263 - "local": "ValuesOfCorrectTypeRule", 264 - "from": "graphql/validation/rules/ValuesOfCorrectTypeRule" 265 - }, 266 - "VariablesAreInputTypesRule": { 267 - "local": "VariablesAreInputTypesRule", 268 - "from": "graphql/validation/rules/VariablesAreInputTypesRule" 269 - }, 270 - "VariablesInAllowedPositionRule": { 271 - "local": "VariablesInAllowedPositionRule", 272 - "from": "graphql/validation/rules/VariablesInAllowedPositionRule" 273 - }, 274 - "__Directive": { 275 - "local": "__Directive", 276 - "from": "graphql/type/introspection" 277 - }, 278 - "__DirectiveLocation": { 279 - "local": "__DirectiveLocation", 280 - "from": "graphql/type/introspection" 281 - }, 282 - "__EnumValue": { 283 - "local": "__EnumValue", 284 - "from": "graphql/type/introspection" 285 - }, 286 - "__Field": { 287 - "local": "__Field", 288 - "from": "graphql/type/introspection" 289 - }, 290 - "__InputValue": { 291 - "local": "__InputValue", 292 - "from": "graphql/type/introspection" 293 - }, 294 - "__Schema": { 295 - "local": "__Schema", 296 - "from": "graphql/type/introspection" 297 - }, 298 - "__Type": { 299 - "local": "__Type", 300 - "from": "graphql/type/introspection" 301 - }, 302 - "__TypeKind": { 303 - "local": "__TypeKind", 304 - "from": "graphql/type/introspection" 305 - }, 306 - "assertDirective": { 307 - "local": "assertDirective", 308 - "from": "graphql/type/directives" 309 - }, 310 - "assertEnumType": { 311 - "local": "assertEnumType", 312 - "from": "graphql/type/definition" 313 - }, 314 - "assertInputObjectType": { 315 - "local": "assertInputObjectType", 316 - "from": "graphql/type/definition" 317 - }, 318 - "assertInputType": { 319 - "local": "assertInputType", 320 - "from": "graphql/type/definition" 321 - }, 322 - "assertLeafType": { 323 - "local": "assertLeafType", 324 - "from": "graphql/type/definition" 325 - }, 326 - "assertListType": { 327 - "local": "assertListType", 328 - "from": "graphql/type/definition" 329 - }, 330 - "assertNamedType": { 331 - "local": "assertNamedType", 332 - "from": "graphql/type/definition" 333 - }, 334 - "assertNonNullType": { 335 - "local": "assertNonNullType", 336 - "from": "graphql/type/definition" 337 - }, 338 - "assertNullableType": { 339 - "local": "assertNullableType", 340 - "from": "graphql/type/definition" 341 - }, 342 - "assertObjectType": { 343 - "local": "assertObjectType", 344 - "from": "graphql/type/definition" 345 - }, 346 - "assertOutputType": { 347 - "local": "assertOutputType", 348 - "from": "graphql/type/definition" 349 - }, 350 - "assertScalarType": { 351 - "local": "assertScalarType", 352 - "from": "graphql/type/definition" 353 - }, 354 - "assertType": { 355 - "local": "assertType", 356 - "from": "graphql/type/definition" 357 - }, 358 - "assertUnionType": { 359 - "local": "assertUnionType", 360 - "from": "graphql/type/definition" 361 - }, 362 - "assertValidName": { 363 - "local": "assertValidName", 364 - "from": "graphql/utilities/assertValidName" 365 - }, 366 - "assertValidSchema": { 367 - "local": "assertValidSchema", 368 - "from": "graphql/type/validate" 369 - }, 370 - "assertWrappingType": { 371 - "local": "assertWrappingType", 372 - "from": "graphql/type/definition" 373 - }, 374 - "astFromValue": { 375 - "local": "astFromValue", 376 - "from": "graphql/utilities/astFromValue" 377 - }, 378 - "buildClientSchema": { 379 - "local": "buildClientSchema", 380 - "from": "graphql/utilities/buildClientSchema" 381 - }, 382 - "coerceInputValue": { 383 - "local": "coerceInputValue", 384 - "from": "graphql/utilities/coerceInputValue" 385 - }, 386 - "concatAST": { 387 - "local": "concatAST", 388 - "from": "graphql/utilities/concatAST" 389 - }, 390 - "createSourceEventStream": { 391 - "local": "createSourceEventStream", 392 - "from": "graphql/execution/subscribe" 393 - }, 394 - "defaultFieldResolver": { 395 - "local": "defaultFieldResolver", 396 - "from": "graphql/execution/execute" 397 - }, 398 - "defaultTypeResolver": { 399 - "local": "defaultTypeResolver", 400 - "from": "graphql/execution/execute" 401 - }, 402 - "doTypesOverlap": { 403 - "local": "doTypesOverlap", 404 - "from": "graphql/utilities/typeComparators" 405 - }, 406 - "execute": { 407 - "local": "execute", 408 - "from": "graphql/execution/execute" 409 - }, 410 - "executeSync": { 411 - "local": "executeSync", 412 - "from": "graphql/execution/execute" 413 - }, 414 - "extendSchema": { 415 - "local": "extendSchema", 416 - "from": "graphql/utilities/extendSchema" 417 - }, 418 - "findBreakingChanges": { 419 - "local": "findBreakingChanges", 420 - "from": "graphql/utilities/findBreakingChanges" 421 - }, 422 - "findDangerousChanges": { 423 - "local": "findDangerousChanges", 424 - "from": "graphql/utilities/findBreakingChanges" 425 - }, 426 - "formatError": { 427 - "local": "formatError", 428 - "from": "graphql/error/formatError" 429 - }, 430 - "getDirectiveValues": { 431 - "local": "getDirectiveValues", 432 - "from": "graphql/execution/values" 433 - }, 434 - "getArgumentValues": { 435 - "local": "getArgumentValues", 436 - "from": "graphql/execution/values" 437 - }, 438 - "getVariableValues": { 439 - "local": "getVariableValues", 440 - "from": "graphql/execution/values" 441 - }, 442 - "getIntrospectionQuery": { 443 - "local": "getIntrospectionQuery", 444 - "from": "graphql/utilities/getIntrospectionQuery" 445 - }, 446 - "getLocation": { 447 - "local": "getLocation", 448 - "from": "graphql/language/location" 449 - }, 450 - "getNamedType": { 451 - "local": "getNamedType", 452 - "from": "graphql/type/definition" 453 - }, 454 - "getNullableType": { 455 - "local": "getNullableType", 456 - "from": "graphql/type/definition" 457 - }, 458 - "resolveObjMapThunk": { 459 - "local": "resolveObjMapThunk", 460 - "from": "graphql/type/definition" 461 - }, 462 - "resolveReadonlyArrayThunk": { 463 - "local": "resolveReadonlyArrayThunk", 464 - "from": "graphql/type/definition" 465 - }, 466 - "getOperationAST": { 467 - "local": "getOperationAST", 468 - "from": "graphql/utilities/getOperationAST" 469 - }, 470 - "getOperationRootType": { 471 - "local": "getOperationRootType", 472 - "from": "graphql/utilities/getOperationRootType" 473 - }, 474 - "getVisitFn": { 475 - "local": "getVisitFn", 476 - "from": "graphql/language/visitor" 477 - }, 478 - "graphql": { 479 - "local": "graphql", 480 - "from": "graphql/graphql" 481 - }, 482 - "graphqlSync": { 483 - "local": "graphqlSync", 484 - "from": "graphql/graphql" 485 - }, 486 - "introspectionFromSchema": { 487 - "local": "introspectionFromSchema", 488 - "from": "graphql/utilities/introspectionFromSchema" 489 - }, 490 - "introspectionTypes": { 491 - "local": "introspectionTypes", 492 - "from": "graphql/type/introspection" 493 - }, 494 - "isAbstractType": { 495 - "local": "isAbstractType", 496 - "from": "graphql/type/definition" 497 - }, 498 - "isCompositeType": { 499 - "local": "isCompositeType", 500 - "from": "graphql/type/definition" 501 - }, 502 - "isDefinitionNode": { 503 - "local": "isDefinitionNode", 504 - "from": "graphql/language/predicates" 505 - }, 506 - "isDirective": { 507 - "local": "isDirective", 508 - "from": "graphql/type/directives" 509 - }, 510 - "isEnumType": { 511 - "local": "isEnumType", 512 - "from": "graphql/type/definition" 513 - }, 514 - "isEqualType": { 515 - "local": "isEqualType", 516 - "from": "graphql/utilities/typeComparators" 517 - }, 518 - "isExecutableDefinitionNode": { 519 - "local": "isExecutableDefinitionNode", 520 - "from": "graphql/language/predicates" 521 - }, 522 - "isInputObjectType": { 523 - "local": "isInputObjectType", 524 - "from": "graphql/type/definition" 525 - }, 526 - "isInputType": { 527 - "local": "isInputType", 528 - "from": "graphql/type/definition" 529 - }, 530 - "isIntrospectionType": { 531 - "local": "isIntrospectionType", 532 - "from": "graphql/type/introspection" 533 - }, 534 - "isLeafType": { 535 - "local": "isLeafType", 536 - "from": "graphql/type/definition" 537 - }, 538 - "isListType": { 539 - "local": "isListType", 540 - "from": "graphql/type/definition" 541 - }, 542 - "isNamedType": { 543 - "local": "isNamedType", 544 - "from": "graphql/type/definition" 545 - }, 546 - "isNonNullType": { 547 - "local": "isNonNullType", 548 - "from": "graphql/type/definition" 549 - }, 550 - "isNullableType": { 551 - "local": "isNullableType", 552 - "from": "graphql/type/definition" 553 - }, 554 - "isObjectType": { 555 - "local": "isObjectType", 556 - "from": "graphql/type/definition" 557 - }, 558 - "isOutputType": { 559 - "local": "isOutputType", 560 - "from": "graphql/type/definition" 561 - }, 562 - "isRequiredArgument": { 563 - "local": "isRequiredArgument", 564 - "from": "graphql/type/definition" 565 - }, 566 - "isRequiredInputField": { 567 - "local": "isRequiredInputField", 568 - "from": "graphql/type/definition" 569 - }, 570 - "isScalarType": { 571 - "local": "isScalarType", 572 - "from": "graphql/type/definition" 573 - }, 574 - "isSelectionNode": { 575 - "local": "isSelectionNode", 576 - "from": "graphql/language/predicates" 577 - }, 578 - "isSpecifiedDirective": { 579 - "local": "isSpecifiedDirective", 580 - "from": "graphql/type/directives" 581 - }, 582 - "isSpecifiedScalarType": { 583 - "local": "isSpecifiedScalarType", 584 - "from": "graphql/type/scalars" 585 - }, 586 - "isType": { 587 - "local": "isType", 588 - "from": "graphql/type/definition" 589 - }, 590 - "isTypeDefinitionNode": { 591 - "local": "isTypeDefinitionNode", 592 - "from": "graphql/language/predicates" 593 - }, 594 - "isTypeExtensionNode": { 595 - "local": "isTypeExtensionNode", 596 - "from": "graphql/language/predicates" 597 - }, 598 - "isTypeNode": { 599 - "local": "isTypeNode", 600 - "from": "graphql/language/predicates" 601 - }, 602 - "isTypeSubTypeOf": { 603 - "local": "isTypeSubTypeOf", 604 - "from": "graphql/utilities/typeComparators" 605 - }, 606 - "isTypeSystemDefinitionNode": { 607 - "local": "isTypeSystemDefinitionNode", 608 - "from": "graphql/language/predicates" 609 - }, 610 - "isTypeSystemExtensionNode": { 611 - "local": "isTypeSystemExtensionNode", 612 - "from": "graphql/language/predicates" 613 - }, 614 - "isUnionType": { 615 - "local": "isUnionType", 616 - "from": "graphql/type/definition" 617 - }, 618 - "isValidNameError": { 619 - "local": "isValidNameError", 620 - "from": "graphql/utilities/assertValidName" 621 - }, 622 - "isValueNode": { 623 - "local": "isValueNode", 624 - "from": "graphql/language/predicates" 625 - }, 626 - "isWrappingType": { 627 - "local": "isWrappingType", 628 - "from": "graphql/type/definition" 629 - }, 630 - "locatedError": { 631 - "local": "locatedError", 632 - "from": "graphql/error/locatedError" 633 - }, 634 - "parse": { 635 - "local": "parse", 636 - "from": "graphql/language/parser" 637 - }, 638 - "parseType": { 639 - "local": "parseType", 640 - "from": "graphql/language/parser" 641 - }, 642 - "parseValue": { 643 - "local": "parseValue", 644 - "from": "graphql/language/parser" 645 - }, 646 - "print": { 647 - "local": "print", 648 - "from": "graphql/language/printer" 649 - }, 650 - "printError": { 651 - "local": "printError", 652 - "from": "graphql/error/GraphQLError" 653 - }, 654 - "printLocation": { 655 - "local": "printLocation", 656 - "from": "graphql/language/printLocation" 657 - }, 658 - "printSourceLocation": { 659 - "local": "printSourceLocation", 660 - "from": "graphql/language/printLocation" 661 - }, 662 - "responsePathAsArray": { 663 - "local": "pathToArray", 664 - "from": "graphql/jsutils/Path" 665 - }, 666 - "separateOperations": { 667 - "local": "separateOperations", 668 - "from": "graphql/utilities/separateOperations" 669 - }, 670 - "specifiedDirectives": { 671 - "local": "specifiedDirectives", 672 - "from": "graphql/type/directives" 673 - }, 674 - "specifiedRules": { 675 - "local": "specifiedRules", 676 - "from": "graphql/validation/specifiedRules" 677 - }, 678 - "specifiedScalarTypes": { 679 - "local": "specifiedScalarTypes", 680 - "from": "graphql/type/scalars" 681 - }, 682 - "stripIgnoredCharacters": { 683 - "local": "stripIgnoredCharacters", 684 - "from": "graphql/utilities/stripIgnoredCharacters" 685 - }, 686 - "subscribe": { 687 - "local": "subscribe", 688 - "from": "graphql/subscription/subscribe" 689 - }, 690 - "typeFromAST": { 691 - "local": "typeFromAST", 692 - "from": "graphql/utilities/typeFromAST" 693 - }, 694 - "validate": { 695 - "local": "validate", 696 - "from": "graphql/validation/validate" 697 - }, 698 - "validateSchema": { 699 - "local": "validateSchema", 700 - "from": "graphql/type/validate" 701 - }, 702 - "valueFromAST": { 703 - "local": "valueFromAST", 704 - "from": "graphql/utilities/valueFromAST" 705 - }, 706 - "valueFromASTUntyped": { 707 - "local": "valueFromASTUntyped", 708 - "from": "graphql/utilities/valueFromASTUntyped" 709 - }, 710 - "version": { 711 - "local": "version", 712 - "from": "graphql/version" 713 - }, 714 - "versionInfo": { 715 - "local": "versionInfo", 716 - "from": "graphql/version" 717 - }, 718 - "visit": { 719 - "local": "visit", 720 - "from": "graphql/language/visitor" 721 - }, 722 - "visitInParallel": { 723 - "local": "visitInParallel", 724 - "from": "graphql/language/visitor" 725 - }, 726 - "visitWithTypeInfo": { 727 - "local": "visitWithTypeInfo", 728 - "from": "graphql/utilities/TypeInfo" 729 - } 730 - }
+136
scripts/rollup/importMap.mjs
··· 1 + import * as path from 'path'; 2 + import { nodeResolve } from '@rollup/plugin-node-resolve'; 3 + import { rollup } from 'rollup'; 4 + 5 + /** Generates a map of exports from a given graphql package to list of import locations. */ 6 + async function traceImports(moduleName) { 7 + const basepath = path.resolve(process.cwd(), 'node_modules/', moduleName); 8 + const exportMap = {}; 9 + 10 + const resolveFile = (to, relative = '.') => { 11 + const dirname = path.join('graphql/', relative, path.dirname(to)); 12 + const filename = path.basename(to, '.mjs'); 13 + return path.join(dirname, filename); 14 + }; 15 + 16 + const bundle = await rollup({ 17 + // This contains all top-level "sub-modules" of graphql too, since not all exports of 18 + // them may be exposed in the main index.mjs file. 19 + input: { 20 + graphql: path.join(basepath, 'index.mjs'), 21 + 'graphql/error': path.join(basepath, 'error/index.mjs'), 22 + 'graphql/execution': path.join(basepath, 'execution/index.mjs'), 23 + 'graphql/language': path.join(basepath, 'language/index.mjs'), 24 + 'graphql/subscription': path.join(basepath, 'subscription/index.mjs'), 25 + 'graphql/type': path.join(basepath, 'type/index.mjs'), 26 + 'graphql/utilities': path.join(basepath, 'utilities/index.mjs'), 27 + 'graphql/validation': path.join(basepath, 'validation/index.mjs'), 28 + }, 29 + shimMissingExports: false, 30 + preserveEntrySignatures: 'allow-extension', 31 + preserveSymlinks: true, 32 + external: id => !/^\.{0,2}\//.test(id), 33 + plugins: [ 34 + nodeResolve(), 35 + { 36 + transform(code, id) { 37 + const relative = path.relative(basepath, id); 38 + const dirname = path.dirname(relative); 39 + const exports = {}; 40 + 41 + this.parse(code) 42 + .body.filter(x => x.type === 'ExportNamedDeclaration') 43 + .forEach(node => { 44 + const from = node.source 45 + ? resolveFile(node.source.value, dirname) 46 + : resolveFile(relative); 47 + 48 + node.specifiers.forEach(specifier => { 49 + const { name: local } = specifier.exported; 50 + exports[local] = { local, from }; 51 + }); 52 + 53 + if (node.declaration) { 54 + (node.declaration.declarations || [node.declaration]).forEach(declaration => { 55 + if (declaration && declaration.id) { 56 + const { name: local } = declaration.id; 57 + exports[local] = { local, from }; 58 + } 59 + }); 60 + } 61 + }); 62 + 63 + exportMap[resolveFile(relative)] = exports; 64 + return null; 65 + }, 66 + }, 67 + ], 68 + }); 69 + 70 + await bundle.generate({}); 71 + return exportMap; 72 + } 73 + 74 + function isDeclarationEqual(a, b) { 75 + return a.local === b.local && a.from === b.from; 76 + } 77 + 78 + function mergeTraces(traces) { 79 + const trace = {}; 80 + 81 + // Iterate over all known filenames in all traces 82 + const ids = new Set( 83 + traces.map(trace => Object.keys(trace)).reduce((acc, names) => acc.concat(names), []) 84 + ); 85 + for (const id of ids) { 86 + // Each file must exist in all traces 87 + if (!traces.every(trace => !!trace[id])) continue; 88 + 89 + const exports = {}; 90 + 91 + // Iterate over all known exports in each trace's set of exports for this file 92 + const exportNames = new Set( 93 + traces.map(trace => Object.keys(trace[id])).reduce((acc, names) => acc.concat(names), []) 94 + ); 95 + for (const name of exportNames) { 96 + // Each export must exist in all traces 97 + if (traces.every(trace => !!trace[id][name])) { 98 + // Collect known declarations and deduplicate 99 + exports[name] = traces 100 + .map(trace => trace[id][name]) 101 + .filter((val, index, all) => { 102 + const firstIndex = all.findIndex(item => isDeclarationEqual(item, val)); 103 + return firstIndex === index; 104 + }); 105 + } 106 + } 107 + 108 + if (Object.keys(exports).length) trace[id] = exports; 109 + } 110 + 111 + // For a given declaration, find the first deepest one that works for the trace 112 + // NOTE: This doesn't find the absolute deepest one, since it assumes that each 113 + // export only has one functional trace 114 + const resolveDeclaration = declaration => { 115 + const declarations = trace[declaration.from]; 116 + if (!declarations || !declarations[declaration.local]) return null; 117 + for (const childDeclaration of declarations[declaration.local]) { 118 + if (childDeclaration.from === declaration.from) continue; 119 + const resolved = resolveDeclaration(childDeclaration); 120 + if (resolved && resolved.from !== declaration.from) return resolved; 121 + } 122 + 123 + return declaration; 124 + }; 125 + 126 + // Resolve all known (and consistent) exports to a common, deepest declaration 127 + const ROOT_MODULE = 'graphql/index'; 128 + const exports = {}; 129 + for (const local in trace[ROOT_MODULE]) 130 + exports[local] = resolveDeclaration({ local, from: ROOT_MODULE }); 131 + return exports; 132 + } 133 + 134 + export async function generateImportMap() { 135 + return mergeTraces(await Promise.all([traceImports('graphql'), traceImports('graphql15')])); 136 + }
-5
scripts/rollup/packageMetadata.mjs
··· 1 1 import semver from 'semver'; 2 - import * as url from 'url'; 3 - import * as path from 'path'; 4 2 import { createRequire } from 'node:module'; 5 3 6 - const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); 7 4 const require = createRequire(import.meta.url); 8 5 9 6 const rootPkg = require('../../package.json'); ··· 39 36 null, 40 37 2 41 38 ); 42 - 43 - export const importMap = require('./importMap.json');