Skip to content

TypeError: undefined is not an object (evaluating 't[1].v') #314

@GauBen

Description

@GauBen

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) {
        // ...

Link

I'll submit a PR with the addition

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions