Skip to content

Instantly share code, notes, and snippets.

@jasonLaster
Created September 10, 2020 20:45
Show Gist options
  • Select an option

  • Save jasonLaster/e66601483dd25d03c936b60cc96ffd95 to your computer and use it in GitHub Desktop.

Select an option

Save jasonLaster/e66601483dd25d03c936b60cc96ffd95 to your computer and use it in GitHub Desktop.
diff --git a/package.json b/package.json
index 4e5163a..f0c5673 100644
--- a/package.json
+++ b/package.json
@@ -22,7 +22,13 @@
},
"homepage": "https://github.com/bhackett1024/ReplayLinker#readme",
"dependencies": {
+ "@apollo/client": "^3.1.5",
"@octokit/rest": "^18.0.4",
- "dotenv": "^8.2.0"
+ "apollo-link-http": "^1.5.17",
+ "dotenv": "^8.2.0",
+ "graphql": "^15.3.0",
+ "isomorphic-unfetch": "^3.0.0",
+ "react": "^16.13.1",
+ "ws": "^7.3.1"
}
}
diff --git a/src/dispatch/apollo.js b/src/dispatch/apollo.js
index 9237d70..f583ec4 100644
--- a/src/dispatch/apollo.js
+++ b/src/dispatch/apollo.js
@@ -1,19 +1,20 @@
const { gql, ApolloClient, InMemoryCache } = require("@apollo/client");
const { HttpLink } = require("apollo-link-http");
+const fetch = require("isomorphic-unfetch");
const createHttpLink = (headers) => {
const httpLink = new HttpLink({
uri: "http://graphql.replay.io/v1/graphql",
headers: {
...headers,
- // "x-hasura-admin-secret": "supersecret",
+ "x-hasura-admin-secret": "supersecret",
}, // auth token is fetched on the server side
fetch,
});
return httpLink;
};
-export const createApolloClient = () => {
+function createApolloClient() {
const link = createHttpLink({});
const client = new ApolloClient({
@@ -21,7 +22,11 @@ export const createApolloClient = () => {
cache: new InMemoryCache(),
});
- client
+ return client;
+}
+
+function examplequery() {
+ createApolloClient()
.query({
query: gql`
query MyRecordingsQuery($user_id: String) {
@@ -43,6 +48,5 @@ export const createApolloClient = () => {
user_id: "google-oauth2|104244849821918151681",
},
})
- .then((result) => console.log(result));
- return client;
-};
+ .then((result) => console.log(JSON.stringify(result, null, 2)));
+}
diff --git a/src/dispatch/main.js b/src/dispatch/main.js
index 1054212..574f776 100644
--- a/src/dispatch/main.js
+++ b/src/dispatch/main.js
@@ -18,42 +18,42 @@ const {
resourcesDirectory,
} = require("../shared/config");
const { ProtocolSocket } = require("../protocol/socket");
-const { loadTypes } = require("../protocol/typeCheck");
+// const { loadTypes } = require("../protocol/typeCheck");
const { log } = require("../shared/utils");
-const {
- AnalysisMessageHandlers,
- analysisOnProtocolSocketClose,
-} = require("./analysis");
-const {
- forwardSessionMessage,
- ControlMessageHandlers,
- controlOnProtocolSocketClose,
-} = require("./control");
-const {
- RecordingMessageHandlers,
- recordingOnProtocolSocketClose,
-} = require("./recording");
-const {
- MetadataMessageHandlers,
- metadataOnProtocolSocketClose,
-} = require("./metadata");
+// const {
+// AnalysisMessageHandlers,
+// analysisOnProtocolSocketClose,
+// } = require("./analysis");
+// const {
+// forwardSessionMessage,
+// ControlMessageHandlers,
+// controlOnProtocolSocketClose,
+// } = require("./control");
+// const {
+// RecordingMessageHandlers,
+// recordingOnProtocolSocketClose,
+// } = require("./recording");
+// const {
+// MetadataMessageHandlers,
+// metadataOnProtocolSocketClose,
+// } = require("./metadata");
process.on("unhandledRejection", (error) => {
console.error("ErrorUnhandledRejection", error);
});
const protocolFile = "/protocol.json";
-loadTypes(protocolFile);
+// loadTypes(protocolFile);
-fs.mkdirSync(recordingDirectory);
-fs.mkdirSync(resourcesDirectory);
+// fs.mkdirSync(recordingDirectory);
+// fs.mkdirSync(resourcesDirectory);
log("Dispatcher initializing.");
const server = http.createServer();
const wss = new WebSocket.Server({ server });
-server.post("/create-recording", () => {
+server.post("/create-recording", async () => {
const { query, variables } = data;
// https://github.com/RecordReplay/recordings/blob/master/pages/api/create-recording.ts
const ADD_RECORDING = gql`
@@ -78,12 +78,9 @@ server.post("/create-recording", () => {
mutation: ADD_RECORDING,
});
res.statusCode = 200;
- res.setHeader('Content-Type', 'application/json');
+ res.setHeader("Content-Type", "application/json");
res.end(JSON.stringify(data.data.insert_recordings_one));
- } catch (e) {
-
- }
-
+ } catch (e) {}
});
wss.on("connection", (socket) => {
@@ -124,6 +121,7 @@ const MessageHandlers = {
// }
"Recording.query": async function ({}) {
const { query, variables } = data;
+ // TODO: query has to go from a string to gql`` fragment
return apolloClient.query(query, variables);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment