Skip to content

Commit 290785f

Browse files
authored
Merge pull request #315 from dolthub/liuliu/pull-and-push
Graphql, Web: pull from and push to remotes
2 parents 2ff83fc + 665e169 commit 290785f

File tree

24 files changed

+669
-41
lines changed

24 files changed

+669
-41
lines changed

graphql-server/schema.gql

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,17 @@ type RemoteList {
291291
list: [Remote!]!
292292
}
293293

294+
type PullRes {
295+
fastForward: Boolean!
296+
conflicts: Int!
297+
message: String!
298+
}
299+
300+
type PushRes {
301+
success: Boolean!
302+
message: String!
303+
}
304+
294305
type Query {
295306
branch(databaseName: String!, branchName: String!): Branch
296307
branchOrDefault(databaseName: String!, branchName: String): Branch
@@ -361,8 +372,10 @@ type Mutation {
361372
resetDatabase(newDatabase: String): Boolean!
362373
loadDataFile(schemaName: String, tableName: String!, refName: String!, databaseName: String!, importOp: ImportOperation!, fileType: FileType!, file: Upload!, modifier: LoadDataModifier): Boolean!
363374
mergePull(fromBranchName: String!, toBranchName: String!, databaseName: String!, author: AuthorInfo): Boolean!
364-
addRemote(databaseName: String!, remoteName: String!, remoteUrl: String!): String!
375+
addRemote(remoteName: String!, databaseName: String!, remoteUrl: String!): String!
365376
deleteRemote(databaseName: String!, remoteName: String!): Boolean!
377+
pullFromRemote(remoteName: String!, databaseName: String!, branchName: String!): PullRes!
378+
pushToRemote(remoteName: String!, databaseName: String!, branchName: String!): PushRes!
366379
restoreAllTables(databaseName: String!, refName: String!): Boolean!
367380
createTag(tagName: String!, databaseName: String!, message: String, fromRefName: String!, author: AuthorInfo): String!
368381
deleteTag(databaseName: String!, tagName: String!): Boolean!

graphql-server/src/queryFactory/dolt/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,22 @@ export class DoltQueryFactory
457457
args.databaseName,
458458
);
459459
}
460+
461+
async callPullRemote(args: t.PushOrPullRemoteArgs): t.PR {
462+
return this.query(
463+
qh.callPullRemote,
464+
[args.remoteName, args.branchName],
465+
args.databaseName,
466+
);
467+
}
468+
469+
async callPushRemote(args: t.PushOrPullRemoteArgs): t.PR {
470+
return this.query(
471+
qh.callPushRemote,
472+
[args.remoteName, args.branchName],
473+
args.databaseName,
474+
);
475+
}
460476
}
461477

462478
async function getTableInfoWithQR(

graphql-server/src/queryFactory/dolt/queries.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ export const callAddRemote = `CALL DOLT_REMOTE("add", ?, ?)`;
8080

8181
export const callDeleteRemote = `CALL DOLT_REMOTE("remove", ?)`;
8282

83+
export const callPullRemote = `CALL DOLT_PULL(?, ?)`;
84+
85+
export const callPushRemote = `CALL DOLT_PUSH(?, ?)`;
86+
8387
// TAGS
8488

8589
export const callDeleteTag = `CALL DOLT_TAG("-d", ?)`;

graphql-server/src/queryFactory/doltgres/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,22 @@ export class DoltgresQueryFactory
448448
args.databaseName,
449449
);
450450
}
451+
452+
async callPullRemote(args: t.PushOrPullRemoteArgs): t.PR {
453+
return this.query(
454+
qh.callPullRemote,
455+
[args.remoteName, args.branchName],
456+
args.databaseName,
457+
);
458+
}
459+
460+
async callPushRemote(args: t.PushOrPullRemoteArgs): t.PR {
461+
return this.query(
462+
qh.callPushRemote,
463+
[args.remoteName, args.branchName],
464+
args.databaseName,
465+
);
466+
}
451467
}
452468

453469
async function getTableInfoWithQR(

graphql-server/src/queryFactory/doltgres/queries.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,7 @@ export const callCheckoutTable = `SELECT DOLT_CHECKOUT($1::text)`;
166166
export const callAddRemote = `SELECT DOLT_REMOTE('add', $1::text, $2::text)`;
167167

168168
export const callDeleteRemote = `SELECT DOLT_REMOTE('remove', $1::text)`;
169+
170+
export const callPullRemote = `SELECT DOLT_PULL($1::text, $2::text)`;
171+
172+
export const callPushRemote = `SELECT DOLT_PUSH($1::text, $2::text)`;

graphql-server/src/queryFactory/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,8 @@ export declare class QueryFactory {
150150
addRemote(args: t.AddRemoteArgs): t.PR;
151151

152152
callDeleteRemote(args: t.RemoteArgs): t.PR;
153+
154+
callPullRemote(args: t.PushOrPullRemoteArgs): t.PR;
155+
156+
callPushRemote(args: t.PushOrPullRemoteArgs): t.PR;
153157
}

graphql-server/src/queryFactory/mysql/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,12 @@ export class MySQLQueryFactory
313313
async callDeleteRemote(_: t.RemoteArgs): t.PR {
314314
throw notDoltError("delete remote");
315315
}
316+
317+
async callPullRemote(_: t.PushOrPullRemoteArgs): t.PR {
318+
throw notDoltError("pull remote");
319+
}
320+
321+
async callPushRemote(_: t.PushOrPullRemoteArgs): t.PR {
322+
throw notDoltError("push remote");
323+
}
316324
}

