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

Shim bloated utilities of graphql/language

Changed files
+46 -12
alias
scripts
rollup
+13
alias/language/blockString.mjs
···
+
export function printBlockString(str) {
+
return '"""\n' +
+
JSON.stringify(str).slice(1, -1)
+
+ '\n"""';
+
}
+
+
export function dedentBlockStringValue(str) {
+
return str;
+
}
+
+
export function getBlockStringIndentation(str) {
+
return 0;
+
}
+15
alias/language/printLocation.mjs
···
+
import { getLocation } from 'graphql/language/location';
+
+
export function printLocation(location) {
+
return printSourceLocation(
+
location.source,
+
getLocation(location.source, location.start),
+
);
+
}
+
+
export function printSourceLocation(source, sourceLocation) {
+
const firstLineColumnOffset = source.locationOffset.column - 1;
+
const lineNum = sourceLocation.line + source.locationOffset.line - 1;
+
const columnNum = sourceLocation.column + sourceLocation.line === 1 ? firstLineColumnOffset : 0;
+
return `${source.name}:${lineNum}:${columnNum}`;
+
}
+1
alias/language/printString.mjs
···
+
export const printString = JSON.stringify;
+17 -12
scripts/rollup/config.mjs
···
import { terser } from 'rollup-plugin-terser';
const cwd = process.cwd();
-
const base = path.join(cwd, 'node_modules/graphql/');
-
const baseAlias = path.join(cwd, 'alias/');
const externalModules = ['dns', 'fs', 'path', 'url'];
const externalPredicate = new RegExp(`^(${externalModules.join('|')})($|/)`);
···
...config,
shimMissingExports: true,
plugins: [
+
{
+
async resolveId(source, importer) {
+
if (source.startsWith('.') && importer) {
+
source = path.resolve(path.dirname(importer), source);
+
}
+
+
const base = path.join(cwd, 'node_modules/graphql/');
+
const baseSource = path.relative(base, source);
+
if (baseSource.startsWith('..')) {
+
return null;
+
}
+
+
const aliasSource = path.join(cwd, 'alias/', baseSource);
+
return this.resolve(aliasSource, importer, { skipSelf: true });
+
},
+
},
+
resolve({
extensions: ['.mjs', '.js'],
mainFields: ['module', 'browser', 'main'],
···
babel({
babelrc: false,
babelHelpers: 'bundled',
-
exclude: 'node_modules/**',
presets: [],
plugins: [
'babel-plugin-modular-graphql',
'reghex/babel',
],
}),
-
-
{
-
async resolveId(source, importer) {
-
const baseSource = path.relative(base, source);
-
if (baseSource.startsWith('..')) return null;
-
const aliasSource = path.join(baseAlias, baseSource);
-
return this.resolve(aliasSource, importer, { skipSelf: true });
-
},
-
},
],
output: [