question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

computedTypesResolver does not work with nested fields

See original GitHub issue

Describe the bug

I have a schema like so:

const schema = Schema({
  top: string.min(100),

  nested: Schema({
    value: string.min(100),
  }),
})

Errors in the top-level fields are reported correctly, while errors in nested fields are lost.

To Reproduce

  1. Go to https://codesandbox.io/s/react-hook-form-computed-types-nested-fields-validation-error-bug-9uuuuq?file=/src/index.jsx
  2. Run
  3. See in the console how the error on the ‘top’ field is reported but not on the nested field.

Codesandbox link (Required)

https://codesandbox.io/s/react-hook-form-computed-types-nested-fields-validation-error-bug-9uuuuq?file=/src/index.jsx

Additional context

Not sure what the expected shape of FieldErrors should be, if it should be a nested object or flat where keys are dot-separated field paths. If the later then fixing computedTypesResolver can be as easy as changing parseErrorSchema like so:

const parseErrorSchema = (computedTypesError: ValidationError): FieldErrors => {
  const parsedErrors: FieldErrors = {};

  for (const { path, error } of computedTypesError.errors || []) {
    parsedErrors[path.join(".")] = {
      type: error.name,
      message: error.message,
    };
  }

  return parsedErrors;
};

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bluebill1049commented, Mar 20, 2022

The way errors get parsed is pretty much like get/set method.

test.test.test

to become

{test: {test: test{}}}

0reactions
bluebill1049commented, Apr 27, 2022

any update on this issue? or is there anything we can need to patch for resolver?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested fields issue · Issue #154 · graphql/graphql-js - GitHub
Consider following code: Schema: const userType = new GraphQLObjectType({ name: 'User', description: 'User type', fields: () => ({ id: ...
Read more >
Advanced topics on federated entities - Apollo GraphQL Docs
This article describes complex behaviors of federated entities beyond those covered in entity basics. Advanced @key s. A single entity can have multiple ......
Read more >
Invoke resolvers of fields on nested execution levels in NestJS ...
I'm building a GraphQL API in NestJS supporting queries for nested objects, but I don't know how to invoke existing resolvers on an ......
Read more >
Resolvers | NestJS - A progressive Node.js framework
In this approach, keep your models ( ObjectType classes), resolvers and services together within a Nest module representing the domain model.
Read more >
Custom Value Resolvers - AutoMapper documentation
The default generated code for resolving a property, if you haven't customized the mapping for that member, generally doesn't have any problems. But...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found