Skip to content

Commit

Permalink
Merge pull request #347 from dolthub/liuliu/not-fetch-from-specific-b…
Browse files Browse the repository at this point in the history
…ranch

Graphql, Web: do not fetch from a specific branch when fetching all remote branches
  • Loading branch information
liuliu-dev authored Jan 6, 2025
2 parents 8d4890f + 0e7beaf commit 1eb0744
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 45 deletions.
2 changes: 1 addition & 1 deletion graphql-server/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ type Query {
docOrDefaultDoc(refName: String!, databaseName: String!, docType: DocType): Doc
pullWithDetails(databaseName: String!, fromBranchName: String!, toBranchName: String!): PullWithDetails!
remotes(databaseName: String!, offset: Int): RemoteList!
fetchRemote(remoteName: String!, databaseName: String!, branchName: String): FetchRes!
fetchRemote(databaseName: String!, remoteName: String!): FetchRes!
remoteBranchDiffCounts(databaseName: String!, fromRefName: String!, toRefName: String!): RemoteBranchDiffCounts!
rowDiffs(offset: Int, databaseName: String!, fromRefName: String!, toRefName: String!, refName: String, tableName: String!, filterByRowType: DiffRowType, type: CommitDiffType): RowDiffList!
rows(schemaName: String, refName: String!, databaseName: String!, tableName: String!, offset: Int): RowList!
Expand Down
8 changes: 2 additions & 6 deletions graphql-server/src/queryFactory/dolt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,8 @@ export class DoltQueryFactory
);
}

async callFetchRemote(args: t.RemoteMaybeBranchArgs): t.PR {
return this.query(
qh.callFetchRemote(!!args.branchName),
[args.remoteName, args.branchName],
args.databaseName,
);
async callFetchRemote(args: t.RemoteArgs): t.PR {
return this.query(qh.callFetchRemote, [args.remoteName], args.databaseName);
}

async getMergeBase(args: t.RefsArgs): Promise<string> {
Expand Down
3 changes: 1 addition & 2 deletions graphql-server/src/queryFactory/dolt/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ export const callPullRemote = `CALL DOLT_PULL(?, ?)`;

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

export const callFetchRemote = (hasBranchName?: boolean) =>
`CALL DOLT_FETCH(?${hasBranchName ? ", ?" : ""})`;
export const callFetchRemote = `CALL DOLT_FETCH(?)`;

// TAGS

Expand Down
8 changes: 2 additions & 6 deletions graphql-server/src/queryFactory/doltgres/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,8 @@ export class DoltgresQueryFactory
);
}

async callFetchRemote(args: t.RemoteMaybeBranchArgs): t.PR {
return this.query(
qh.callFetchRemote(!!args.branchName),
[args.remoteName, args.branchName],
args.databaseName,
);
async callFetchRemote(args: t.RemoteArgs): t.PR {
return this.query(qh.callFetchRemote, [args.remoteName], args.databaseName);
}
}

Expand Down
5 changes: 1 addition & 4 deletions graphql-server/src/queryFactory/doltgres/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,4 @@ export const callPullRemote = `SELECT DOLT_PULL($1::text, $2::text)`;

export const callPushRemote = `SELECT DOLT_PUSH($1::text, $2::text)`;

export const callFetchRemote = (hasBranchName?: boolean) =>
hasBranchName
? `SELECT DOLT_FETCH($1::text, $2::text)`
: `SELECT DOLT_FETCH($1::text)`;
export const callFetchRemote = `SELECT DOLT_FETCH($1::text)`;
2 changes: 1 addition & 1 deletion graphql-server/src/queryFactory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export declare class QueryFactory {

callPushRemote(args: t.RemoteMaybeBranchArgs): t.PR;

callFetchRemote(args: t.RemoteMaybeBranchArgs): t.PR;
callFetchRemote(args: t.RemoteArgs): t.PR;

getMergeBase(args: t.RefsArgs): Promise<string>;
}
2 changes: 1 addition & 1 deletion graphql-server/src/queryFactory/mysql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export class MySQLQueryFactory
throw notDoltError("push remote");
}

