BackendUserInfo.ts (hoppscotch-2.2.1) | : | BackendUserInfo.ts (hoppscotch-3.0.0) | ||
---|---|---|---|---|
import { pipe } from "fp-ts/function" | ||||
import * as E from "fp-ts/Either" | ||||
import { BehaviorSubject } from "rxjs" | import { BehaviorSubject } from "rxjs" | |||
import gql from "graphql-tag" | ||||
import { authIdToken$ } from "../fb/auth" | import { authIdToken$ } from "../fb/auth" | |||
import { apolloClient } from "../apollo" | import { runGQLQuery } from "../backend/GQLClient" | |||
import { GetUserInfoDocument } from "../backend/graphql" | ||||
/* | /* | |||
* This file deals with interfacing data provided by the | * This file deals with interfacing data provided by the | |||
* Hoppscotch Backend server | * Hoppscotch Backend server | |||
*/ | */ | |||
/** | /** | |||
* Defines the information provided about a user | * Defines the information provided about a user | |||
*/ | */ | |||
export interface UserInfo { | export interface UserInfo { | |||
skipping to change at line 55 | skipping to change at line 57 | |||
} else { | } else { | |||
currentUserInfo$.next(null) | currentUserInfo$.next(null) | |||
} | } | |||
}) | }) | |||
} | } | |||
/** | /** | |||
* Runs the actual user info fetching | * Runs the actual user info fetching | |||
*/ | */ | |||
async function updateUserInfo() { | async function updateUserInfo() { | |||
try { | const result = await runGQLQuery({ | |||
const { data } = await apolloClient.query({ | query: GetUserInfoDocument, | |||
query: gql` | }) | |||
query GetUserInfo { | ||||
me { | currentUserInfo$.next( | |||
uid | pipe( | |||
displayName | result, | |||
E.matchW( | ||||
photoURL | () => null, | |||
} | (x) => ({ | |||
} | uid: x.me.uid, | |||
`, | displayName: x.me.displayName ?? null, | |||
}) | email: x.me.email ?? null, | |||
photoURL: x.me.photoURL ?? null, | ||||
currentUserInfo$.next({ | }) | |||
uid: data.me.uid, | ) | |||
displayName: data.me.displayName, | ) | |||
email: data.me.email, | ) | |||
photoURL: data.me.photoURL, | ||||
}) | ||||
} catch (e) { | ||||
currentUserInfo$.next(null) | ||||
} | ||||
} | } | |||
End of changes. 4 change blocks. | ||||
25 lines changed or deleted | 22 lines changed or added |