decap-cms-backend-github 3.2.3-beta.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,35 +1,22 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _trimStart2 = _interopRequireDefault(require("lodash/trimStart"));
8
- var _trim2 = _interopRequireDefault(require("lodash/trim"));
9
- var _apolloClient = require("apollo-client");
10
- var _apolloCacheInmemory = require("apollo-cache-inmemory");
11
- var _apolloLinkHttp = require("apollo-link-http");
12
- var _apolloLinkContext = require("apollo-link-context");
13
- var _decapCmsLibUtil = require("decap-cms-lib-util");
14
- var _fragmentTypes = _interopRequireDefault(require("./fragmentTypes"));
15
- var _API = _interopRequireWildcard(require("./API"));
16
- var queries = _interopRequireWildcard(require("./queries"));
17
- var mutations = _interopRequireWildcard(require("./mutations"));
18
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
19
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
22
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
23
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
24
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
25
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
1
+ import { ApolloClient } from 'apollo-client';
2
+ import { InMemoryCache, defaultDataIdFromObject, IntrospectionFragmentMatcher } from 'apollo-cache-inmemory';
3
+ import { createHttpLink } from 'apollo-link-http';
4
+ import { setContext } from 'apollo-link-context';
5
+ import { APIError, readFile, localForage, DEFAULT_PR_BODY, branchFromContentKey, CMS_BRANCH_PREFIX, throwOnConflictingBranches } from 'decap-cms-lib-util';
6
+ import trim from 'lodash/trim';
7
+ import trimStart from 'lodash/trimStart';
8
+ import introspectionQueryResultData from './fragmentTypes';
9
+ import API, { API_NAME, PullRequestState, MOCK_PULL_REQUEST } from './API';
10
+ import * as queries from './queries';
11
+ import * as mutations from './mutations';
26
12
  const NO_CACHE = 'no-cache';
27
13
  const CACHE_FIRST = 'cache-first';