async callFetchRemote(_: t.RemoteMaybeBranchArgs): t.PR {
async callFetchRemote(_: t.RemoteArgs): t.PR {
throw notDoltError("fetch remote");
}

Expand Down
2 changes: 1 addition & 1 deletion graphql-server/src/remotes/remote.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class RemoteResolver {
}

@Query(_returns => FetchRes)
async fetchRemote(@Args() args: RemoteMaybeBranchArgs): Promise<FetchRes> {
async fetchRemote(@Args() args: RemoteArgs): Promise<FetchRes> {
const conn = this.conn.connection();
const res = await conn.callFetchRemote(args);
if (res.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { HiRefresh } from "@react-icons/all-files/hi/HiRefresh";
import { DropdownItem } from "@components/DatabaseOptionsDropdown";
import { RemoteFragment, useFetchRemoteLazyQuery } from "@gen/graphql-types";
import { OptionalRefParams } from "@lib/params";
import useDefaultBranch from "@hooks/useDefaultBranch";
import { SmallLoader } from "@dolthub/react-components";
import { useState } from "react";
import { SetApolloErrorType } from "@lib/errors/types";
Expand All @@ -21,8 +20,6 @@ export default function FetchButton({
params,
remote,
}: Props) {
const { defaultBranchName } = useDefaultBranch(params);
const branchName = params.refName || defaultBranchName;
const [fetch] = useFetchRemoteLazyQuery();
const [loading, setLoading] = useState(false);

Expand All @@ -32,13 +29,13 @@ export default function FetchButton({
variables: {
databaseName: params.databaseName,
remoteName: remote.name,
branchName,
},
fetchPolicy: "network-only",
});
setLoading(false);
if (!fetchRes.data?.fetchRemote.success) {
setErr(fetchRes.error || new Error("Fetch failed"));
setFetchModalOpen(true);
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { gql } from "@apollo/client";

export const FETCH_REMOTE = gql`
query FetchRemote(
$remoteName: String!
$databaseName: String!
$branchName: String
) {
fetchRemote(
remoteName: $remoteName
databaseName: $databaseName
branchName: $branchName
) {
query FetchRemote($remoteName: String!, $databaseName: String!) {
fetchRemote(remoteName: $remoteName, databaseName: $databaseName) {
success
}
}
Expand Down
11 changes: 2 additions & 9 deletions web/renderer/gen/graphql-types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ export type QueryDoltSchemasArgs = {


export type QueryFetchRemoteArgs = {
branchName?: InputMaybe<Scalars['String']['input']>;
databaseName: Scalars['String']['input'];
remoteName: Scalars['String']['input'];
};
Expand Down Expand Up @@ -1285,7 +1284,6 @@ export type AddRemoteMutation = { __typename?: 'Mutation', addRemote: string };
export type FetchRemoteQueryVariables = Exact<{
remoteName: Scalars['String']['input'];
databaseName: Scalars['String']['input'];
branchName?: InputMaybe<Scalars['String']['input']>;
}>;


Expand Down Expand Up @@ -3741,12 +3739,8 @@ export type AddRemoteMutationHookResult = ReturnType<typeof useAddRemoteMutation
export type AddRemoteMutationResult = Apollo.MutationResult<AddRemoteMutation>;
export type AddRemoteMutationOptions = Apollo.BaseMutationOptions<AddRemoteMutation, AddRemoteMutationVariables>;
export const FetchRemoteDocument = gql`
query FetchRemote($remoteName: String!, $databaseName: String!, $branchName: String) {
fetchRemote(
remoteName: $remoteName
databaseName: $databaseName
branchName: $branchName
) {
query FetchRemote($remoteName: String!, $databaseName: String!) {
fetchRemote(remoteName: $remoteName, databaseName: $databaseName) {
success
}
}
Expand All @@ -3766,7 +3760,6 @@ export const FetchRemoteDocument = gql`
* variables: {
* remoteName: // value for 'remoteName'
* databaseName: // value for 'databaseName'
* branchName: // value for 'branchName'
* },
* });
*/
Expand Down

0 comments on commit 1eb0744

Please sign in to comment.