graphql-server/src/queryFactory/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type RefMaybeSchemaArgs = RefArgs & { schemaName?: string };
99
export type BranchArgs = DBArgs & { branchName: string };
1010
export type RemoteArgs = DBArgs & { remoteName: string };
1111
export type AddRemoteArgs = RemoteArgs & { remoteUrl: string };
12+
export type PushOrPullRemoteArgs = RemoteArgs & { branchName?: string };
1213
export type TagArgs = DBArgs & { tagName: string };
1314
export type TableArgs = RefArgs & { tableName: string };
1415
export type TableMaybeSchemaArgs = TableArgs & { schemaName?: string };

graphql-server/src/remotes/remote.model.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Field, ID, ObjectType } from "@nestjs/graphql";
1+
import { Field, ID, Int, ObjectType } from "@nestjs/graphql";
22
import { __Type } from "graphql";
33
import { getNextOffset, ROW_LIMIT } from "../utils";
44
import { RawRow } from "../queryFactory/types";
@@ -25,6 +25,27 @@ export class RemoteList extends ListOffsetRes {
2525
list: Remote[];
2626
}
2727

28+
@ObjectType()
29+
export class PullRes {
30+
@Field()
31+
fastForward: boolean;
32+
33+
@Field(_type => Int)
34+
conflicts: number;
35+
36+
@Field()
37+
message: string;
38+
}
39+
40+
@ObjectType()
41+
export class PushRes {
42+
@Field()
43+
success: boolean;
44+
45+
@Field()
46+
message: string;
47+
}
48+
2849
export function fromDoltRemotesRow(databaseName: string, r: RawRow): Remote {
2950
return {
3051
_id: `databases/${databaseName}/remotes/${r.name}`,
@@ -45,3 +66,18 @@ export function getRemoteListRes(
4566
nextOffset: getNextOffset(remotes.length, args.offset ?? 0),
4667
};
4768
}
69+
70+
export function fromPullRes(r: RawRow): PullRes {
71+
return {
72+
fastForward: r.fast_forward === "1",
73+
conflicts: parseInt(r.conflicts, 10),
74+
message: r.message,
75+
};
76+
}
77+
78+
export function fromPushRes(r: RawRow): PushRes {
79+
return {
80+
success: r.status === "0",
81+
message: r.message,
82+
};
83+
}

graphql-server/src/remotes/remote.resolver.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,27 @@ import {
77
Resolver,
88
} from "@nestjs/graphql";
99
import { ConnectionProvider } from "../connections/connection.provider";
10-
import { DBArgs, DBArgsWithOffset, RemoteArgs } from "../utils/commonTypes";
11-
import { getRemoteListRes, Remote, RemoteList } from "./remote.model";
10+
import { DBArgsWithOffset, RemoteArgs } from "../utils/commonTypes";
11+
import {
12+
fromPullRes,
13+
fromPushRes,
14+
getRemoteListRes,
15+
PullRes,
16+
PushRes,
17+
Remote,
18+
RemoteList,
19+
} from "./remote.model";
1220

1321
@ArgsType()
14-
export class AddRemoteArgs extends DBArgs {
22+
export class AddRemoteArgs extends RemoteArgs {
1523
@Field()
16-
remoteName: string;
24+
remoteUrl: string;
25+
}
1726

27+
@ArgsType()
28+
export class PullOrPushRemoteArgs extends RemoteArgs {
1829
@Field()
19-
remoteUrl: string;
30+
branchName: string;
2031
}
2132

2233
@Resolver(_of => Remote)
@@ -44,4 +55,24 @@ export class RemoteResolver {
4455
await conn.callDeleteRemote(args);
4556
return true;
4657
}
58+
59+
@Mutation(_returns => PullRes)
60+
async pullFromRemote(@Args() args: PullOrPushRemoteArgs): Promise<PullRes> {
61+
const conn = this.conn.connection();
62+
const res = await conn.callPullRemote(args);
63+
if (res.length === 0) {
64+
throw new Error("No response from pull");
65+
}
66+
return fromPullRes(res[0]);
67+
}
68+
69+
@Mutation(_returns => PushRes)
70+
async pushToRemote(@Args() args: PullOrPushRemoteArgs): Promise<PushRes> {
71+
const conn = this.conn.connection();
72+
const res = await conn.callPushRemote(args);
73+
if (res.length === 0) {
74+
throw new Error("No response from push");
75+
}
76+
return fromPushRes(res[0]);
77+
}
4778
}

0 commit comments

Comments
 (0)