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

Improve output of GraphQL parser replacement

Changed files
+20 -20
alias
language
+15 -15
alias/language/parser.mjs
···
import { match, parse as makeParser } from 'reghex';
// 2.1.7: Includes commas, and line comments
-
const ignored = match('_ignored')`
+
const ignored = match()`
${/([\s,]|#[^\n\r]+)+/}
`;
···
// 2.9.1-2: These combine both number values for the sake of simplicity.
// It allows for leading zeroes, unlike graphql.js, which shouldn't matter;
-
const number = match('_number', x => ({
+
const number = match(null, x => ({
kind: x.length === 1 ? Kind.INT : Kind.FLOAT,
value: x.join('')
}))`
···
`;
// 2.9: This matches the spec closely and is complete
-
const value = match('_value', x => x[0])`
+
const value = match(null, x => x[0])`
:${ignored}?
(
${null_}
···
${value}
`;
-
const args = match('_argumentset')`
+
const args = match()`
:${ignored}?
(
(?: ${'('} ${ignored}?)
···
:${ignored}?
`;
-
const directives = match('_directiveset')`
+
const directives = match()`
:${ignored}?
${directive}*
`;
···
// 2.11: The type declarations may be simplified since there's little room
// for error in this limited type system.
-
const type = match('_type', x => {
+
const type = match(null, x => {
const node = x[0].kind === 'Name'
? { kind: Kind.NAMED_TYPE, name: x[0] }
: { kind: Kind.LIST_TYPE, type: x[0] }
···
:${ignored}?
`;
-
const typeCondition = match('_typecondition', x => ({
+
const typeCondition = match(null, x => ({
kind: Kind.NAMED_TYPE,
name: x[0]
}))`
···
let i = 0;
return {
kind: x.tag,
-
typeCondition: x[i].tag === '_typecondition' ? x[i++] : undefined,
+
typeCondition: x[i].kind === Kind.NAMED_TYPE ? x[i++] : undefined,
directives: x[i++],
selectionSet: x[i]
};
···
const selectionSet = match(Kind.SELECTION_SET, x => ({
kind: x.tag,
-
selections:x,
+
selections: x.slice(),
}))`
(?: ${'{'} ${ignored}?)
(
···
(?: ${'}'} ${ignored}?)
`;
-
const varDefinitionDefault = match('_defaultvariable', x => x[0])`
+
const varDefinitionDefault = match(null, x => x[0])`
(?: ${'='} ${ignored}?)
${value}
`;
···
kind: x.tag,
variable: x[0],
type: x[1],
-
defaultValue: !x[2].tag ? x[2] : undefined,
-
directives: x[2].tag ? x[2] : x[3],
+
defaultValue: x[2].kind ? x[2] : undefined,
+
directives: !x[2].kind ? x[2] : x[3],
}))`
${variable}
(?: ${ignored}? ${':'} ${ignored}?)
···
:${ignored}?
`;
-
const varDefinitions = match('_variabledefinitionset')`
+
const varDefinitions = match('vars')`
(?: ${'('} ${ignored}?)
${varDefinition}+
(?: ${')'} ${ignored}?)
···
kind: x.tag,
operation: x[0],
name: x.length === 5 ? x[i++] : undefined,
-
variableDefinitions: x[i].tag === '_variabledefinitionset' ? x[i++] : null,
+
variableDefinitions: x[i].tag === 'vars' ? x[i++].slice() : null,
directives: x[i++],
selectionSet: x[i],
};
···
const root = match(Kind.DOCUMENT, x => (
x.length
-
? { kind: x.tag, definitions: x }
+
? { kind: x.tag, definitions: x.slice() }
: undefined
))`
${queryShorthand}
+1 -1
package.json
···
"babel-plugin-modular-graphql": "^1.0.1",
"graphql": "^16.0.0-alpha.5",
"jest": "^27.0.6",
-
"reghex": "^3.0.1",
+
"reghex": "^3.0.2",
"rollup": "^2.56.2",
"rollup-plugin-terser": "^7.0.2"
}
+4 -4
yarn.lock
···
unicode-match-property-ecmascript "^1.0.4"
unicode-match-property-value-ecmascript "^1.1.0"
-
reghex@^3.0.1:
-
version "3.0.1"
-
resolved "https://registry.yarnpkg.com/reghex/-/reghex-3.0.1.tgz#76dd93c0ebef17dfbff0ea6705e9ee764eb36717"
-
integrity sha512-4EVlR7D9BMSUcCVtU2LO6iRzcxwgwlQgHa2MBMlHu39SGswa2FueAqVV+LtUNmpm1+eySVeH+04vI4Zaqg9Q2A==
+
reghex@^3.0.2:
+
version "3.0.2"
+
resolved "https://registry.yarnpkg.com/reghex/-/reghex-3.0.2.tgz#984045126642ee0709c3e10727e7041112281330"
+
integrity sha512-Zb9DJ5u6GhgqRSBnxV2QSnLqEwcKxHWFA1N2yUa4ZUAO1P8jlWKYtWZ6/ooV6yylspGXJX0O/uNzEv0xrCtwaA==
regjsgen@^0.5.0:
version "0.5.2"