Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphql, Web: pull from and push to remotes #315

Merged
merged 12 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion graphql-server/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,17 @@ type RemoteList {
list: [Remote!]!
}

type PullRes {
fastForward: String!
conflicts: String!
message: String!
}

type PushRes {
status: String!
message: String!
}

type Query {
branch(databaseName: String!, branchName: String!): Branch
branchOrDefault(databaseName: String!, branchName: String): Branch
Expand Down Expand Up @@ -361,8 +372,10 @@ type Mutation {
resetDatabase(newDatabase: String): Boolean!
loadDataFile(schemaName: String, tableName: String!, refName: String!, databaseName: String!, importOp: ImportOperation!, fileType: FileType!, file: Upload!, modifier: LoadDataModifier): Boolean!
mergePull(fromBranchName: String!, toBranchName: String!, databaseName: String!, author: AuthorInfo): Boolean!
addRemote(databaseName: String!, remoteName: String!, remoteUrl: String!): String!
addRemote(remoteName: String!, databaseName: String!, remoteUrl: String!): String!
deleteRemote(databaseName: String!, remoteName: String!): Boolean!
pullFromRemote(remoteName: String!, databaseName: String!, branchName: String!): PullRes!
pushToRemote(remoteName: String!, databaseName: String!, branchName: String!): PushRes!
restoreAllTables(databaseName: String!, refName: String!): Boolean!
createTag(tagName: String!, databaseName: String!, message: String, fromRefName: String!, author: AuthorInfo): String!
deleteTag(databaseName: String!, tagName: String!): Boolean!
Expand Down
16 changes: 16 additions & 0 deletions graphql-server/src/queryFactory/dolt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,14 @@
async restoreAllTables(args: t.RefArgs): t.PR {
return this.queryQR(
async qr => {
console.log("[restore_all]: starting transaction");

Check warning on line 396 in graphql-server/src/queryFactory/dolt/index.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
await qr.query("BEGIN");

console.log("[restore_all]: calling");

Check warning on line 399 in graphql-server/src/queryFactory/dolt/index.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
const res = await qr.query(qh.callResetHard);

if (res.length && res[0].status !== "0") {
console.log("[restore_all]: reset not successful, rolling back");

Check warning on line 403 in graphql-server/src/queryFactory/dolt/index.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
await qr.query("ROLLBACK");
throw new Error("Reset --hard not successful");
}
Expand All @@ -410,12 +410,12 @@

if (status.length) {
status.forEach(async r => {
console.log("[restore_all]: checking out new table", r.table_name);

Check warning on line 413 in graphql-server/src/queryFactory/dolt/index.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
const checkRes = await qr.query(qh.callCheckoutTable, [
r.table_name,
]);
if (checkRes.length && checkRes[0].status !== "0") {
console.log(

Check warning on line 418 in graphql-server/src/queryFactory/dolt/index.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
"[restore_all]: checkout not successful, rolling back",
);
await qr.query("ROLLBACK");
Expand Down Expand Up @@ -457,6 +457,22 @@
args.databaseName,
);
}

async callPullRemote(args: t.PushOrPullRemoteArgs): t.PR {
return this.query(
qh.callPullRemote,
[args.remoteName, args.branchName],
args.databaseName,
);
}

async callPushRemote(args: t.PushOrPullRemoteArgs): t.PR {
return this.query(
qh.callPushRemote,
[args.remoteName, args.branchName],
args.databaseName,
);
}
}

async function getTableInfoWithQR(
Expand Down
4 changes: 4 additions & 0 deletions graphql-server/src/queryFactory/dolt/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export const callAddRemote = `CALL DOLT_REMOTE("add", ?, ?)`;

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

export const callPullRemote = `CALL DOLT_PULL(?, ?)`;

export const callPushRemote = `CALL DOLT_PUSH(?, ?)`;

// TAGS

export const callDeleteTag = `CALL DOLT_TAG("-d", ?)`;
Expand Down
16 changes: 16 additions & 0 deletions graphql-server/src/queryFactory/doltgres/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,22 @@ export class DoltgresQueryFactory
args.databaseName,
);
}

async callPullRemote(args: t.PushOrPullRemoteArgs): t.PR {
return this.query(
qh.callPullRemote,
[args.remoteName, args.branchName],
args.databaseName,
);
}

async callPushRemote(args: t.PushOrPullRemoteArgs): t.PR {
return this.query(
qh.callPushRemote,
[args.remoteName, args.branchName],
args.databaseName,
);
}
}

async function getTableInfoWithQR(
Expand Down
4 changes: 4 additions & 0 deletions graphql-server/src/queryFactory/doltgres/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,7 @@ export const callCheckoutTable = `SELECT DOLT_CHECKOUT($1::text)`;
export const callAddRemote = `SELECT DOLT_REMOTE('add', $1::text, $2::text)`;

export const callDeleteRemote = `SELECT DOLT_REMOTE('remove', $1::text)`;

export const callPullRemote = `SELECT DOLT_PULL($1::text, $2::text)`;

export const callPushRemote = `SELECT DOLT_PUSH($1::text, $2::text)`;
4 changes: 4 additions & 0 deletions graphql-server/src/queryFactory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,8 @@ export declare class QueryFactory {
addRemote(args: t.AddRemoteArgs): t.PR;

callDeleteRemote(args: t.RemoteArgs): t.PR;

callPullRemote(args: t.PushOrPullRemoteArgs): t.PR;

callPushRemote(args: t.PushOrPullRemoteArgs): t.PR;
}
8 changes: 8 additions & 0 deletions graphql-server/src/queryFactory/mysql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,12 @@ export class MySQLQueryFactory
async callDeleteRemote(_: t.RemoteArgs): t.PR {
throw notDoltError("delete remote");
}

async callPullRemote(_: t.PushOrPullRemoteArgs): t.PR {
throw notDoltError("pull remote");
}

async callPushRemote(_: t.PushOrPullRemoteArgs): t.PR {
throw notDoltError("push remote");
}
}
1 change: 1 addition & 0 deletions graphql-server/src/queryFactory/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type RefMaybeSchemaArgs = RefArgs & { schemaName?: string };
export type BranchArgs = DBArgs & { branchName: string };
export type RemoteArgs = DBArgs & { remoteName: string };
export type AddRemoteArgs = RemoteArgs & { remoteUrl: string };
export type PushOrPullRemoteArgs = RemoteArgs & { branchName?: string };
export type TagArgs = DBArgs & { tagName: string };
export type TableArgs = RefArgs & { tableName: string };
export type TableMaybeSchemaArgs = TableArgs & { schemaName?: string };
Expand Down
36 changes: 36 additions & 0 deletions graphql-server/src/remotes/remote.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ export class RemoteList extends ListOffsetRes {
list: Remote[];
}

@ObjectType()
export class PullRes {
@Field()
fastForward: string;

@Field()
conflicts: string;
liuliu-dev marked this conversation as resolved.
Show resolved Hide resolved

@Field()
message: string;
}

@ObjectType()
export class PushRes {
@Field()
status: string;
liuliu-dev marked this conversation as resolved.
Show resolved Hide resolved

@Field()
message: string;
}

export function fromDoltRemotesRow(databaseName: string, r: RawRow): Remote {
return {
_id: `databases/${databaseName}/remotes/${r.name}`,
Expand All @@ -45,3 +66,18 @@ export function getRemoteListRes(
nextOffset: getNextOffset(remotes.length, args.offset ?? 0),
};
}

export function fromPullRes(r: RawRow): PullRes {
return {
fastForward: r.fast_forward,
conflicts: r.conflicts,
message: r.message,
};
}

export function fromPushRes(r: RawRow): PushRes {
return {
status: r.status,
message: r.message,
};
}
35 changes: 30 additions & 5 deletions graphql-server/src/remotes/remote.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,27 @@ import {
Resolver,
} from "@nestjs/graphql";
import { ConnectionProvider } from "../connections/connection.provider";
import { DBArgs, DBArgsWithOffset, RemoteArgs } from "../utils/commonTypes";
import { getRemoteListRes, Remote, RemoteList } from "./remote.model";
import { DBArgsWithOffset, RemoteArgs } from "../utils/commonTypes";
import {
fromPullRes,
fromPushRes,
getRemoteListRes,
PullRes,
PushRes,
Remote,
RemoteList,
} from "./remote.model";

@ArgsType()
export class AddRemoteArgs extends DBArgs {
export class AddRemoteArgs extends RemoteArgs {
@Field()
remoteName: string;
remoteUrl: string;
}

@ArgsType()
export class PullOrPushRemoteArgs extends RemoteArgs {
@Field()
remoteUrl: string;
branchName: string;
}

@Resolver(_of => Remote)
Expand Down Expand Up @@ -44,4 +55,18 @@ export class RemoteResolver {
await conn.callDeleteRemote(args);
return true;
}

@Mutation(_returns => PullRes)
async pullFromRemote(@Args() args: PullOrPushRemoteArgs): Promise<PullRes> {
const conn = this.conn.connection();
const res = await conn.callPullRemote(args);
return fromPullRes(res[0]);
}

@Mutation(_returns => PushRes)
async pushToRemote(@Args() args: PullOrPushRemoteArgs): Promise<PushRes> {
const conn = this.conn.connection();
const res = await conn.callPushRemote(args);
return fromPushRes(res[0]);
liuliu-dev marked this conversation as resolved.
Show resolved Hide resolved
}
}
4 changes: 2 additions & 2 deletions web/renderer/components/SqlDataTable/useSqlQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { useSessionQueryHistory } from "@dolthub/react-hooks";
import useSqlParser from "@hooks/useSqlParser";
import { SqlQueryParams } from "@lib/params";
import { refetchSqlUpdateQueriesCacheEvict } from "@lib/refetchQueries";
import { refetchUpdateDatabaseQueriesCacheEvict } from "@lib/refetchQueries";
import { databases } from "@lib/urls";
import { useRouter } from "next/router";
import { useEffect } from "react";
Expand All @@ -33,7 +33,7 @@ export default function useSqlQuery(
// time to finish
setTimeout(() => {
client
.refetchQueries(refetchSqlUpdateQueriesCacheEvict)
.refetchQueries(refetchUpdateDatabaseQueriesCacheEvict)
.catch(console.error);
}, 300);
}, [gqlError, isMut, client]);
Expand Down
4 changes: 2 additions & 2 deletions web/renderer/components/StatusWithOptions/ResetModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useSqlBuilder from "@hooks/useSqlBuilder";
import { ModalProps } from "@lib/modalProps";
import { RefParams } from "@lib/params";
import { getPostgresTableName } from "@lib/postgres";
import { refetchSqlUpdateQueriesCacheEvict } from "@lib/refetchQueries";
import { refetchUpdateDatabaseQueriesCacheEvict } from "@lib/refetchQueries";
import { sqlQuery } from "@lib/urls";
import css from "./index.module.css";

Expand All @@ -27,7 +27,7 @@ export default function ResetModal(props: Props) {
await mutateFn({ variables: props.params });
props.setIsOpen(false);
client
.refetchQueries(refetchSqlUpdateQueriesCacheEvict)
.refetchQueries(refetchUpdateDatabaseQueriesCacheEvict)
.catch(console.error);
} catch (_) {
// Handled by useMutation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DatabaseParams } from "@lib/params";
import { OptionalRefParams } from "@lib/params";
import AddRemoteForm from "./AddRemoteForm";
import css from "./index.module.css";

type Props = {
params: DatabaseParams;
params: OptionalRefParams;
};

export default function AddRemotePage(props: Props): JSX.Element {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { newRemote } from "@lib/urls";
import { useState } from "react";
import DeleteModal from "@components/DeleteModal";
import { refetchRemoteQueries } from "@lib/refetchQueries";
import { DatabaseParams } from "@lib/params";
import { OptionalRefParams } from "@lib/params";
import RemoteRow from "./RemoteRow";
import css from "./index.module.css";

type InnerProps = {
params: DatabaseParams;
params: OptionalRefParams;
remotes: RemoteFragment[];
loadMore: () => Promise<void>;
hasMore: boolean;
Expand Down
Loading
Loading