From 5ddedb6b8bf3f47c400e3d38e415462abefa3b50 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 21 May 2019 14:26:18 +0100 Subject: Added tree list row component --- app/assets/javascripts/repository/graphql.js | 31 +++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'app/assets/javascripts/repository/graphql.js') diff --git a/app/assets/javascripts/repository/graphql.js b/app/assets/javascripts/repository/graphql.js index 0aedc73fc12..c85db5c01e5 100644 --- a/app/assets/javascripts/repository/graphql.js +++ b/app/assets/javascripts/repository/graphql.js @@ -7,7 +7,36 @@ Vue.use(VueApollo); const defaultClient = createDefaultClient({ Query: { files() { - return []; + return [ + { + __typename: 'file', + id: 1, + name: 'app', + flatPath: 'app', + type: 'folder', + }, + { + __typename: 'file', + id: 2, + name: 'gitlab-svg', + flatPath: 'gitlab-svg', + type: 'commit', + }, + { + __typename: 'file', + id: 3, + name: 'index.js', + flatPath: 'index.js', + type: 'blob', + }, + { + __typename: 'file', + id: 4, + name: 'test.pdf', + flatPath: 'fixtures/test.pdf', + type: 'blob', + }, + ]; }, }, }); -- cgit v1.2.1 From d8bb8d458c09146d70261026a5c90e97903b99c4 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Fri, 24 May 2019 10:39:18 +0100 Subject: Pull files for repository tree from GraphQL API --- app/assets/javascripts/repository/graphql.js | 65 +++++++++++++--------------- 1 file changed, 31 insertions(+), 34 deletions(-) (limited to 'app/assets/javascripts/repository/graphql.js') diff --git a/app/assets/javascripts/repository/graphql.js b/app/assets/javascripts/repository/graphql.js index c85db5c01e5..c64d16ef02a 100644 --- a/app/assets/javascripts/repository/graphql.js +++ b/app/assets/javascripts/repository/graphql.js @@ -1,45 +1,42 @@ import Vue from 'vue'; import VueApollo from 'vue-apollo'; +import { IntrospectionFragmentMatcher } from 'apollo-cache-inmemory'; import createDefaultClient from '~/lib/graphql'; +import introspectionQueryResultData from './fragmentTypes.json'; Vue.use(VueApollo); -const defaultClient = createDefaultClient({ - Query: { - files() { - return [ - { - __typename: 'file', - id: 1, - name: 'app', - flatPath: 'app', - type: 'folder', - }, - { - __typename: 'file', - id: 2, - name: 'gitlab-svg', - flatPath: 'gitlab-svg', - type: 'commit', - }, - { - __typename: 'file', - id: 3, - name: 'index.js', - flatPath: 'index.js', - type: 'blob', - }, - { - __typename: 'file', - id: 4, - name: 'test.pdf', - flatPath: 'fixtures/test.pdf', - type: 'blob', - }, - ]; +// We create a fragment matcher so that we can create a fragment from an interface +// Without this, Apollo throws a heuristic fragment matcher warning +const fragmentMatcher = new IntrospectionFragmentMatcher({ + introspectionQueryResultData, +}); + +const defaultClient = createDefaultClient( + {}, + { + cacheConfig: { + fragmentMatcher, + dataIdFromObject: obj => { + // eslint-disable-next-line no-underscore-dangle + switch (obj.__typename) { + // We need to create a dynamic ID for each entry + // Each entry can have the same ID as the ID is a commit ID + // So we create a unique cache ID with the path and the ID + case 'TreeEntry': + case 'Submodule': + case 'Blob': + return `${obj.flatPath}-${obj.id}`; + default: + // If the type doesn't match any of the above we fallback + // to using the default Apollo ID + // eslint-disable-next-line no-underscore-dangle + return obj.id || obj._id; + } + }, }, }, -}); +); export default new VueApollo({ defaultClient, -- cgit v1.2.1