Guest User

Untitled

a guest
Feb 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. export interface WithLoginMutation {
  2. login(opts: {username: string, password: string}): Promise<Login.Login>;
  3. }
  4.  
  5. const WithLoginMutation = graphql<Login.Mutation>(
  6. GraphQL.login,
  7. {
  8. props({ mutate }): WithLoginMutation {
  9. if (!mutate) {
  10. throw new Error("No mutate found");
  11. }
  12.  
  13. return {
  14. async login(opts: {username: string, password: string}): Promise<Login.Login> {
  15. try {
  16. const {username, password} = opts;
  17.  
  18. const variables: Login.Variables = {
  19. username,
  20. password
  21. };
  22.  
  23. const result = await mutate({
  24. variables
  25. });
  26.  
  27. return result.data.login
  28. } catch (error) {
  29. throw error;
  30. }
  31. }
  32. };
  33. }
  34. }
  35. );
Add Comment
Please, Sign In to add comment