-
Notifications
You must be signed in to change notification settings - Fork 108
Closed
Description
While not an error of Zeus strictly speaking, the client does not succeed in building specific malformed queries:
// Valid query
me: {
id: true,
contacts: { // Contact does not expect arguments
id: true,
name: true
}
}
// Crashes Zeus at runtime with a cryptic error
me: {
id: true,
contacts: [{}, {
id: true,
name: true
}]
}
I'd like either the types to be stricter (because the invalid query is not reported at compile-time) or the runtime error to be more explicit (see below for proposal).
const ResolveReturnType = (mappedParts: Part[]) => {
if (mappedParts.length === 0) {
return 'not';
}
const oKey = ops[mappedParts[0].v];
const returnP1 = oKey ? returns[oKey] : returns[mappedParts[0].v];
if (typeof returnP1 === 'object') {
+ if (!mappedParts[1]) throw new Error(`${mappedParts[0].v} does not take arguments`);
+ // Proposal: ^ Explicit runtime error
const returnP2 = returnP1[mappedParts[1].v];
// ^^^ This thing does not exist if the field is not expecting args
if (returnP2) {
// ...
I'll submit a PR with the addition
Metadata
Metadata
Assignees
Labels
No labels