Skip to content

Commit

Permalink
Remove unnecessary invariant in favor of explicit cast
Browse files Browse the repository at this point in the history
See open TS issue microsoft/TypeScript#31613

Marked with FIXME for when TS feature/bug fix lands upstream

[This code will likely be removed in v17 prior to the feature landing, but may be retained within v16 for longer.]

Similar code "works" at https:/graphql/graphql-js/blob/1f8ba95c662118452bd969c6b26ba4e9050c55da/src/error/GraphQLError.ts#L47 because all the option properties are optional.
  • Loading branch information
yaacovCR committed Jun 10, 2022
1 parent 120ae79 commit c39e0f3
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/execution/subscribe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { inspect } from '../jsutils/inspect';
import { invariant } from '../jsutils/invariant';
import { isAsyncIterable } from '../jsutils/isAsyncIterable';
import { isPromise } from '../jsutils/isPromise';
import type { Maybe } from '../jsutils/Maybe';
Expand Down Expand Up @@ -108,11 +107,10 @@ function toNormalizedArgs(args: BackwardsCompatibleArgs): ExecutionArgs {
return firstArg;
}

invariant(args[1] != null, 'Must provide document.');

return {
schema: firstArg,
document: args[1],
// FIXME: when underlying TS bug fixed, see https:/microsoft/TypeScript/issues/31613
document: args[1] as DocumentNode,
rootValue: args[2],
contextValue: args[3],
variableValues: args[4],
Expand Down

0 comments on commit c39e0f3

Please sign in to comment.