Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
GauBen opened this issue Jun 28, 2022 · 0 comments · Fixed by #315
Closed

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

GauBen opened this issue Jun 28, 2022 · 0 comments · Fixed by #315

Comments

@GauBen
Copy link
Contributor

GauBen commented Jun 28, 2022

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

GauBen added a commit to GauBen/graphql-zeus that referenced this issue Jun 28, 2022
aexol added a commit that referenced this issue Sep 1, 2022
@aexol aexol closed this as completed in #315 Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant