| 902 | type ErasedTestHandler = (variables: unknown, options: TestCallOptions) => unknown |
| 903 | |
| 904 | const makeTestMethod = (operation: GraphQL.Any, handler: ErasedTestHandler | undefined) => { |
| 905 | const subscription = operation.kind === "subscription" |
| 906 | if (handler === undefined) { |
| 907 | const unimplemented = () => { |
| 908 | const prevLimit = getStackTraceLimit() |
| 909 | setStackTraceLimit(2) |
| 910 | const error = new Error(`GraphQLClient: Unimplemented operation "${operation.name}"`) |
| 911 | setStackTraceLimit(prevLimit) |
| 912 | error.name = "UnimplementedError" |
| 913 | return subscription ? Stream.die(error) : Effect.die(error) |
| 914 | } |
| 915 | return Object.assign(unimplemented, { operation }) |
| 916 | } |
| 917 | const call = (variables: unknown, options: (TestCallOptions & { readonly partial?: boolean }) | undefined) => { |
| 918 | const run = () => handler(variables === undefined ? {} : variables, options ?? {}) |
| 919 | if (subscription) return Stream.suspend(run as () => Stream.Stream<unknown, unknown>) |
| 920 | const result = Effect.suspend(run as () => Effect.Effect<unknown, unknown>) |
| 921 | return options?.partial === true |
| 922 | ? Effect.map(result, (data): PartialResult<unknown> => ({ data, errors: [] })) |
| 923 | : result |
| 924 | } |
| 925 | return Object.assign(call, { operation }) |
| 926 | } |