Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alloy/f0c9c90ff7a28f3b17850021488979d5 to your computer and use it in GitHub Desktop.
Save alloy/f0c9c90ff7a28f3b17850021488979d5 to your computer and use it in GitHub Desktop.
import someLiveResolver from "@msteams/some-live-resolver-package";
{
"someLiveResolverBackedField": someLiveResolver as RelayLiveResolverFn<
import("@msteams/some-core-package").LiveResolverContext
// ^......................................................^ - type annotation literal, extracted by relay-compiler from @msteams/frameworks-relay/createRelayEnvironmentTask.ts
>
}
import { getLiveResolverContext } from "@msteams/some-core-package";
export function createRelayEnvironmentTask() {
const store = new LiveResolverStore<
import("@msteams/some-core-package").LiveResolverContext
// ^......................................................^ - type annotation literal, extracted by relay-compiler here
>(
new RelayRecordSource(),
{ liveResolverContextProvider: getLiveResolverContext }
)
// ...
}
export interface LiveResolverContext {
someService: SomeService;
}
export const getLiveResolverContext: () => LiveResolverContext = () => ({
someService: new SomeService(),
})
export const someLiveResolver: RelayLiveResolverFn<
import("@msteams/some-core-package").LiveResolverContext
//^......................................................^ - type annotation literal, written manually by dev
> = (context) => {
// ...
}
@alloy
Copy link
Author

alloy commented Jun 13, 2024

To be clear, I don't mean safe all the way through relay, but safe in the sense that what is being passed to the store matches what the resolver functions would accept. (If still unclear, I'll rework the gist as a typescript playground sample.)

But as said, a naive approach would break down quickly when there's more than 1 store/context typing in the system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment