{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/relay/issues/541","repository_url":"https://api.github.com/repos/facebook/relay","labels_url":"https://api.github.com/repos/facebook/relay/issues/541/labels{/name}","comments_url":"https://api.github.com/repos/facebook/relay/issues/541/comments","events_url":"https://api.github.com/repos/facebook/relay/issues/541/events","html_url":"https://github.com/facebook/relay/issues/541","id":114671103,"number":541,"title":"[meta] Support real-time updates via event subscriptions","user":{"login":"josephsavona","id":6425824,"avatar_url":"https://avatars.githubusercontent.com/u/6425824?v=3","gravatar_id":"","url":"https://api.github.com/users/josephsavona","html_url":"https://github.com/josephsavona","followers_url":"https://api.github.com/users/josephsavona/followers","following_url":"https://api.github.com/users/josephsavona/following{/other_user}","gists_url":"https://api.github.com/users/josephsavona/gists{/gist_id}","starred_url":"https://api.github.com/users/josephsavona/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josephsavona/subscriptions","organizations_url":"https://api.github.com/users/josephsavona/orgs","repos_url":"https://api.github.com/users/josephsavona/repos","events_url":"https://api.github.com/users/josephsavona/events{/privacy}","received_events_url":"https://api.github.com/users/josephsavona/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/facebook/relay/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/facebook/relay/labels/help%20wanted","name":"help wanted","color":"159818"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":38,"created_at":"2015-11-02T19:51:38Z","updated_at":"2016-05-28T00:54:53Z","closed_at":null,"body":"The way we've been thinking of subscriptions is as a mix of push/pull semantics. In particular, the client would explicitly request updates from the server for a particular event, and the server could then notify the client when the event occurs (until the client closes the subscription). The rationale for this approach is detailed in [Subscriptions in GraphQL and Relay](http://graphql.org/blog/subscriptions-in-graphql-and-relay/).\r\n\r\nHere's the API we're considering:\r\n\r\n## Public API\r\n\r\nThe public API would be similar to mutations. The main difference is that subscriptions would have fixed/static queries (unlike mutations which intersect the fat query with those fields queried by the application).\r\n\r\n1) Define a subscription by subclassing `Relay.Subscription`:\r\n\r\n```javascript\r\nclass StoryLikeSubscription extends Relay.Subscription {\r\n  // Return a static query listing all fields to fetch when the event occurs\r\n  getSubscription() {\r\n    return Relay.QL`\r\n      subscription {\r\n        storyLikeSubscription(storyId: $storyId) {\r\n          likeCount\r\n        }\r\n      }\r\n    `;\r\n  }\r\n  // Describe how to handle the response payload (just like mutations)\r\n  getConfigs() { ... }\r\n  // Get the variables to send along with the query (e.g. the value of `$storyId`)\r\n  getVariables() { ... }\r\n}\r\n```\r\n\r\n2) Initiate a subscription, requesting updates from the server:\r\n\r\n```javascript\r\n// Relay.subscribe(subscription, callbacks)\r\nvar subscription = Relay.subscribe(\r\n  new StoryLikeSubscription({storyId: ...}), \r\n  {\r\n    onNext: data => { ... }, // called whenever data is received\r\n    onError: error => { ... }, // called if an error occurs\r\n  }\r\n);\r\nsubscription.dispose(); // notify the server to stop sending updates\r\n```\r\n\r\n## Internal Changes\r\n\r\nThe rough steps to implementing the above are:\r\n- Create a `Relay.Subscription` base class similar to  `Relay.Mutation`.\r\n- Create a `RelaySubscriptionRequest` class, similar to `RelayMutationRequest` for describing a subscription to send to the network layer. The public API would be roughly:\r\n\r\n```javascript\r\ntype RelaySubscriptionRequest = {\r\n  getDebugName: () => string;\r\n  getSubscription: () => RelayQuery.Subscription;\r\n  onCompleted: () => void; // called by the network layer if the server intentionally closes the subscription to signal that it cannot/will not provide additional data.  \r\n  onError: (err) => void; // called by the network layer if an error occurs. this ends the subscription.\r\n  onNext: (data) => void; // called by the network layer whenever data is received from the server.\r\n}\r\n```\r\n\r\n- Provide a stub implementation in `RelayDefaultNetworkLayer` which throws when subscriptions are requested\r\n- Docs, examples, tests\r\n- Last but not least, a working example implementation.\r\n\r\n\r\n### Completed\r\nThe following original todo items have already landed in master:\r\n- Update the `graphql` dependency to the latest version which supports parsing `subscription { .. }`.\r\n- Modify `babel-relay-plugin` to handle parsing those queries into a \"concrete\" subscription. The concrete subscription and corresponding `RelayQuery.Subscription` are already implemented."},"comment":{"url":"https://api.github.com/repos/facebook/relay/issues/comments/222281207","html_url":"https://github.com/facebook/relay/issues/541#issuecomment-222281207","issue_url":"https://api.github.com/repos/facebook/relay/issues/541","id":222281207,"user":{"login":"miketamis","id":1079931,"avatar_url":"https://avatars.githubusercontent.com/u/1079931?v=3","gravatar_id":"","url":"https://api.github.com/users/miketamis","html_url":"https://github.com/miketamis","followers_url":"https://api.github.com/users/miketamis/followers","following_url":"https://api.github.com/users/miketamis/following{/other_user}","gists_url":"https://api.github.com/users/miketamis/gists{/gist_id}","starred_url":"https://api.github.com/users/miketamis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miketamis/subscriptions","organizations_url":"https://api.github.com/users/miketamis/orgs","repos_url":"https://api.github.com/users/miketamis/repos","events_url":"https://api.github.com/users/miketamis/events{/privacy}","received_events_url":"https://api.github.com/users/miketamis/received_events","type":"User","site_admin":false},"created_at":"2016-05-28T00:54:53Z","updated_at":"2016-05-28T00:54:53Z","body":"We have realtime working within our relay application, I will release how we did it within a week, it isn't very fancy and not as powerful as subscription but it's a first step, and something that could turn into subscriptions."}}
{"actor":{"display_login":"miketamis"}}