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

Fix discrepancies in parser

Changed files
+16 -18
alias
language
+16 -18
alias/language/parser.mjs
···
import { match, parse as makeParser } from 'reghex';
// 2.1.7: Includes commas, and line comments
-
const ignored = match()`
-
${/([\s,]|#[^\n\r]+)+/}
-
`;
// 2.1.9: Limited to ASCII character set, so regex shortcodes are fine
const name = match(Kind.NAME, (x) => ({
···
kind: x.tag,
value: x[0] === 'true',
}))`
-
${'true'} | ${'false'}
`;
const variable = match(Kind.VARIABLE, (x) => ({
···
const list = match(Kind.LIST, (x) => ({
kind: x.tag,
-
values: x,
}))`
-
(?: ${'['} ${ignored}?)
${value}*
-
(?: ${']'} ${ignored}?)
`;
const objectField = match(Kind.OBJECT_FIELD, (x) => ({
···
name: x[0],
value: x[1],
}))`
${name}
-
(?: ${ignored} ${/:/} ${ignored})?
${value}
-
(?: ${ignored})?
`;
const object = match(Kind.OBJECT, (x) => ({
kind: x.tag,
-
fields: x,
}))`
-
(?: ${'{'} ${ignored}?)
${objectField}*
(?: ${'}'} ${ignored}?)
`;
···
kind: Kind.NAMED_TYPE,
name: x[0],
}))`
-
(?: ${ignored} ${'on'} ${ignored})
${name}
:${ignored}?
`;
···
selectionSet: x[i],
};
})`
-
(?: ${'...'} ${ignored}?)
${typeCondition}?
${directives}
${selectionSet}
···
kind: x.tag,
selections: x.slice(),
}))`
(?: ${'{'} ${ignored}?)
(
${inlineFragment} |
···
`;
const varDefinitions = match('vars')`
(?: ${'('} ${ignored}?)
${varDefinition}+
(?: ${')'} ${ignored}?)
···
return {
kind: x.tag,
operation: x[0],
-
name: x.length === 5 ? x[i++] : undefined,
-
variableDefinitions: x[i].tag === 'vars' ? x[i++].slice() : null,
directives: x[i++],
selectionSet: x[i],
};
})`
:${ignored}?
${/query|mutation|subscription/}
-
((?: ${ignored}) ${name})?
-
:${ignored}?
${varDefinitions}?
${directives}
${selectionSet}
···
directives: [],
selectionSet: x[0],
}))`
-
:${ignored}?
${selectionSet}
`;
···
import { match, parse as makeParser } from 'reghex';
// 2.1.7: Includes commas, and line comments
+
const ignored = /([\s,]|#[^\n\r]+)+/;
// 2.1.9: Limited to ASCII character set, so regex shortcodes are fine
const name = match(Kind.NAME, (x) => ({
···
kind: x.tag,
value: x[0] === 'true',
}))`
+
${/true|false/}
`;
const variable = match(Kind.VARIABLE, (x) => ({
···
const list = match(Kind.LIST, (x) => ({
kind: x.tag,
+
values: x.slice(),
}))`
+
:${'['}
${value}*
+
(?: ${ignored}? ${']'} ${ignored}?)
`;
const objectField = match(Kind.OBJECT_FIELD, (x) => ({
···
name: x[0],
value: x[1],
}))`
+
:${ignored}?
${name}
+
(?: ${ignored}? ${':'})
${value}
`;
const object = match(Kind.OBJECT, (x) => ({
kind: x.tag,
+
fields: x.slice(),
}))`
+
:${'{'}
${objectField}*
(?: ${'}'} ${ignored}?)
`;
···
kind: Kind.NAMED_TYPE,
name: x[0],
}))`
+
(?: ${ignored}? ${'on'} ${ignored})
${name}
:${ignored}?
`;
···
selectionSet: x[i],
};
})`
+
:${'...'}
${typeCondition}?
${directives}
${selectionSet}
···
kind: x.tag,
selections: x.slice(),
}))`
+
:${ignored}?
(?: ${'{'} ${ignored}?)
(
${inlineFragment} |
···
`;
const varDefinitions = match('vars')`
+
:${ignored}?
(?: ${'('} ${ignored}?)
${varDefinition}+
(?: ${')'} ${ignored}?)
···
return {
kind: x.tag,
operation: x[0],
+
name: x[i].kind === Kind.NAME ? x[i++] : undefined,
+
variableDefinitions: x[i].tag === 'vars' ? x[i++].slice() : [],
directives: x[i++],
selectionSet: x[i],
};
})`
:${ignored}?
${/query|mutation|subscription/}
+
(:${ignored} ${name})?
${varDefinitions}?
${directives}
${selectionSet}
···
directives: [],
selectionSet: x[0],
}))`
${selectionSet}
`;