Created
June 12, 2024 22:56
-
-
Save alloy/f0c9c90ff7a28f3b17850021488979d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | |
) | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface LiveResolverContext { | |
someService: SomeService; | |
} | |
export const getLiveResolverContext: () => LiveResolverContext = () => ({ | |
someService: new SomeService(), | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const someLiveResolver: RelayLiveResolverFn< | |
import("@msteams/some-core-package").LiveResolverContext | |
//^......................................................^ - type annotation literal, written manually by dev | |
> = (context) => { | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.