Skip to content

Commit

Permalink
Fix error reporting bug
Browse files Browse the repository at this point in the history
  • Loading branch information
captbaritone committed Dec 23, 2023
1 parent 7dbad5a commit 7f2bada
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export default class SomeType {
-----------------
OUTPUT
-----------------
src/tests/fixtures/field_values/OptionalStringFieldKillsParentOnException.invalid.ts:5:7 - error: Unexpected `@killsParentOnException` tag. `@killsParentOnException` is unnecessary on fields that are already nullable.
src/tests/fixtures/field_values/OptionalStringFieldKillsParentOnException.invalid.ts:5:6 - error: Unexpected `@killsParentOnException` tag on field typed as nullable. `@killsParentOnException` will force a field to appear as non-nullable in the schema, so it's implementation must also be non-nullable. .

5 * @killsParentOnException
~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
6 */
~~~
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ OUTPUT
-----------------
-- SDL --
type SomeType {
hello: String!
hello: String! @killsParentOnException
}
-- TypeScript --
import { GraphQLSchema, GraphQLObjectType, GraphQLNonNull, GraphQLString } from "graphql";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default class SomeType {
-----------------
OUTPUT
-----------------
src/tests/fixtures/field_values/StringFieldKillsParentOnExceptionWithoutNullableByDefaultEnables.invalid.ts:6:7 - error: Unexpected `@killsParentOnException` tag. `@killsParentOnException` is only supported when the Grats config option `nullableByDefault` is enabled in your `tsconfig.json`.
src/tests/fixtures/field_values/StringFieldKillsParentOnExceptionWithoutNullableByDefaultEnables.invalid.ts:6:6 - error: Unexpected `@killsParentOnException` tag. `@killsParentOnException` is only supported when the Grats config option `nullableByDefault` is enabled in your `tsconfig.json`.

6 * @killsParentOnException
~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
7 */
~~~
5 changes: 2 additions & 3 deletions src/transforms/applyDefaultNullability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ export function applyDefaultNullability(
}
// You can only use @killsParentOnException if nullableByDefault is on.
if (!nullableByDefault) {
this.report(
killsParent.loc,
E.killsParentOnExceptionWithWrongConfig(),
errors.push(
gqlErr(killsParent.loc, E.killsParentOnExceptionWithWrongConfig()),
);
}
// You can't use @killsParentOnException if it's been typed as nullable
Expand Down

0 comments on commit 7f2bada

Please sign in to comment.