Commit 94631a02 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '271542-prefetch-requests-link' into 'master'

Pre-fetch GraphQL requests with startupJS

See merge request gitlab-org/gitlab!46130
parents 7aca7eee 1554e73e
<script> <script>
import GetBlobContent from 'shared_queries/snippet/snippet_blob_content.query.graphql';
import BlobHeader from '~/blob/components/blob_header.vue'; import BlobHeader from '~/blob/components/blob_header.vue';
import BlobContent from '~/blob/components/blob_content.vue'; import BlobContent from '~/blob/components/blob_content.vue';
import GetBlobContent from '../queries/snippet.blob.content.query.graphql';
import { import {
SIMPLE_BLOB_VIEWER, SIMPLE_BLOB_VIEWER,
RICH_BLOB_VIEWER, RICH_BLOB_VIEWER,
...@@ -21,7 +21,7 @@ export default { ...@@ -21,7 +21,7 @@ export default {
query: GetBlobContent, query: GetBlobContent,
variables() { variables() {
return { return {
ids: this.snippet.id, ids: [this.snippet.id],
rich: this.activeViewerType === RICH_BLOB_VIEWER, rich: this.activeViewerType === RICH_BLOB_VIEWER,
paths: [this.blob.path], paths: [this.blob.path],
}; };
......
...@@ -11,12 +11,12 @@ import { ...@@ -11,12 +11,12 @@ import {
GlButton, GlButton,
GlTooltipDirective, GlTooltipDirective,
} from '@gitlab/ui'; } from '@gitlab/ui';
import CanCreatePersonalSnippet from 'shared_queries/snippet/user_permissions.query.graphql';
import CanCreateProjectSnippet from 'shared_queries/snippet/project_permissions.query.graphql';
import { __ } from '~/locale'; import { __ } from '~/locale';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import DeleteSnippetMutation from '../mutations/deleteSnippet.mutation.graphql'; import DeleteSnippetMutation from '../mutations/deleteSnippet.mutation.graphql';
import CanCreatePersonalSnippet from '../queries/userPermissions.query.graphql';
import CanCreateProjectSnippet from '../queries/projectPermissions.query.graphql';
import { joinPaths } from '~/lib/utils/url_utility'; import { joinPaths } from '~/lib/utils/url_utility';
import { fetchPolicies } from '~/lib/graphql'; import { fetchPolicies } from '~/lib/graphql';
......
import GetSnippetQuery from '../queries/snippet.query.graphql'; import GetSnippetQuery from 'shared_queries/snippet/snippet.query.graphql';
const blobsDefault = []; const blobsDefault = [];
...@@ -8,7 +8,7 @@ export const getSnippetMixin = { ...@@ -8,7 +8,7 @@ export const getSnippetMixin = {
query: GetSnippetQuery, query: GetSnippetQuery,
variables() { variables() {
return { return {
ids: this.snippetGid, ids: [this.snippetGid],
}; };
}, },
update: data => { update: data => {
......
#import '../fragments/snippetBase.fragment.graphql'
#import '../fragments/project.fragment.graphql'
#import "~/graphql_shared/fragments/author.fragment.graphql"
query GetSnippetQuery($ids: [ID!]) {
snippets(ids: $ids) {
nodes {
...SnippetBase
...SnippetProject
author {
...Author
}
}
}
}
query CanCreateProjectSnippet($fullPath: ID!) { query CanCreateProjectSnippet($fullPath: ID!) {
project(fullPath: $fullPath) { project(fullPath: $fullPath) {
__typename
userPermissions { userPermissions {
__typename
createSnippet createSnippet
} }
} }
......
query GetSnippetQuery($ids: [ID!]) {
snippets(ids: $ids) {
__typename
nodes {
__typename
id
title
description
descriptionHtml
createdAt
updatedAt
visibilityLevel
webUrl
httpUrlToRepo
sshUrlToRepo
blobs {
__typename
nodes {
__typename
binary
name
path
rawPath
size
externalStorage
renderedAsText
simpleViewer {
__typename
collapsed
renderError
tooLarge
type
fileType
}
richViewer {
__typename
collapsed
renderError
tooLarge
type
fileType
}
}
}
userPermissions {
__typename
adminSnippet
updateSnippet
}
project {
__typename
fullPath
webUrl
}
author {
__typename
id
avatarUrl
name
username
webUrl
}
}
}
}
query SnippetBlobContent($ids: [ID!], $rich: Boolean!, $paths: [String!]) { query SnippetBlobContent($ids: [ID!], $rich: Boolean!, $paths: [String!]) {
snippets(ids: $ids) { snippets(ids: $ids) {
__typename
nodes { nodes {
__typename
id id
blobs(paths: $paths) { blobs(paths: $paths) {
__typename
nodes { nodes {
__typename
path path
richData @include(if: $rich) richData @include(if: $rich)
plainData @skip(if: $rich) plainData @skip(if: $rich)
......
query CanCreatePersonalSnippet { query CanCreatePersonalSnippet {
currentUser { currentUser {
__typename
userPermissions { userPermissions {
__typename
createSnippet createSnippet
} }
} }
......
- add_page_startup_graphql_call('snippet/snippet', { ids: [@snippet.to_global_id.uri] })
- add_page_startup_graphql_call('snippet/snippet_blob_content', { ids: [@snippet.to_global_id.uri], rich: false, paths: [@snippet.file_name] })
- if @snippet.project_id?
- add_page_startup_graphql_call('snippet/project_permissions', { fullPath: @snippet.project_id })
- else
- add_page_startup_graphql_call('snippet/user_permissions')
- @hide_top_links = true - @hide_top_links = true
- @content_class = "limit-container-width limited-inner-width-container" unless fluid_layout - @content_class = "limit-container-width limited-inner-width-container" unless fluid_layout
- add_to_breadcrumbs _("Snippets"), dashboard_snippets_path - add_to_breadcrumbs _("Snippets"), dashboard_snippets_path
......
---
title: Pre-fetched GraphQL queries for snippet view
merge_request: 46130
author:
type: changed
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment