MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeTestMethod

Function makeTestMethod

packages/effect/src/graphql/GraphQLClient.ts:904–926  ·  view source on GitHub ↗
(operation: GraphQL.Any, handler: ErasedTestHandler | undefined)

Source from the content-addressed store, hash-verified

902type ErasedTestHandler = (variables: unknown, options: TestCallOptions) => unknown
903
904const 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}

Callers 1

makeTestFunction · 0.85

Calls 1

assignMethod · 0.80

Tested by

no test coverage detected