-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web,graphql: Refactor schemas and procedures
- Loading branch information
Showing
18 changed files
with
153 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Field, ObjectType } from "@nestjs/graphql"; | ||
|
||
@ObjectType() | ||
export class SchemaItem { | ||
@Field() | ||
name: string; | ||
|
||
@Field() | ||
type: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { DoltSystemTable } from "../systemTables/systemTable.enums"; | ||
|
||
export const getDoltSchemasQuery = (hasWhereCause = false): string => | ||
`SELECT * FROM ${DoltSystemTable.SCHEMAS}${ | ||
hasWhereCause ? " WHERE type = ?" : "" | ||
}`; | ||
|
||
export const doltProceduresQuery = `SELECT * FROM ${DoltSystemTable.PROCEDURES}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Args, Query, Resolver } from "@nestjs/graphql"; | ||
import { handleTableNotFound } from "src/tables/table.resolver"; | ||
import { DataSourceService } from "../dataSources/dataSource.service"; | ||
import { RefArgs } from "../utils/commonTypes"; | ||
import { SchemaItem } from "./schema.model"; | ||
import { doltProceduresQuery, getDoltSchemasQuery } from "./schema.queries"; | ||
|
||
@Resolver(_of => SchemaItem) | ||
export class SchemaResolver { | ||
constructor(private readonly dss: DataSourceService) {} | ||
|
||
@Query(_returns => [SchemaItem]) | ||
async doltSchemas( | ||
@Args() args: RefArgs, | ||
type?: string, | ||
): Promise<SchemaItem[]> { | ||
return this.dss.queryMaybeDolt( | ||
async (query, isDolt) => { | ||
const res = await handleTableNotFound(async () => | ||
query(getDoltSchemasQuery(!!type), [type]), | ||
); | ||
if (!res) return []; | ||
return res.map(r => { | ||
return { name: r.name, type: r.type }; | ||
}); | ||
}, | ||
args.databaseName, | ||
args.refName, | ||
); | ||
} | ||
|
||
@Query(_returns => [SchemaItem]) | ||
async views(@Args() args: RefArgs): Promise<SchemaItem[]> { | ||
return this.doltSchemas(args, "view"); | ||
} | ||
|
||
@Query(_returns => [SchemaItem]) | ||
async doltProcedures(@Args() args: RefArgs): Promise<[SchemaItem]> { | ||
return this.dss.queryMaybeDolt( | ||
async (query, isDolt) => { | ||
const res = await handleTableNotFound(async () => | ||
query(doltProceduresQuery), | ||
); | ||
if (!res) return []; | ||
return res.map(r => { | ||
return { name: r.name, type: "procedure" }; | ||
}); | ||
}, | ||
args.databaseName, | ||
args.refName, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import { gql } from "@apollo/client"; | ||
|
||
export const ROWS_FOR_SCHEMAS = gql` | ||
fragment SchemaItem on SchemaItem { | ||
name | ||
type | ||
} | ||
query RowsForDoltSchemas($databaseName: String!, $refName: String!) { | ||
doltSchemas(databaseName: $databaseName, refName: $refName) { | ||
list { | ||
...RowForSchemas | ||
} | ||
...SchemaItem | ||
} | ||
} | ||
`; | ||
|
||
export const ROWS_FOR_PROCEDURES = gql` | ||
query RowsForDoltProcedures($databaseName: String!, $refName: String!) { | ||
doltProcedures(databaseName: $databaseName, refName: $refName) { | ||
list { | ||
...RowForSchemas | ||
} | ||
...SchemaItem | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.