Add SetViewMutation

This commit is contained in:
Chi Vinh Le
2018-08-08 15:03:51 +02:00
parent 245b8648d1
commit ac4b431d71
3 changed files with 47 additions and 0 deletions
@@ -0,0 +1,21 @@
import { Environment, RecordSource } from "relay-runtime";
import { LOCAL_ID } from "talk-framework/lib/relay";
import { createRelayEnvironment } from "talk-framework/testHelpers";
import { commit } from "./SetViewMutation";
let environment: Environment;
const source: RecordSource = new RecordSource();
beforeAll(() => {
environment = createRelayEnvironment({
source,
});
});
it("Sets view", () => {
const view = "SIGN_UP";
commit(environment, { view }, {} as any);
expect(source.get(LOCAL_ID)!.view).toEqual(view);
});
@@ -0,0 +1,25 @@
import { commitLocalUpdate, Environment } from "relay-runtime";
import { TalkContext } from "talk-framework/lib/bootstrap";
import { createMutationContainer } from "talk-framework/lib/relay";
import { LOCAL_ID } from "talk-framework/lib/relay/withLocalStateContainer";
export interface SetViewInput {
// TODO: replace with generated typescript types.
view: "SIGN_IN" | "SIGN_UP" | "FORGOT_PASSWORD";
}
export type SetViewMutation = (input: SetViewInput) => Promise<void>;
export async function commit(
environment: Environment,
input: SetViewInput,
{ pym }: TalkContext
) {
return commitLocalUpdate(environment, store => {
const record = store.get(LOCAL_ID)!;
record.setValue(input.view, "view");
});
}
export const withSetViewMutation = createMutationContainer("setView", commit);
+1
View File
@@ -0,0 +1 @@
export { withSetViewMutation, SetViewMutation } from "./SetViewMutation";