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

Fix up parsing bugs in Variable and Field nodes

Changed files
+37 -18
alias
language
+32 -13
alias/language/parser.mjs
···
* in graphql.js it will only parse the query language, but not the schema
* language.
*/
-
import { Kind } from 'graphql';
import { match, parse as makeParser } from 'reghex';
// 2.1.7: Includes commas, and line comments
···
const variable = match(Kind.VARIABLE, x => ({
kind: x.tag,
-
value: x[0]
}))`
:${'$'} ${name}
`;
···
`;
const args = match('_argumentset')`
(
(?: ${'('} ${ignored}?)
${arg}+
···
let i = 0;
return {
kind: x.tag,
-
alias: x[1].kind === 'Name' ? x[i++] : undefined,
name: x[i++],
arguments: x[i++],
directives: x[i++],
selectionSet: x[i++],
};
})`
${name}
-
:${ignored}?
-
((?: ${':'} ${ignored}?) ${name})?
-
:${ignored}?
${args}
${directives}
${selectionSet}?
···
kind: Kind.NAMED_TYPE,
name: x[0]
}))`
-
(?: ${'on'} ${ignored})
${name}
:${ignored}?
`;
···
directives: x[2],
selectionSet: x[3],
}))`
-
(?: ${'fragment'} ${ignored})
-
!${'on'}
${name}
-
:${ignored}
${typeCondition}
${directives}
${selectionSet}
···
| (${operationDefinition} | ${fragmentDefinition})+
`;
-
export const parse = makeParser(root);
-
export const parseValue = makeParser(value);
-
export const parseType = makeParser(type);
···
* in graphql.js it will only parse the query language, but not the schema
* language.
*/
+
import { Kind, GraphQLError } from 'graphql';
import { match, parse as makeParser } from 'reghex';
// 2.1.7: Includes commas, and line comments
···
const variable = match(Kind.VARIABLE, x => ({
kind: x.tag,
+
name: x[0]
}))`
:${'$'} ${name}
`;
···
`;
const args = match('_argumentset')`
+
:${ignored}?
(
(?: ${'('} ${ignored}?)
${arg}+
···
let i = 0;
return {
kind: x.tag,
+
alias: x[1].kind === Kind.NAME ? x[i++] : undefined,
name: x[i++],
arguments: x[i++],
directives: x[i++],
selectionSet: x[i++],
};
})`
+
:${ignored}?
${name}
+
(
+
(?: ${ignored}? ${':'} ${ignored}?)
+
${name}
+
)?
${args}
${directives}
${selectionSet}?
···
kind: Kind.NAMED_TYPE,
name: x[0]
}))`
+
(?: ${ignored} ${'on'} ${ignored})
${name}
:${ignored}?
`;
···
directives: x[2],
selectionSet: x[3],
}))`
+
(?: ${ignored}? ${'fragment'} ${ignored})
${name}
${typeCondition}
${directives}
${selectionSet}
···
| (${operationDefinition} | ${fragmentDefinition})+
`;
+
const _parse = makeParser(root);
+
const _parseValue = makeParser(value);
+
const _parseType = makeParser(type);
+
+
export function parse(input) {
+
const result = _parse(input);
+
if (result == null) throw new GraphQLError('Syntax Error');
+
return result;
+
}
+
+
export function parseValue(input) {
+
const result = _parseValue(input);
+
if (result == null) throw new GraphQLError('Syntax Error');
+
return result;
+
}
+
+
export function parseType(input) {
+
const result = _parseType(input);
+
if (result == null) throw new GraphQLError('Syntax Error');
+
return result;
+
}
+1 -1
package.json
···
"babel-plugin-modular-graphql": "^1.0.1",
"graphql": "^16.0.0-alpha.5",
"jest": "^27.0.6",
-
"reghex": "^3.0.0",
"rollup": "^2.56.2",
"rollup-plugin-terser": "^7.0.2"
}
···
"babel-plugin-modular-graphql": "^1.0.1",
"graphql": "^16.0.0-alpha.5",
"jest": "^27.0.6",
+
"reghex": "^3.0.1",
"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.0:
-
version "3.0.0"
-
resolved "https://registry.yarnpkg.com/reghex/-/reghex-3.0.0.tgz#8121a96a75c81bd3996e94255760f98db0d7f3c0"
-
integrity sha512-CWL9oEFQBq1PF3iT4GjSz7Te/OuLFYYHWS5/lCyxmMFncsr4Cxi/aapgmEF1AiqodEHI16t0cu1A/B/O78NUcA==
regjsgen@^0.5.0:
version "0.5.2"
···
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==
regjsgen@^0.5.0:
version "0.5.2"