28
- const fragmentMatcher = new _apolloCacheInmemory.IntrospectionFragmentMatcher({
29
- introspectionQueryResultData: _fragmentTypes.default
14
+ const fragmentMatcher = new IntrospectionFragmentMatcher({
15
+ introspectionQueryResultData
30
16
  });
31
17
  function transformPullRequest(pr) {
32
- return _objectSpread(_objectSpread({}, pr), {}, {
18
+ return {
19
+ ...pr,
33
20
  labels: pr.labels.nodes,
34
21
  head: {
35
22
  ref: pr.headRefName,
@@ -42,32 +29,31 @@ function transformPullRequest(pr) {
42
29
  ref: pr.baseRefName,
43
30
  sha: pr.baseRefOid
44
31
  }
45
- });
32
+ };
46
33
  }
47
- class GraphQLAPI extends _API.default {
34
+ export default class GraphQLAPI extends API {
48
35
  constructor(config) {
49
36
  super(config);
50
- _defineProperty(this, "client", void 0);
51
37
  this.client = this.getApolloClient();
52
38
  }
53
39
  getApolloClient() {
54
- const authLink = (0, _apolloLinkContext.setContext)((_, {
40
+ const authLink = setContext((_, {
55
41
  headers
56
42
  }) => {
57
43
  return {
58
- headers: _objectSpread(_objectSpread({
59
- 'Content-Type': 'application/json; charset=utf-8'
60
- }, headers), {}, {
44
+ headers: {
45
+ 'Content-Type': 'application/json; charset=utf-8',
46
+ ...headers,
61
47
  authorization: this.token ? `${this.tokenKeyword} ${this.token}` : ''
62
- })
48
+ }
63
49
  };
64
50
  });
65
- const httpLink = (0, _apolloLinkHttp.createHttpLink)({
51
+ const httpLink = createHttpLink({
66
52
  uri: `${this.apiRoot}/graphql`
67
53
  });
68
- return new _apolloClient.ApolloClient({
54
+ return new ApolloClient({
69
55
  link: authLink.concat(httpLink),
70
- cache: new _apolloCacheInmemory.InMemoryCache({
56
+ cache: new InMemoryCache({
71
57
  fragmentMatcher
72
58
  }),
73
59
  defaultOptions: {
@@ -100,7 +86,7 @@ class GraphQLAPI extends _API.default {
100
86
  }
101
87
  query(options) {
102
88
  return this.client.query(options).catch(error => {
103
- throw new _decapCmsLibUtil.APIError(error.message, 500, 'GitHub');
89
+ throw new APIError(error.message, 500, 'GitHub');
104
90
  });
105
91
  }
106
92
  async mutate(options) {
@@ -110,18 +96,16 @@ class GraphQLAPI extends _API.default {
110
96
  } catch (error) {
111
97
  const errors = error.graphQLErrors;
112
98
  if (Array.isArray(errors) && errors.some(e => e.message === 'Ref cannot be created.')) {
113
- var _options$variables, _options$variables$cr;
114
- const refName = (options === null || options === void 0 ? void 0 : (_options$variables = options.variables) === null || _options$variables === void 0 ? void 0 : (_options$variables$cr = _options$variables.createRefInput) === null || _options$variables$cr === void 0 ? void 0 : _options$variables$cr.name) || '';
115
- const branchName = (0, _trimStart2.default)(refName, 'refs/heads/');
99
+ const refName = options?.variables?.createRefInput?.name || '';
100
+ const branchName = trimStart(refName, 'refs/heads/');
116
101
  if (branchName) {
117
- await (0, _decapCmsLibUtil.throwOnConflictingBranches)(branchName, name => this.getBranch(name), _API.API_NAME);
102
+ await throwOnConflictingBranches(branchName, name => this.getBranch(name), API_NAME);
118
103
  }
119
- } else if (Array.isArray(errors) && errors.some(e => new RegExp(`A ref named "refs/heads/${_decapCmsLibUtil.CMS_BRANCH_PREFIX}/.+?" already exists in the repository.`).test(e.message))) {
120
- var _options$variables2, _options$variables2$c, _options$variables3, _options$variables3$c;
121
- const refName = (options === null || options === void 0 ? void 0 : (_options$variables2 = options.variables) === null || _options$variables2 === void 0 ? void 0 : (_options$variables2$c = _options$variables2.createRefInput) === null || _options$variables2$c === void 0 ? void 0 : _options$variables2$c.name) || '';
122
- const sha = (options === null || options === void 0 ? void 0 : (_options$variables3 = options.variables) === null || _options$variables3 === void 0 ? void 0 : (_options$variables3$c = _options$variables3.createRefInput) === null || _options$variables3$c === void 0 ? void 0 : _options$variables3$c.oid) || '';
123
- const branchName = (0, _trimStart2.default)(refName, 'refs/heads/');
124
- if (branchName && branchName.startsWith(`${_decapCmsLibUtil.CMS_BRANCH_PREFIX}/`) && sha) {
104
+ } else if (Array.isArray(errors) && errors.some(e => new RegExp(`A ref named "refs/heads/${CMS_BRANCH_PREFIX}/.+?" already exists in the repository.`).test(e.message))) {
105
+ const refName = options?.variables?.createRefInput?.name || '';
106
+ const sha = options?.variables?.createRefInput?.oid || '';
107
+ const branchName = trimStart(refName, 'refs/heads/');
108
+ if (branchName && branchName.startsWith(`${CMS_BRANCH_PREFIX}/`) && sha) {
125
109
  try {
126
110
  // this can happen if the branch wasn't deleted when the PR was merged
127
111
  // we backup the existing branch just in case an re-run the mutation
@@ -134,7 +118,7 @@ class GraphQLAPI extends _API.default {
134
118
  }
135
119
  }
136
120
  }
137
- throw new _decapCmsLibUtil.APIError(error.message, 500, 'GitHub');
121
+ throw new APIError(error.message, 500, 'GitHub');
138
122
  }
139
123
  }
140
124
  async hasWriteAccess() {
@@ -175,14 +159,15 @@ class GraphQLAPI extends _API.default {
175
159
  async retrieveBlobObject(owner, name, expression, options = {}) {
176
160
  const {
177
161
  data
178
- } = await this.query(_objectSpread({
162
+ } = await this.query({
179
163
  query: queries.blob,
180
164
  variables: {
181
165
  owner,
182
166
  name,
183
167
  expression
184
- }
185
- }, options));
168
+ },
169
+ ...options
170
+ });
186
171
  // https://developer.github.com/v4/object/blob/
187
172
  if (data.repository.object) {
188
173
  const {
@@ -232,7 +217,7 @@ class GraphQLAPI extends _API.default {
232
217
  repoURL,
233
218
  parseText
234
219
  });
235
- const content = await (0, _decapCmsLibUtil.readFile)(sha, fetchContent, _decapCmsLibUtil.localForage, parseText);
220
+ const content = await readFile(sha, fetchContent, localForage, parseText);
236
221
  return content;
237
222
  }
238
223
  async fetchBlobContent({
@@ -260,7 +245,7 @@ class GraphQLAPI extends _API.default {
260
245
  } // blob sha is derived from file content
261
246
  );
262
247
  if (isNull) {
263
- throw new _decapCmsLibUtil.APIError('Not Found', 404, 'GitHub');
248
+ throw new APIError('Not Found', 404, 'GitHub');
264
249
  } else if (!isBinary) {
265
250
  return text;
266
251
  } else {
@@ -273,7 +258,7 @@ class GraphQLAPI extends _API.default {
273
258
  }
274
259
  async getPullRequestAuthor(pullRequest) {
275
260
  const user = pullRequest.user;
276
- return (user === null || user === void 0 ? void 0 : user.name) || (user === null || user === void 0 ? void 0 : user.login);
261
+ return user?.name || user?.login;
277
262
  }
278
263
  async getPullRequests(head, state, predicate) {
279
264
  const {
@@ -281,9 +266,9 @@ class GraphQLAPI extends _API.default {
281
266
  originRepoName: name
282
267
  } = this;
283
268
  let states;
284
- if (state === _API.PullRequestState.Open) {
269
+ if (state === PullRequestState.Open) {
285
270
  states = ['OPEN'];
286
- } else if (state === _API.PullRequestState.Closed) {
271
+ } else if (state === PullRequestState.Closed) {
287
272
  states = ['CLOSED', 'MERGED'];
288
273
  } else {
289
274
  states = ['OPEN', 'CLOSED', 'MERGED'];
@@ -292,20 +277,20 @@ class GraphQLAPI extends _API.default {
292
277
  data
293
278
  } = await this.query({
294
279
  query: queries.pullRequests,
295
- variables: _objectSpread(_objectSpread({
280
+ variables: {
296
281
  owner,
297
- name
298
- }, head ? {
299
- head
300
- } : {}), {}, {
282
+ name,
283
+ ...(head ? {
284
+ head
285
+ } : {}),
301
286
  states
302
- })
287
+ }
303
288
  });
304
289
  const {
305
290
  pullRequests
306
291
  } = data.repository;
307
292
  const mapped = pullRequests.nodes.map(transformPullRequest);
308
- return mapped.filter(pr => pr.head.ref.startsWith(`${_decapCmsLibUtil.CMS_BRANCH_PREFIX}/`) && predicate(pr));
293
+ return mapped.filter(pr => pr.head.ref.startsWith(`${CMS_BRANCH_PREFIX}/`) && predicate(pr));
309
294
  }
310
295
  async getOpenAuthoringBranches() {
311
296
  const {
@@ -331,7 +316,7 @@ class GraphQLAPI extends _API.default {
331
316
  }
332
317
  async getStatuses(collectionName, slug) {
333
318
  const contentKey = this.generateContentKey(collectionName, slug);
334
- const branch = (0, _decapCmsLibUtil.branchFromContentKey)(contentKey);
319
+ const branch = branchFromContentKey(contentKey);
335
320
  const pullRequest = await this.getBranchPullRequest(branch);
336
321
  const sha = pullRequest.head.sha;
337
322
  const {
@@ -365,8 +350,7 @@ class GraphQLAPI extends _API.default {
365
350
  getAllFiles(entries, path) {
366
351
  const allFiles = entries.reduce((acc, item) => {
367
352
  if (item.type === 'tree') {
368
- var _item$object;
369
- const entries = ((_item$object = item.object) === null || _item$object === void 0 ? void 0 : _item$object.entries) || [];
353
+ const entries = item.object?.entries || [];
370
354
  return [...acc, ...this.getAllFiles(entries, `${path}/${item.name}`)];
371
355
  } else if (item.type === 'blob') {
372
356
  return [...acc, {
@@ -390,7 +374,7 @@ class GraphQLAPI extends _API.default {
390
374
  owner,
391
375
  name
392
376
  } = this.getOwnerAndNameFromRepoUrl(repoURL);
393
- const folder = (0, _trim2.default)(path, '/');
377
+ const folder = trim(path, '/');
394
378
  const {
395
379
  data
396
380
  } = await this.query({
@@ -424,17 +408,20 @@ class GraphQLAPI extends _API.default {
424
408
  async getDefaultBranch() {
425
409
  const {
426
410
  data
427
- } = await this.query(_objectSpread({}, this.getBranchQuery(this.branch, this.originRepoOwner, this.originRepoName)));
411
+ } = await this.query({
412
+ ...this.getBranchQuery(this.branch, this.originRepoOwner, this.originRepoName)
413
+ });
428
414
  return data.repository.branch;
429
415
  }
430
416
  async getBranch(branch) {
431
417
  const {
432
418
  data
433
- } = await this.query(_objectSpread(_objectSpread({}, this.getBranchQuery(branch, this.repoOwner, this.repoName)), {}, {
419
+ } = await this.query({
420
+ ...this.getBranchQuery(branch, this.repoOwner, this.repoName),
434
421
  fetchPolicy: CACHE_FIRST
435
- }));
422
+ });
436
423
  if (!data.repository.branch) {
437
- throw new _decapCmsLibUtil.APIError('Branch not found', 404, _API.API_NAME);
424
+ throw new APIError('Branch not found', 404, API_NAME);
438
425
  }
439
426
  return data.repository.branch;
440
427
  }
@@ -470,7 +457,7 @@ class GraphQLAPI extends _API.default {
470
457
  }
471
458
  },
472
459
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
473
- update: store => store.data.delete((0, _apolloCacheInmemory.defaultDataIdFromObject)(branch))
460
+ update: store => store.data.delete(defaultDataIdFromObject(branch))
474
461
  });
475
462
  return data.deleteRef;
476
463
  }
@@ -491,17 +478,19 @@ class GraphQLAPI extends _API.default {
491
478
  async getPullRequest(number) {
492
479
  const {
493
480
  data
494
- } = await this.query(_objectSpread(_objectSpread({}, this.getPullRequestQuery(number)), {}, {
481
+ } = await this.query({
482
+ ...this.getPullRequestQuery(number),
495
483
  fetchPolicy: CACHE_FIRST
496
- }));
484
+ });
497
485
 
498
486
  // https://developer.github.com/v4/enum/pullrequeststate/
499
487
  // GraphQL state: [CLOSED, MERGED, OPEN]
500
488
  // REST API state: [closed, open]
501
- const state = data.repository.pullRequest.state === 'OPEN' ? _API.PullRequestState.Open : _API.PullRequestState.Closed;
502
- return _objectSpread(_objectSpread({}, data.repository.pullRequest), {}, {
489
+ const state = data.repository.pullRequest.state === 'OPEN' ? PullRequestState.Open : PullRequestState.Closed;
490
+ return {
491
+ ...data.repository.pullRequest,
503
492
  state
504
- });
493
+ };
505
494
  }
506
495
  getPullRequestAndBranchQuery(branch, number) {
507
496
  const {
@@ -527,9 +516,10 @@ class GraphQLAPI extends _API.default {
527
516
  async getPullRequestAndBranch(branch, number) {
528
517
  const {
529
518
  data
530
- } = await this.query(_objectSpread(_objectSpread({}, this.getPullRequestAndBranchQuery(branch, number)), {}, {
519
+ } = await this.query({
520
+ ...this.getPullRequestAndBranchQuery(branch, number),
531
521
  fetchPolicy: CACHE_FIRST
532
- }));
522
+ });
533
523
  const {
534
524
  repository,
535
525
  origin
@@ -557,13 +547,15 @@ class GraphQLAPI extends _API.default {
557
547
  pullRequest
558
548
  } = mutationResult.reopenPullRequest;
559
549
  const pullRequestData = {
560
- repository: _objectSpread(_objectSpread({}, pullRequest.repository), {}, {
550
+ repository: {
551
+ ...pullRequest.repository,
561
552
  pullRequest
562
- })
553
+ }
563
554
  };
564
- store.writeQuery(_objectSpread(_objectSpread({}, this.getPullRequestQuery(pullRequest.number)), {}, {
555
+ store.writeQuery({
556
+ ...this.getPullRequestQuery(pullRequest.number),
565
557
  data: pullRequestData
566
- }));
558
+ });
567
559
  }
568
560
  });
569
561
  return data.reopenPullRequest;
@@ -586,13 +578,15 @@ class GraphQLAPI extends _API.default {
586
578
  pullRequest
587
579
  } = mutationResult.closePullRequest;
588
580
  const pullRequestData = {
589
- repository: _objectSpread(_objectSpread({}, pullRequest.repository), {}, {
581
+ repository: {
582
+ ...pullRequest.repository,
590
583
  pullRequest
591
- })
584
+ }
592
585
  };
593
- store.writeQuery(_objectSpread(_objectSpread({}, this.getPullRequestQuery(pullRequest.number)), {}, {
586
+ store.writeQuery({
587
+ ...this.getPullRequestQuery(pullRequest.number),
594
588
  data: pullRequestData
595
- }));
589
+ });
596
590
  }
597
591
  });
598
592
  return data.closePullRequest;
@@ -600,9 +594,9 @@ class GraphQLAPI extends _API.default {
600
594
  async deleteUnpublishedEntry(collectionName, slug) {
601
595
  try {
602
596
  const contentKey = this.generateContentKey(collectionName, slug);
603
- const branchName = (0, _decapCmsLibUtil.branchFromContentKey)(contentKey);
597
+ const branchName = branchFromContentKey(contentKey);
604
598
  const pr = await this.getBranchPullRequest(branchName);
605
- if (pr.number !== _API.MOCK_PULL_REQUEST) {
599
+ if (pr.number !== MOCK_PULL_REQUEST) {
606
600
  const {
607
601
  branch,
608
602
  pullRequest
@@ -621,8 +615,8 @@ class GraphQLAPI extends _API.default {
621
615
  },
622
616
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
623
617
  update: store => {
624
- store.data.delete((0, _apolloCacheInmemory.defaultDataIdFromObject)(branch));
625
- store.data.delete((0, _apolloCacheInmemory.defaultDataIdFromObject)(pullRequest));
618
+ store.data.delete(defaultDataIdFromObject(branch));
619
+ store.data.delete(defaultDataIdFromObject(pullRequest));
626
620
  }
627
621
  });
628
622
  return data.closePullRequest;
@@ -651,7 +645,7 @@ class GraphQLAPI extends _API.default {
651
645
  variables: {
652
646
  createPullRequestInput: {
653
647
  baseRefName: this.branch,
654
- body: _decapCmsLibUtil.DEFAULT_PR_BODY,
648
+ body: DEFAULT_PR_BODY,
655
649
  title,
656
650
  headRefName: headReference,
657
651
  repositoryId: repository.id
@@ -664,23 +658,26 @@ class GraphQLAPI extends _API.default {
664
658
  pullRequest
665
659
  } = mutationResult.createPullRequest;
666
660
  const pullRequestData = {
667
- repository: _objectSpread(_objectSpread({}, pullRequest.repository), {}, {
661
+ repository: {
662
+ ...pullRequest.repository,
668
663
  pullRequest
669
- })
664
+ }
670
665
  };
671
- store.writeQuery(_objectSpread(_objectSpread({}, this.getPullRequestQuery(pullRequest.number)), {}, {
666
+ store.writeQuery({
667
+ ...this.getPullRequestQuery(pullRequest.number),
672
668
  data: pullRequestData
673
- }));
669
+ });
674
670
  }
675
671
  });
676
672
  const {
677
673
  pullRequest
678
674
  } = data.createPullRequest;
679
- return _objectSpread(_objectSpread({}, pullRequest), {}, {
675
+ return {
676
+ ...pullRequest,
680
677
  head: {
681
678
  sha: pullRequest.headRefOid
682
679
  }
683
- });
680
+ };
684
681
  }
685
682
  async createBranch(branchName, sha) {
686
683
  const owner = this.repoOwner;
@@ -704,21 +701,24 @@ class GraphQLAPI extends _API.default {
704
701
  branch
705
702
  } = mutationResult.createRef;
706
703
  const branchData = {
707
- repository: _objectSpread(_objectSpread({}, branch.repository), {}, {
704
+ repository: {
705
+ ...branch.repository,
708
706
  branch
709
- })
707
+ }
710
708
  };
711
- store.writeQuery(_objectSpread(_objectSpread({}, this.getBranchQuery(branchName, owner, name)), {}, {
709
+ store.writeQuery({
710
+ ...this.getBranchQuery(branchName, owner, name),
712
711
  data: branchData
713
- }));
712
+ });
714
713
  }
715
714
  });
716
715
  const {
717
716
  branch
718
717
  } = data.createRef;
719
- return _objectSpread(_objectSpread({}, branch), {}, {
718
+ return {
719
+ ...branch,
720
720
  ref: `${branch.prefix}${branch.name}`
721
- });
721
+ };
722
722
  }
723
723
  async createBranchAndPullRequest(branchName, sha, title) {
724
724
  const owner = this.originRepoOwner;
@@ -736,7 +736,7 @@ class GraphQLAPI extends _API.default {
736
736
  },
737
737
  createPullRequestInput: {
738
738
  baseRefName: this.branch,
739
- body: _decapCmsLibUtil.DEFAULT_PR_BODY,
739
+ body: DEFAULT_PR_BODY,
740
740
  title,
741
741
  headRefName: branchName,
742
742
  repositoryId: repository.id
@@ -752,24 +752,29 @@ class GraphQLAPI extends _API.default {
752
752
  pullRequest
753
753
  } = mutationResult.createPullRequest;
754
754
  const branchData = {
755
- repository: _objectSpread(_objectSpread({}, branch.repository), {}, {
755
+ repository: {
756
+ ...branch.repository,
756
757
  branch
757
- })
758
+ }
758
759
  };
759
760
  const pullRequestData = {
760
- repository: _objectSpread(_objectSpread({}, pullRequest.repository), {}, {
761
+ repository: {
762
+ ...pullRequest.repository,
761
763
  branch
762
- }),
763
- origin: _objectSpread(_objectSpread({}, pullRequest.repository), {}, {
764
+ },
765
+ origin: {
766
+ ...pullRequest.repository,
764
767
  pullRequest
765
- })
768
+ }
766
769
  };
767
- store.writeQuery(_objectSpread(_objectSpread({}, this.getBranchQuery(branchName, owner, name)), {}, {
770
+ store.writeQuery({
771
+ ...this.getBranchQuery(branchName, owner, name),
768
772
  data: branchData
769
- }));
770
- store.writeQuery(_objectSpread(_objectSpread({}, this.getPullRequestAndBranchQuery(branchName, pullRequest.number)), {}, {
773
+ });
774
+ store.writeQuery({
775
+ ...this.getPullRequestAndBranchQuery(branchName, pullRequest.number),
771
776
  data: pullRequestData
772
- }));
777
+ });
773
778
  }
774
779
  });
775
780
  const {
@@ -798,7 +803,6 @@ class GraphQLAPI extends _API.default {
798
803
  if (data.repository.file) {
799
804
  return data.repository.file.sha;
800
805
  }
801
- throw new _decapCmsLibUtil.APIError('Not Found', 404, _API.API_NAME);
806
+ throw new APIError('Not Found', 404, API_NAME);
802
807
  }
803
- }
804
- exports.default = GraphQLAPI;
808
+ }
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  module.exports = {
4
2
  "__schema": {
5
3
  "types": [{
@@ -1,30 +1,24 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.treeEntry = exports.repository = exports.pullRequest = exports.object = exports.fileEntry = exports.branch = exports.blobWithText = void 0;
7
- var _graphqlTag = require("graphql-tag");
8
- const repository = exports.repository = (0, _graphqlTag.gql)`
1
+ import { gql } from 'graphql-tag';
2
+ export const repository = gql`
9
3
  fragment RepositoryParts on Repository {
10
4
  id
11
5
  isFork
12
6
  }
13
7
  `;
14
- const blobWithText = exports.blobWithText = (0, _graphqlTag.gql)`
8
+ export const blobWithText = gql`
15
9
  fragment BlobWithTextParts on Blob {
16
10
  id
17
11
  text
18
12
  is_binary: isBinary
19
13
  }
20
14
  `;
21
- const object = exports.object = (0, _graphqlTag.gql)`
15
+ export const object = gql`
22
16
  fragment ObjectParts on GitObject {
23
17
  id
24
18
  sha: oid
25
19
  }
26
20
  `;
27
- const branch = exports.branch = (0, _graphqlTag.gql)`
21
+ export const branch = gql`
28
22
  fragment BranchParts on Ref {
29
23
  commit: target {
30
24
  ...ObjectParts
@@ -39,7 +33,7 @@ const branch = exports.branch = (0, _graphqlTag.gql)`
39
33
  ${object}
40
34
  ${repository}
41
35
  `;
42
- const pullRequest = exports.pullRequest = (0, _graphqlTag.gql)`
36
+ export const pullRequest = gql`
43
37
  fragment PullRequestParts on PullRequest {
44
38
  id
45
39
  baseRefName
@@ -69,7 +63,7 @@ const pullRequest = exports.pullRequest = (0, _graphqlTag.gql)`
69
63
  }
70
64
  ${repository}
71
65
  `;
72
- const treeEntry = exports.treeEntry = (0, _graphqlTag.gql)`
66
+ export const treeEntry = gql`
73
67
  fragment TreeEntryParts on TreeEntry {
74
68
  path: name
75
69
  sha: oid
@@ -77,7 +71,7 @@ const treeEntry = exports.treeEntry = (0, _graphqlTag.gql)`
77
71
  mode
78
72
  }
79
73
  `;
80
- const fileEntry = exports.fileEntry = (0, _graphqlTag.gql)`
74
+ export const fileEntry = gql`
81
75
  fragment FileEntryParts on TreeEntry {
82
76
  name
83
77
  sha: oid