Urigo / graphql-scalars

A library of custom GraphQL Scalars for creating precise type-safe GraphQL schemas.
https://www.the-guild.dev/graphql/scalars
MIT License
1.88k stars 133 forks source link

fix(JSONObject): Throw proper error if literal is not an object #2284

Closed tjenkinson closed 7 months ago

tjenkinson commented 7 months ago

Description

This PR handles the literal for JSONObject not being an object and throws a proper error.

Related #2285

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

In my local project I copied the dist/esm dir into my node modules and verified the error is now correct.

It now looks like

"JSONObject cannot represent non-object value: \"test\""

instead of

"Expected value of type \"JSONObject\", found \"test\"; Cannot read properties of undefined (reading 'forEach')"

Test Environment:

Checklist: