MCPcopy Create free account
hub / github.com/decaporg/decap-cms / API

Class API

packages/decap-cms-backend-gitlab/src/API.ts:211–1033  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211export default class API {
212 apiRoot: string;
213 graphQLAPIRoot: string;
214 token: string | boolean;
215 branch: string;
216 useOpenAuthoring?: boolean;
217 repo: string;
218 repoURL: string;
219 commitAuthor?: CommitAuthor;
220 squashMerges: boolean;
221 initialWorkflowStatus: string;
222 cmsLabelPrefix: string;
223 requestFunction?: (req: ApiRequest) => Promise<Response>;
224
225 graphQLClient?: ApolloClient<NormalizedCacheObject>;
226
227 constructor(config: Config) {
228 this.apiRoot = config.apiRoot || 'https://gitlab.com/api/v4';
229 this.graphQLAPIRoot = config.graphQLAPIRoot || 'https://gitlab.com/api/graphql';
230 this.token = config.token || false;
231 this.requestFunction = config.requestFunction;
232 this.branch = config.branch || 'master';
233 this.repo = config.repo || '';
234 this.repoURL = `/projects/${encodeURIComponent(this.repo)}`;
235 this.squashMerges = config.squashMerges;
236 this.initialWorkflowStatus = config.initialWorkflowStatus;
237 this.cmsLabelPrefix = config.cmsLabelPrefix;
238 if (config.useGraphQL === true) {
239 this.graphQLClient = this.getApolloClient();
240 }
241 }
242
243 getApolloClient() {
244 const authLink = setContext((_, { headers }) => {
245 return {
246 headers: {
247 'Content-Type': 'application/json; charset=utf-8',
248 ...headers,
249 authorization: this.token ? `Bearer ${this.token}` : '',
250 },
251 };
252 });
253 const httpLink = createHttpLink({ uri: this.graphQLAPIRoot });
254 return new ApolloClient({
255 link: authLink.concat(httpLink),
256 cache: new InMemoryCache(),
257 defaultOptions: {
258 watchQuery: {
259 fetchPolicy: NO_CACHE,
260 errorPolicy: 'ignore',
261 },
262 query: {
263 fetchPolicy: NO_CACHE,
264 errorPolicy: 'all',
265 },
266 },
267 });
268 }

Callers

nothing calls this directly

Calls 15

requestMethod · 0.95
getDefaultBranchMethod · 0.95
uploadAndCommitMethod · 0.95
requestWithBackoffFunction · 0.90
responseParserFunction · 0.90
readFileFunction · 0.90
parseLinkHeaderFunction · 0.90
thenFunction · 0.90
getMaxAccessFunction · 0.85
MapInterface · 0.85
batchFunction · 0.85
hasMethod · 0.80

Tested by

no test coverage detected