export class YogaApp extends Effect.Service<YogaApp>()("YogaApp", {
effect: Effect.gen(function* () {
const config = yield* GraphqlConfig;
const runPromise = yield* FiberSet.makeRuntimePromise<GrpcService>();
const yoga = createYoga({
schema,
context: async (initialContext) => {
const requestCache = Request.makeCache({
capacity: 1000,
timeToLive: Duration.infinity,
});
const wrappedRunPromise = <A, E, R extends GrpcService>(
effect: Effect.Effect<A, E, R>,
) =>
runPromise(
effect.pipe(
Effect.provide(Layer.setRequestCache(requestCache)),
Effect.withRequestCaching(true),
Effect.withRequestBatching(true),
),
);
return createGraphQLContext(
initialContext,
withErrorHandlingAndLogging(wrappedRunPromise),
);
},
graphqlEndpoint: config.endpoint,
});
// ... rest of setup
}),
}) {}
export class YogaApp extends Effect.Service<YogaApp>()("YogaApp", {
effect: Effect.gen(function* () {
const config = yield* GraphqlConfig;
const runPromise = yield* FiberSet.makeRuntimePromise<GrpcService>();
const yoga = createYoga({
schema,
context: async (initialContext) => {
const requestCache = Request.makeCache({
capacity: 1000,
timeToLive: Duration.infinity,
});
const wrappedRunPromise = <A, E, R extends GrpcService>(
effect: Effect.Effect<A, E, R>,
) =>
runPromise(
effect.pipe(
Effect.provide(Layer.setRequestCache(requestCache)),
Effect.withRequestCaching(true),
Effect.withRequestBatching(true),
),
);
return createGraphQLContext(
initialContext,
withErrorHandlingAndLogging(wrappedRunPromise),
);
},
graphqlEndpoint: config.endpoint,
});
// ... rest of setup
}),
}) {}