{"action":"created","comment":{"url":"https://api.github.com/repos/orbiting/republik-frontend/pulls/comments/194870719","pull_request_review_id":128126450,"id":194870719,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NDg3MDcxOQ==","diff_hunk":"@@ -0,0 +1,120 @@\n+import { ApolloLink, Observable } from 'apollo-link'\n+import { SubscriptionClient } from 'subscriptions-transport-ws'\n+import { API_WS_URL } from '../constants'\n+\n+export const hasSubscriptionOperation = ({ query: { definitions } }) => (\n+  definitions.some(\n+    ({ kind, operation }) =>\n+      kind === 'OperationDefinition' && operation === 'subscription'\n+  )\n+)\n+\n+// WebSocket compliant interface to handle subscriptions via app worker\n+class WorkerInterface {\n+  constructor (url, protocol) {\n+    this.url = url\n+    this.protocol = protocol\n+    this.readyState = WorkerInterface.OPEN\n+  }\n+\n+  send (serializedMessage) {\n+    window.postMessage(serializedMessage, '*')\n+  }\n+\n+  set onmessage (fn) {\n+    document.addEventListener('message', ({ data }) => {\n+      const d = JSON.parse(data)\n+\n+      if (d.type === 'start' || d.type === 'data') {\n+        fn({ data })\n+      }\n+    })\n+  }\n+}\n+\n+WorkerInterface.CLOSED = 'CLOSED'\n+WorkerInterface.OPEN = 'OPEN'\n+WorkerInterface.CONNECTING = 'CONNECTING'\n+\n+// Keep track of queries and mutations\n+let operationIds = 0\n+\n+// Apollo link implementation to resolve queries and mutations via app worker\n+class PromiseWorkerLink extends ApolloLink {\n+  constructor () {\n+    super()\n+    this.callbacks = {}\n+    this.onMessage = this.onMessage.bind(this)\n+    this.postMessage = this.postMessage.bind(this)\n+\n+    document.addEventListener('message', this.onMessage)\n+  }\n+\n+  onMessage (event) {\n+    const operation = JSON.parse(event.data)\n+    const callback = this.callbacks[operation.id]\n+\n+    if (callback) {\n+      callback(operation)\n+    }\n+  }\n+\n+  postMessage (id, operation) {\n+    return new Promise((resolve, reject) => {\n+      this.callbacks[id] = result => {\n+        resolve(result)\n+      }\n+\n+      window.postMessage(JSON.stringify({\n+        type: 'graphql',\n+        data: {\n+          id,\n+          payload: operation\n+        }\n+      }), '*')\n+    })\n+  }\n+\n+  request (operation) {\n+    const id = operationIds++\n+\n+    return new Observable(observer => {\n+      // Sends operation to be processed in app \"worker\"\n+      this.postMessage(id, operation).then(response => {\n+        observer.next(response)\n+        observer.complete()\n+      })\n+    })\n+  }\n+}\n+\n+// Apollo link implementation to resolve subscriptions via app worker\n+class SubscriptionWorkerLink extends ApolloLink {\n+  constructor ({ uri, options }) {\n+    super()\n+    this.subscriptionClient = new SubscriptionClient(uri, options, WorkerInterface)","path":"lib/apollo/appWorkerLink.js","position":95,"original_position":95,"commit_id":"3a01905cc97bb5e2a4109fc3383d8ae275d58bee","original_commit_id":"3a01905cc97bb5e2a4109fc3383d8ae275d58bee","user":{"login":"diegomura","id":5600341,"node_id":"MDQ6VXNlcjU2MDAzNDE=","avatar_url":"https://avatars1.githubusercontent.com/u/5600341?v=4","gravatar_id":"","url":"https://api.github.com/users/diegomura","html_url":"https://github.com/diegomura","followers_url":"https://api.github.com/users/diegomura/followers","following_url":"https://api.github.com/users/diegomura/following{/other_user}","gists_url":"https://api.github.com/users/diegomura/gists{/gist_id}","starred_url":"https://api.github.com/users/diegomura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diegomura/subscriptions","organizations_url":"https://api.github.com/users/diegomura/orgs","repos_url":"https://api.github.com/users/diegomura/repos","events_url":"https://api.github.com/users/diegomura/events{/privacy}","received_events_url":"https://api.github.com/users/diegomura/received_events","type":"User","site_admin":false},"body":"Agree. Good catch","created_at":"2018-06-12T20:03:55Z","updated_at":"2018-06-12T20:03:55Z","html_url":"https://github.com/orbiting/republik-frontend/pull/120#discussion_r194870719","pull_request_url":"https://api.github.com/repos/orbiting/republik-frontend/pulls/120","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/orbiting/republik-frontend/pulls/comments/194870719"},"html":{"href":"https://github.com/orbiting/republik-frontend/pull/120#discussion_r194870719"},"pull_request":{"href":"https://api.github.com/repos/orbiting/republik-frontend/pulls/120"}},"in_reply_to_id":194853060},"pull_request":{"url":"https://api.github.com/repos/orbiting/republik-frontend/pulls/120","id":193662692,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkzNjYyNjky","html_url":"https://github.com/orbiting/republik-frontend/pull/120","diff_url":"https://github.com/orbiting/republik-frontend/pull/120.diff","patch_url":"https://github.com/orbiting/republik-frontend/pull/120.patch","issue_url":"https://api.github.com/repos/orbiting/republik-frontend/issues/120","number":120,"state":"open","locked":false,"title":"Resolve graphql calls app side","user":{"login":"diegomura","id":5600341,"node_id":"MDQ6VXNlcjU2MDAzNDE=","avatar_url":"https://avatars1.githubusercontent.com/u/5600341?v=4","gravatar_id":"","url":"https://api.github.com/users/diegomura","html_url":"https://github.com/diegomura","followers_url":"https://api.github.com/users/diegomura/followers","following_url":"https://api.github.com/users/diegomura/following{/other_user}","gists_url":"https://api.github.com/users/diegomura/gists{/gist_id}","starred_url":"https://api.github.com/users/diegomura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diegomura/subscriptions","organizations_url":"https://api.github.com/users/diegomura/orgs","repos_url":"https://api.github.com/users/diegomura/repos","events_url":"https://api.github.com/users/diegomura/events{/privacy}","received_events_url":"https://api.github.com/users/diegomura/received_events","type":"User","site_admin":false},"body":"@tpreusse Proof of concept of the idea you proposed about resolving graphql queries app side.\r\n\r\n**What this does**\r\n- Undo special signin handling\r\n- Prevent using `HTTPLink` in app (I would then refactor the nested ternary conditionals) \r\n- Implement `AppLink` (name might change) that instead of resolving the request, it sends it to app\r\n- Listens for response\r\n\r\nIt's the first time I implement an ApolloLink, so maybe you have enhancements  we can do in mind 😄 \r\n\r\nI don't know yet which would be the best approach of correctly bind the message posting and response. Maybe you have thought about it.\r\n\r\nRelated to https://github.com/orbiting/app/pull/39","created_at":"2018-06-08T16:20:43Z","updated_at":"2018-06-12T20:03:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6e7b91186a885c1f0da1ec5f9851be5080f502d2","assignee":{"login":"diegomura","id":5600341,"node_id":"MDQ6VXNlcjU2MDAzNDE=","avatar_url":"https://avatars1.githubusercontent.com/u/5600341?v=4","gravatar_id":"","url":"https://api.github.com/users/diegomura","html_url":"https://github.com/diegomura","followers_url":"https://api.github.com/users/diegomura/followers","following_url":"https://api.github.com/users/diegomura/following{/other_user}","gists_url":"https://api.github.com/users/diegomura/gists{/gist_id}","starred_url":"https://api.github.com/users/diegomura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diegomura/subscriptions","organizations_url":"https://api.github.com/users/diegomura/orgs","repos_url":"https://api.github.com/users/diegomura/repos","events_url":"https://api.github.com/users/diegomura/events{/privacy}","received_events_url":"https://api.github.com/users/diegomura/received_events","type":"User","site_admin":false},"assignees":[{"login":"diegomura","id":5600341,"node_id":"MDQ6VXNlcjU2MDAzNDE=","avatar_url":"https://avatars1.githubusercontent.com/u/5600341?v=4","gravatar_id":"","url":"https://api.github.com/users/diegomura","html_url":"https://github.com/diegomura","followers_url":"https://api.github.com/users/diegomura/followers","following_url":"https://api.github.com/users/diegomura/following{/other_user}","gists_url":"https://api.github.com/users/diegomura/gists{/gist_id}","starred_url":"https://api.github.com/users/diegomura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diegomura/subscriptions","organizations_url":"https://api.github.com/users/diegomura/orgs","repos_url":"https://api.github.com/users/diegomura/repos","events_url":"https://api.github.com/users/diegomura/events{/privacy}","received_events_url":"https://api.github.com/users/diegomura/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/orbiting/republik-frontend/pulls/120/commits","review_comments_url":"https://api.github.com/repos/orbiting/republik-frontend/pulls/120/comments","review_comment_url":"https://api.github.com/repos/orbiting/republik-frontend/pulls/comments{/number}","comments_url":"https://api.github.com/repos/orbiting/republik-frontend/issues/120/comments","statuses_url":"https://api.github.com/repos/orbiting/republik-frontend/statuses/3a01905cc97bb5e2a4109fc3383d8ae275d58bee","head":{"label":"orbiting:apollo-link-poc","ref":"apollo-link-poc","sha":"3a01905cc97bb5e2a4109fc3383d8ae275d58bee","user":{"login":"orbiting","id":26253823,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI2MjUzODIz","avatar_url":"https://avatars1.githubusercontent.com/u/26253823?v=4","gravatar_id":"","url":"https://api.github.com/users/orbiting","html_url":"https://github.com/orbiting","followers_url":"https://api.github.com/users/orbiting/followers","following_url":"https://api.github.com/users/orbiting/following{/other_user}","gists_url":"https://api.github.com/users/orbiting/gists{/gist_id}","starred_url":"https://api.github.com/users/orbiting/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orbiting/subscriptions","organizations_url":"https://api.github.com/users/orbiting/orgs","repos_url":"https://api.github.com/users/orbiting/repos","events_url":"https://api.github.com/users/orbiting/events{/privacy}","received_events_url":"https://api.github.com/users/orbiting/received_events","type":"Organization","site_admin":false},"repo":{"id":105517506,"node_id":"MDEwOlJlcG9zaXRvcnkxMDU1MTc1MDY=","name":"republik-frontend","full_name":"orbiting/republik-frontend","owner":{"login":"orbiting","id":26253823,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI2MjUzODIz","avatar_url":"https://avatars1.githubusercontent.com/u/26253823?v=4","gravatar_id":"","url":"https://api.github.com/users/orbiting","html_url":"https://github.com/orbiting","followers_url":"https://api.github.com/users/orbiting/followers","following_url":"https://api.github.com/users/orbiting/following{/other_user}","gists_url":"https://api.github.com/users/orbiting/gists{/gist_id}","starred_url":"https://api.github.com/users/orbiting/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orbiting/subscriptions","organizations_url":"https://api.github.com/users/orbiting/orgs","repos_url":"https://api.github.com/users/orbiting/repos","events_url":"https://api.github.com/users/orbiting/events{/privacy}","received_events_url":"https://api.github.com/users/orbiting/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/orbiting/republik-frontend","description":"The front end of the online magazine Republik.","fork":false,"url":"https://api.github.com/repos/orbiting/republik-frontend","forks_url":"https://api.github.com/repos/orbiting/republik-frontend/forks","keys_url":"https://api.github.com/repos/orbiting/republik-frontend/keys{/key_id}","collaborators_url":"https://api.github.com/repos/orbiting/republik-frontend/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/orbiting/republik-frontend/teams","hooks_url":"https://api.github.com/repos/orbiting/republik-frontend/hooks","issue_events_url":"https://api.github.com/repos/orbiting/republik-frontend/issues/events{/number}","events_url":"https://api.github.com/repos/orbiting/republik-frontend/events","assignees_url":"https://api.github.com/repos/orbiting/republik-frontend/assignees{/user}","branches_url":"https://api.github.com/repos/orbiting/republik-frontend/branches{/branch}","tags_url":"https://api.github.com/repos/orbiting/republik-frontend/tags","blobs_url":"https://api.github.com/repos/orbiting/republik-frontend/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/orbiting/republik-frontend/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/orbiting/republik-frontend/git/refs{/sha}","trees_url":"https://api.github.com/repos/orbiting/republik-frontend/git/trees{/sha}","statuses_url":"https://api.github.com/repos/orbiting/republik-frontend/statuses/{sha}","languages_url":"https://api.github.com/repos/orbiting/republik-frontend/languages","stargazers_url":"https://api.github.com/repos/orbiting/republik-frontend/stargazers","contributors_url":"https://api.github.com/repos/orbiting/republik-frontend/contributors","subscribers_url":"https://api.github.com/repos/orbiting/republik-frontend/subscribers","subscription_url":"https://api.github.com/repos/orbiting/republik-frontend/subscription","commits_url":"https://api.github.com/repos/orbiting/republik-frontend/commits{/sha}","git_commits_url":"https://api.github.com/repos/orbiting/republik-frontend/git/commits{/sha}","comments_url":"https://api.github.com/repos/orbiting/republik-frontend/comments{/number}","issue_comment_url":"https://api.github.com/repos/orbiting/republik-frontend/issues/comments{/number}","contents_url":"https://api.github.com/repos/orbiting/republik-frontend/contents/{+path}","compare_url":"https://api.github.com/repos/orbiting/republik-frontend/compare/{base}...{head}","merges_url":"https://api.github.com/repos/orbiting/republik-frontend/merges","archive_url":"https://api.github.com/repos/orbiting/republik-frontend/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/orbiting/republik-frontend/downloads","issues_url":"https://api.github.com/repos/orbiting/republik-frontend/issues{/number}","pulls_url":"https://api.github.com/repos/orbiting/republik-frontend/pulls{/number}","milestones_url":"https://api.github.com/repos/orbiting/republik-frontend/milestones{/number}","notifications_url":"https://api.github.com/repos/orbiting/republik-frontend/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/orbiting/republik-frontend/labels{/name}","releases_url":"https://api.github.com/repos/orbiting/republik-frontend/releases{/id}","deployments_url":"https://api.github.com/repos/orbiting/republik-frontend/deployments","created_at":"2017-10-02T09:23:09Z","updated_at":"2018-06-11T15:43:32Z","pushed_at":"2018-06-12T18:39:28Z","git_url":"git://github.com/orbiting/republik-frontend.git","ssh_url":"git@github.com:orbiting/republik-frontend.git","clone_url":"https://github.com/orbiting/republik-frontend.git","svn_url":"https://github.com/orbiting/republik-frontend","homepage":"https://www.republik.ch/","size":73028,"stargazers_count":16,"watchers_count":16,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":11,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":2,"open_issues":11,"watchers":16,"default_branch":"master"}},"base":{"label":"orbiting:fix-auth-cookies","ref":"fix-auth-cookies","sha":"76d7be613fa9bcd86e35b6f6c813e99c15412092","user":{"login":"orbiting","id":26253823,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI2MjUzODIz","avatar_url":"https://avatars1.githubusercontent.com/u/26253823?v=4","gravatar_id":"","url":"https://api.github.com/users/orbiting","html_url":"https://github.com/orbiting","followers_url":"https://api.github.com/users/orbiting/followers","following_url":"https://api.github.com/users/orbiting/following{/other_user}","gists_url":"https://api.github.com/users/orbiting/gists{/gist_id}","starred_url":"https://api.github.com/users/orbiting/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orbiting/subscriptions","organizations_url":"https://api.github.com/users/orbiting/orgs","repos_url":"https://api.github.com/users/orbiting/repos","events_url":"https://api.github.com/users/orbiting/events{/privacy}","received_events_url":"https://api.github.com/users/orbiting/received_events","type":"Organization","site_admin":false},"repo":{"id":105517506,"node_id":"MDEwOlJlcG9zaXRvcnkxMDU1MTc1MDY=","name":"republik-frontend","full_name":"orbiting/republik-frontend","owner":{"login":"orbiting","id":26253823,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI2MjUzODIz","avatar_url":"https://avatars1.githubusercontent.com/u/26253823?v=4","gravatar_id":"","url":"https://api.github.com/users/orbiting","html_url":"https://github.com/orbiting","followers_url":"https://api.github.com/users/orbiting/followers","following_url":"https://api.github.com/users/orbiting/following{/other_user}","gists_url":"https://api.github.com/users/orbiting/gists{/gist_id}","starred_url":"https://api.github.com/users/orbiting/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orbiting/subscriptions","organizations_url":"https://api.github.com/users/orbiting/orgs","repos_url":"https://api.github.com/users/orbiting/repos","events_url":"https://api.github.com/users/orbiting/events{/privacy}","received_events_url":"https://api.github.com/users/orbiting/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/orbiting/republik-frontend","description":"The front end of the online magazine Republik.","fork":false,"url":"https://api.github.com/repos/orbiting/republik-frontend","forks_url":"https://api.github.com/repos/orbiting/republik-frontend/forks","keys_url":"https://api.github.com/repos/orbiting/republik-frontend/keys{/key_id}","collaborators_url":"https://api.github.com/repos/orbiting/republik-frontend/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/orbiting/republik-frontend/teams","hooks_url":"https://api.github.com/repos/orbiting/republik-frontend/hooks","issue_events_url":"https://api.github.com/repos/orbiting/republik-frontend/issues/events{/number}","events_url":"https://api.github.com/repos/orbiting/republik-frontend/events","assignees_url":"https://api.github.com/repos/orbiting/republik-frontend/assignees{/user}","branches_url":"https://api.github.com/repos/orbiting/republik-frontend/branches{/branch}","tags_url":"https://api.github.com/repos/orbiting/republik-frontend/tags","blobs_url":"https://api.github.com/repos/orbiting/republik-frontend/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/orbiting/republik-frontend/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/orbiting/republik-frontend/git/refs{/sha}","trees_url":"https://api.github.com/repos/orbiting/republik-frontend/git/trees{/sha}","statuses_url":"https://api.github.com/repos/orbiting/republik-frontend/statuses/{sha}","languages_url":"https://api.github.com/repos/orbiting/republik-frontend/languages","stargazers_url":"https://api.github.com/repos/orbiting/republik-frontend/stargazers","contributors_url":"https://api.github.com/repos/orbiting/republik-frontend/contributors","subscribers_url":"https://api.github.com/repos/orbiting/republik-frontend/subscribers","subscription_url":"https://api.github.com/repos/orbiting/republik-frontend/subscription","commits_url":"https://api.github.com/repos/orbiting/republik-frontend/commits{/sha}","git_commits_url":"https://api.github.com/repos/orbiting/republik-frontend/git/commits{/sha}","comments_url":"https://api.github.com/repos/orbiting/republik-frontend/comments{/number}","issue_comment_url":"https://api.github.com/repos/orbiting/republik-frontend/issues/comments{/number}","contents_url":"https://api.github.com/repos/orbiting/republik-frontend/contents/{+path}","compare_url":"https://api.github.com/repos/orbiting/republik-frontend/compare/{base}...{head}","merges_url":"https://api.github.com/repos/orbiting/republik-frontend/merges","archive_url":"https://api.github.com/repos/orbiting/republik-frontend/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/orbiting/republik-frontend/downloads","issues_url":"https://api.github.com/repos/orbiting/republik-frontend/issues{/number}","pulls_url":"https://api.github.com/repos/orbiting/republik-frontend/pulls{/number}","milestones_url":"https://api.github.com/repos/orbiting/republik-frontend/milestones{/number}","notifications_url":"https://api.github.com/repos/orbiting/republik-frontend/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/orbiting/republik-frontend/labels{/name}","releases_url":"https://api.github.com/repos/orbiting/republik-frontend/releases{/id}","deployments_url":"https://api.github.com/repos/orbiting/republik-frontend/deployments","created_at":"2017-10-02T09:23:09Z","updated_at":"2018-06-11T15:43:32Z","pushed_at":"2018-06-12T18:39:28Z","git_url":"git://github.com/orbiting/republik-frontend.git","ssh_url":"git@github.com:orbiting/republik-frontend.git","clone_url":"https://github.com/orbiting/republik-frontend.git","svn_url":"https://github.com/orbiting/republik-frontend","homepage":"https://www.republik.ch/","size":73028,"stargazers_count":16,"watchers_count":16,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":11,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":2,"open_issues":11,"watchers":16,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/orbiting/republik-frontend/pulls/120"},"html":{"href":"https://github.com/orbiting/republik-frontend/pull/120"},"issue":{"href":"https://api.github.com/repos/orbiting/republik-frontend/issues/120"},"comments":{"href":"https://api.github.com/repos/orbiting/republik-frontend/issues/120/comments"},"review_comments":{"href":"https://api.github.com/repos/orbiting/republik-frontend/pulls/120/comments"},"review_comment":{"href":"https://api.github.com/repos/orbiting/republik-frontend/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/orbiting/republik-frontend/pulls/120/commits"},"statuses":{"href":"https://api.github.com/repos/orbiting/republik-frontend/statuses/3a01905cc97bb5e2a4109fc3383d8ae275d58bee"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"diegomura"}}