--- stage: Data Stores group: Cloud Connector info: Any user with at least the Maintainer role can merge updates to this content. For details, see https://docs.gitlab.com/ee/development/development_processes.html#development-guidelines-review. --- # Build and deploy real-time view components GitLab provides an interactive user experience through individual view components that accept user input and reflect state changes back to the user. For example, on the Merge Request page, users can approve, leave comments, interact with the CI/CD pipeline, and more. However, GitLab often does not reflect state updates in a timely manner. This means parts of the page display stale data that only update after users reload the page. To address this, GitLab has introduced technology and programming APIs that allow view components to receive state updates in real-time over a WebSocket. The following documentation tells you how to build and deploy view components that receive updates in real-time from the GitLab Ruby on Rails server. NOTE: Action Cable and GraphQL subscriptions are a work-in-progress and under active development. Developers must evaluate their use case to check if these are the right tools to use. If you are not sure, ask for help in the [`#f_real-time` internal Slack channel](https://gitlab.slack.com/archives/CUX9Z2N66). ## Build real-time view components Prerequisites: Read the: - [GraphQL development guide](fe_guide/graphql.md). - [Vue development guide](fe_guide/vue.md). To build a real-time view component on GitLab, you must: - Integrate a Vue component with Apollo subscriptions in the GitLab frontend. - Add and trigger GraphQL subscriptions from the GitLab Ruby on Rails backend. ### Integrate a Vue component with Apollo subscriptions NOTE: Our current real-time stack assumes that client code is built using Vue as the rendering layer and Apollo as the state and networking layer. If you are working with a part of the GitLab frontend that has not been migrated to Vue + Apollo yet, complete that task first. Consider a hypothetical `IssueView` Vue component that observes and renders GitLab `Issue` data. For simplicity, we assume here that all it does is render an issue's title and description: ```javascript import issueQuery from '~/issues/queries/issue_view.query.graqhql'; export default { props: { issueId: { type: Number, required: false, default: null, }, }, apollo: { // Name of the Apollo query object. Must match the field name bound by `data`. issue: { // Query used for the initial fetch. query: issueQuery, // Bind arguments used for the initial fetch query. variables() { return { iid: this.issueId, }; }, // Map response data to view properties. update(data) { return data.project?.issue || {}; }, }, }, // Reactive Vue component data. Apollo updates these when queries return or subscriptions fire. data() { return { issue: {}, // It is good practice to return initial state here while the view is loading. }; }, }; // The