Skip to content

Commit

Permalink
Merge pull request open-source-labs#19 from garyslootskiy/master
Browse files Browse the repository at this point in the history
Integrate headers and cookies into graphql queries and mutations
  • Loading branch information
samhaar authored Oct 28, 2020
2 parents e265090 + 26b3d50 commit 0502835
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
12 changes: 5 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,6 @@ ipcMain.on("open-gql", (event, args) => {
});
});

// IT SEEMS THAT HEADERS ARE NOT READING |HERE
console.log(headers);
// creates http connection to host
const httpLink = createHttpLink({
uri: reqResObj.url,
Expand Down Expand Up @@ -585,22 +583,22 @@ ipcMain.on("open-gql", (event, args) => {
const variables = reqResObj.request.bodyVariables
? JSON.parse(reqResObj.request.bodyVariables)
: {};

if (reqResObj.request.method === "QUERY") {
client
.query({ query: body, variables })
.query({ query: body, variables, context: headers })
.then((data) => {
event.sender.send("reply-gql", { reqResObj, data });
event.sender.send("reply-gql", { reqResObj, data })
})
.catch((err) => {
// error is actually sent to graphQLController via "errorLink"
console.log("gql query error in main.js", err);
});
} else if (reqResObj.request.method === "MUTATION") {
client
.mutate({ mutation: body, variables })
.mutate({ mutation: body, variables, context: headers })
.then((data) => {
// return response from GRAPHQL MUTATION
return event.sender.send("reply-gql", { reqResObj, data })
event.sender.send("reply-gql", { reqResObj, data })
})
.catch((err) => {
// error is actually sent to graphQLController via "errorLink"
Expand Down
1 change: 0 additions & 1 deletion src/client/components/containers/SingleReqResContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ const SingleReqResContainer = (props) => {
<button
className="is-flex-basis-0 is-flex-grow-1 button is-neutral-100 is-size-7"
onClick={() => {
ReqResCtrl.openReqRes(content.id);
dispatch(actions.saveCurrentResponseData(content));
}}
>
Expand Down
5 changes: 3 additions & 2 deletions src/client/controllers/graphQLController.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const graphQLController = {
api.send("open-gql", args);
api.receive("reply-gql", (result) => {
// needs formatting because component reads them in a particular order
result.reqResObj.response.cookies = this.cookieFormatter(
result.reqResObj.response.cookies = this.cookieFormatter(
result.reqResObj.response.cookies
);
);
resolve(result);
});
});
Expand Down Expand Up @@ -106,6 +106,7 @@ const graphQLController = {
reqResObj.timeReceived = Date.now();
reqResObj.response.events.push(JSON.stringify(response.data));
store.default.dispatch(actions.reqResUpdate(reqResObj));
store.default.dispatch(actions.saveCurrentResponseData(reqResObj));
store.default.dispatch(actions.updateGraph(reqResObj));
},

Expand Down
2 changes: 2 additions & 0 deletions src/client/controllers/reqResController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const connectionController = {

openReqRes(id) {
// listens for reqResUpdate event from main process telling it to update reqResobj
// REST EVENTS
api.receive("reqResUpdate", (reqResObj) => {
if (
reqResObj.connection === "closed" &&
Expand All @@ -40,6 +41,7 @@ const connectionController = {
store.default.dispatch(actions.updateGraph(reqResObj));
}
store.default.dispatch(actions.reqResUpdate(reqResObj));
store.default.dispatch(actions.saveCurrentResponseData(reqResObj));
});
//Since only obj ID is passed in, next two lines get the current array of reqest objects and finds the one with matching ID
const reqResArr = store.default.getState().business.reqResArray;
Expand Down

0 comments on commit 0502835

Please sign in to comment.