Adding a Service to an Existing Runtime

How do I add another service to an existing runtime ?
I have created this function which builds a new runtime, but I wonder if there is a simpler way:
const addServiceToRuntime =
  <T extends Context.Tag<any, any>>(tag: T, service: Context.Tag.Service<T>) =>
  <Services>(
    self: Runtime.Runtime<Services>,
  ): Runtime.Runtime<Services | Context.Tag.Identifier<T>> =>
    Runtime.make({
      context: self.context.pipe(Context.add(tag, service)),
      fiberRefs: FiberRefs.empty(),
      runtimeFlags: Runtime.defaultRuntimeFlags,
    })

export const createGraphQLRuntime = (
  runtime: ServerRuntime,
  userAccess: UserAccess,
) => addServiceToRuntime(UserAccessTag, userAccess)(runtime)


My goal is to provide the user which initiated the request to the server runtime that were built when the server started. Then I can use this runtime in my graphql resolvers without having to provide the UserAccess.
Was this page helpful?