Created
November 16, 2020 20:18
-
-
Save jasonLaster/e89d67460d3b71e3d1757fb5604edf0a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| diff --git a/src/dispatch/internal.js b/src/dispatch/internal.js | |
| index a09fc7bb..7181bd17 100644 | |
| --- a/src/dispatch/internal.js | |
| +++ b/src/dispatch/internal.js | |
| @@ -18,12 +18,54 @@ async function fetchGraphQL(query, name, variables = {}) { | |
| return await result.json(); | |
| } | |
| +async function fetchUserId(authId) { | |
| + const query = `query fetchUserId($auth_id: String) { | |
| + userIds(where: {auth_id: { _eq: $auth_id } }, limit: 1) { | |
| + id | |
| + } | |
| + } | |
| + `; | |
| + let response = await fetchGraphQL(query, "fetchUserId", { auth_id: authId }); | |
| + return response.userIds[0]; | |
| +} | |
| + | |
| const InternalMessageHandlers = { | |
| "Internal.echo": async function ({ str, count }) { | |
| const newStr = str.repeat(count); | |
| return { str: newStr }; | |
| }, | |
| + "Internal.saveRecording": async ({ recordingData, authId }) => { | |
| + // we used to use get-user.ts to get the hasura user_id. We can do that directly from the backend now | |
| + // https://github.com/RecordReplay/recordings/blob/master/pages/api/get-user.ts | |
| + | |
| + const userId = await fetchUserId(authId); | |
| + | |
| + // heavily inspired by | |
| + // https://github.com/RecordReplay/recordings/blob/master/pages/api/create-recording.ts | |
| + | |
| + const name = `SaveRecording`; | |
| + const query = ` | |
| + mutation SaveRecording($data: recordings_insert_input!) { | |
| + insert_recordings_one(object: $data) { | |
| + id | |
| + recording_id | |
| + last_screen_data | |
| + last_screen_mime_type | |
| + duration | |
| + title | |
| + url | |
| + user_id | |
| + } | |
| + } | |
| + `; | |
| + | |
| + let response = await fetchGraphQL(query, name, { | |
| + data: { ...recordingData, user_id: userId }, | |
| + }); | |
| + return { recordings: response.data.insert_recordings_one }; | |
| + }, | |
| + | |
| "Internal.getRecordings": async function ({ authId }) { | |
| const name = `GetRecordings`; | |
| const query = ` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment