import { PubSub, withFilter } from 'graphql-subscriptions'; import { IGitStatusResult, IResolvers } from '@git-stack/core'; import { IResolverOptions } from '@common-stack/server-core'; export const resolver: (options: IResolverOptions) => IResolvers = (options: IResolverOptions) => ({ Query: { getCommit(root, { ref }, ctx) { return ctx.gitService.getCommit(ref); }, refs(root, args, ctx) { return ctx.gitService.getRefs(); }, status(root, args, ctx): Promise { return ctx.gitService.status(); }, stashes(root, args, ctx) { return ctx.gitService.getStashes(); }, gitContent(root, args, ctx) { return ctx.gitService.getHeadContent(args.resource); }, init(root, args, ctx) { return ctx.gitService.init(); }, async fetch(root, args, ctx) { await ctx.gitService.fetch(args.remote); return true; }, }, Mutation: { async open(root, args, ctx) { if (!args.path) { return; } await ctx.gitService.openRepository(args.path); const openStatus = await ctx.gitService.status(); return { openStatus }; }, async changeRepo(root, args, ctx) { await ctx.gitService.setRepo(args.path); return ctx.gitService.status(); }, close(root, args, ctx) { ctx.gitService.close(args.path); return { newPath: '', isClosed: true, }; }, add(root, args, ctx): Promise { return ctx.gitService.add(args.paths); }, pull(root, args, ctx) { return ctx.gitService.pull(args.options); }, push(root, args, ctx) { return ctx.gitService.push(args.remote, args.name, args.options); }, unstage(root, args, ctx): Promise { return ctx.gitService.reset(args.paths); }, clean(root, args, ctx) { return ctx.gitService.discartChanges(args.paths); }, commit(root, args, ctx) { return ctx.gitService.commit(args.message, args.opts); }, commitAll(root, args, ctx) { return ctx.gitService.commitAll(args.message, args.opts); }, stash(root, args, ctx): Promise { return ctx.gitService.stash(args.message); }, unstash(root, args, ctx): Promise { return ctx.gitService.unstash(args.index); }, sync(root, args, ctx) { return ctx.gitService.sync(args.options); }, clone(root, args, ctx) { return ctx.gitService.clone(args.url, args.path, args.options as any); }, createBranch(root, args, ctx) { return ctx.gitService.createBranch(args.name, args.checkout); }, tag(root, args, ctx) { return ctx.gitService.tag(args.name, args.message); }, deleteBranch(root, args, ctx) { return ctx.gitService.deleteBranch(args.name); }, checkout(root, args, ctx) { return ctx.gitService.checkout(args.name, args.options); }, merge(root, args, ctx) { return ctx.gitService.merge(args.branch); }, undoLastCommit(root, args, ctx) { return ctx.gitService.undoLastCommit(); }, setGlobalData(root, args, ctx) { options.logger.info('(setGlobalData) args: [%j]', args); return ctx.gitService.setGlobalData(args.type, args.data, args.options); }, }, Subscription: { gitContentData: { subscribe: withFilter(() => options.pubsub.asyncIterator(`GIT_CONTENT_DATA_SUBSCRIPTIONS`), (payload, variables) => { return true; }, ), }, }, });