graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

MockStore find and filter fail if no items have ever been added for the type

Open snstanton opened this issue 1 year ago • 0 comments
trafficstars

Issue workflow progress

Progress of the issue based on the Contributor Workflow

  • [x] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox

    see the test cases

  • [x] 2. A failing test has been provided
  • [x] 3. A local solution has been provided
  • [x] 4. A pull request is pending review

Describe the bug

If the store does not have an entry for typeName yet, then filter() or find() of the type raises: TypeError: Cannot convert undefined or null to object

To Reproduce Steps to reproduce the behavior:

Create a MockStore with no entries. Call store.filter('foo', x => true) and see the exception

Expected behavior

It should return an empty array instead of raising an exception.

Environment:

  • OS: macos
  • @graphql-tools/mock: 9.0.3
  • NodeJS: v22.2.0

Additional context

snstanton avatar Jun 13 '24 18:06 snstanton