hasura-utils
v1.0.6
Published
Downloads
28
Readme
hasura-utils
- Installation
- Synopsis
- Details
- API
- hasura-utils
- Classes
- Class: HasuraUtils
- Interfaces
- Interface: HasuraTableName
- Interface: MetaData
- Interface: Options
Installation
Synopsis
Details
API
hasura-utils
Type aliases
NameFunction
Ƭ NameFunction: function
Defined in index.ts:48
Type declaration:
▸ (table
: string, schema?
: undefined | string): string
Parameters:
Name | Type |
------ | ------ |
table
| string |
schema?
| undefined | string |
Operation
Ƭ Operation: "insert" | "select" | "update" | "delete"
Defined in index.ts:49
TableFilterFunction
Ƭ TableFilterFunction: function
Defined in index.ts:50
Type declaration:
▸ (table
: Table): boolean
Parameters:
Name | Type |
------ | ------ |
table
| Table |
Variables
Const
OPERATIONS
• OPERATIONS: Operation[] = ["insert", "select", "update", "delete"]
Defined in index.ts:30
Functions
_untrackTable
▸ _untrackTable(table
: string, schema
: string): object
Defined in migration-commands/untrack-table.ts:1
Parameters:
Name | Type | Default |
------ | ------ | ------ |
table
| string | - |
schema
| string | "public" |
Returns: object
type: string = "untrack_table"
args: object
table: object
name: string = table
schema: string
createDeletePermission
▸ createDeletePermission(table
: string, schema
: string, __namedParameters
: object): object
Defined in migration-commands/create-delete-permission.ts:3
Parameters:
▪ table: string
▪Default value
schema: string= "public"
▪ __namedParameters: object
Name | Type |
------ | ------ |
role
| string |
filter
| object |
Returns: object
createInsertPermission
▸ createInsertPermission(table
: string, schema
: string, __namedParameters
: object): object
Defined in migration-commands/create-insert-permission.ts:3
Parameters:
▪ table: string
▪Default value
schema: string= "public"
▪ __namedParameters: object
Name | Type | Default |
------ | ------ | ------ |
columns
| string[] | [] |
filter
| object | - |
role
| string | - |
set
| object | - |
Returns: object
createSelectPermission
▸ createSelectPermission(table
: string, schema
: string, __namedParameters
: object): object
Defined in migration-commands/create-select-permission.ts:3
Parameters:
▪ table: string
▪Default value
schema: string= "public"
▪ __namedParameters: object
Name | Type | Default |
------ | ------ | ------ |
allowAggregations
| boolean | false |
columns
| string[] | [] |
computedFields
| undefined | string[] | - |
limit
| number | 10000 |
role
| string | - |
filter
| object | - |
Returns: object
createUpdatePermission
▸ createUpdatePermission(table
: string, schema
: string, __namedParameters
: object): object
Defined in migration-commands/create-update-permission.ts:3
Parameters:
▪ table: string
▪Default value
schema: string= "public"
▪ __namedParameters: object
Name | Type | Default |
------ | ------ | ------ |
columns
| string[] | [] |
role
| string | - |
set
| undefined | object | - |
filter
| object | - |
Returns: object
dropPermission
▸ dropPermission(table
: string, schema
: string, __namedParameters
: object): object
Defined in migration-commands/drop-permission.ts:3
Parameters:
▪ table: string
▪Default value
schema: string= "public"
▪ __namedParameters: object
Name | Type |
------ | ------ |
operation
| "insert" | "select" | "update" | "delete" |
role
| string |
Returns: object
formatAndWriteData
▸ formatAndWriteData<T>(data
: T, format?
: "json" | "yaml", file?
: undefined | string): Promise‹string | T›
Defined in helper.ts:8
Type parameters:
▪ T
Parameters:
Name | Type |
------ | ------ |
data
| T |
format?
| "json" | "yaml" |
file?
| undefined | string |
Returns: Promise‹string | T›
getColumnNames
▸ getColumnNames(table
: Table, exclude
: string[]): string[]
Defined in helper.ts:93
Parameters:
Name | Type |
------ | ------ |
table
| Table |
exclude
| string[] |
Returns: string[]
getHasuraCacheRedirectMapSource
▸ getHasuraCacheRedirectMapSource(map
: Record‹string, string›): string
Defined in helper.ts:49
Parameters:
Name | Type |
------ | ------ |
map
| Record‹string, string› |
Returns: string
getMultipleObjectName
▸ getMultipleObjectName(table
: string, schema?
: undefined | string): string
Defined in helper.ts:45
Returns multiple object name used by Hasura for given PostgreSQL table.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
table
| string | is the table name to create single result name. |
schema?
| undefined | string | - |
Returns: string
single object name.
getSingleObjectName
▸ getSingleObjectName(table
: string, schema?
: undefined | string): string
Defined in helper.ts:35
Returns single object name used by Hasura for given PostgreSQL table.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
table
| string | is the table name to create single result name. |
schema?
| undefined | string | - |
Returns: string
single object name.
getTableName
▸ getTableName(table
: string, schema?
: undefined | string): string
Defined in helper.ts:25
Parameters:
Name | Type |
------ | ------ |
table
| string |
schema?
| undefined | string |
Returns: string
trackTable
▸ trackTable(table
: string, schema
: string, options
: object): object
Defined in migration-commands/track-table.ts:4
Parameters:
▪ table: string
▪ schema: string
▪ options: object
Name | Type |
------ | ------ |
getMultipleObjectName
| NameFunction |
getSingleObjectName
| NameFunction |
getTableName
| NameFunction |
Returns: object
type: string = "track_table"
version: number = 2
args: object
configuration: object
custom_root_fields: object
delete: string =
delete${camelize(options.getMultipleObjectName(table, schema))}
insert: string =
add${camelize(options.getMultipleObjectName(table, schema))}
select: string = options.getMultipleObjectName(table, schema)
select_aggregate: string =
${camelize(options.getTableName(table, schema), true)}Aggregate
select_by_pk: string = options.getSingleObjectName(table, schema)
update: string =
update${camelize(options.getMultipleObjectName(table, schema))}
table: object
name: string = table
schema: string
writeMigration
▸ writeMigration(dir
: string, up
: object, down
: object): Promise‹any›
Defined in helper.ts:21
Parameters:
Name | Type |
------ | ------ |
dir
| string |
up
| object |
down
| object |
Returns: Promise‹any›
Object literals
Const
PERMISSION_FUNCTION
▪ PERMISSION_FUNCTION: object
Defined in index.ts:31
delete
• delete: createDeletePermission = createDeletePermission
Defined in index.ts:35
insert
• insert: createInsertPermission = createInsertPermission
Defined in index.ts:32
select
• select: createSelectPermission = createSelectPermission
Defined in index.ts:33
update
• update: createUpdatePermission = createUpdatePermission
Defined in index.ts:34
Classes
Class: HasuraUtils
Hierarchy
- HasuraUtils
Methods
getMetaData
▸ getMetaData(): Promise‹MetaData›
Defined in index.ts:128
Returns: Promise‹MetaData›
getTrackedTables
▸ getTrackedTables(): Promise‹Table[]›
Defined in index.ts:140
Returns: Promise‹Table[]›
writeHasureCacheRedirectMap
▸ writeHasureCacheRedirectMap(file
: string, __namedParameters
: object): Promise‹string›
Defined in index.ts:206
Creates typescript file for mapping (single object name
-> table name
) to be used with cache redirects.
Example
import { InMemoryCache, CacheResolver } from "apollo-cache-inmemory";
function getHasuraCacheRedirects(redirectMap: Record<string, string>): Record<string, CacheResolver> {
const result: Record<string, CacheResolver> = {};
Object.entries(redirectMap).forEach(([singleRecordName, tableName]) => {
result[singleRecordName] = (_, args, { getCacheKey }) => getCacheKey({ __typename: tableName, id: args.id });
});
return result;
}
const cache: InMemoryCache = new InMemoryCache({
cacheRedirects: {
Query: { ...getHasuraCacheRedirects(apolloCacheRedirectMap) }
}
});
see
https://www.apollographql.com/docs/react/caching/cache-interaction/#cache-redirects-with-cacheredirects
see
https://www.apollographql.com/docs/react/performance/performance/
Parameters:
▪ file: string
is the file to wirte mapping.
▪Default value
__namedParameters: object= {}
Name | Type | Default |
------ | ------ | ------ |
onlyTracked
| boolean | false |
filter
| | - |
Returns: Promise‹string›
writeMigrationsCreatePermissions
▸ writeMigrationsCreatePermissions(__namedParameters
: object): Promise‹string | object›
Defined in index.ts:145
Parameters:
▪ __namedParameters: object
Name | Type |
------ | ------ |
dir
| string |
filter
| undefined | function |
role
| string |
set
| undefined | object |
excludeColumns
| object |
Returns: Promise‹string | object›
writeMigrationsTrackTable
▸ writeMigrationsTrackTable(__namedParameters
: object): Promise‹any›
Defined in index.ts:172
Parameters:
▪ __namedParameters: object
Name | Type |
------ | ------ |
dir
| string |
filter
| undefined | function |
Returns: Promise‹any›
Static
create
▸ create(__namedParameters
: object): Promise‹HasuraUtils›
Defined in index.ts:92
Parameters:
▪Default value
__namedParameters: object= {} as any
Name | Type | Default |
------ | ------ | ------ |
adminSecret
| string | process.env["X-HASURA-ADMIN-SECRET"] || "" |
database
| string | - |
includeSchemas
| string[] | ["public"] |
multipleObjectNameFunction
| function | getMultipleObjectName |
password
| string | - |
singleObjectNameFunction
| function | getSingleObjectName |
tableNameFunction
| function | getTableName |
url
| string | process.env["GRAPHQL-URL"] || "http://localhost:8080/v1/query" |
user
| string | - |
Returns: Promise‹HasuraUtils›
Interfaces
hasura-utils › HasuraTableName
Interface: HasuraTableName
Hierarchy
- HasuraTableName
Properties
name
• name: string
Defined in index.ts:40
schema
• schema: string
Defined in index.ts:39
Interface: MetaData
Hierarchy
- MetaData
Properties
tables
• tables: Array‹object›
Defined in index.ts:45
version
• version: number
Defined in index.ts:44
Interface: Options
Hierarchy
- Options
Properties
Optional
adminSecret
• adminSecret? : undefined | string
Defined in index.ts:54
database
• database: string
Defined in index.ts:55
Optional
includeSchemas
• includeSchemas? : string[]
Defined in index.ts:58
Optional
multipleObjectNameFunction
• multipleObjectNameFunction? : NameFunction
Defined in index.ts:60
password
• password: string
Defined in index.ts:57
Optional
singleObjectNameFunction
• singleObjectNameFunction? : NameFunction
Defined in index.ts:59
Optional
tableNameFunction
• tableNameFunction? : NameFunction
Defined in index.ts:61
Optional
url
• url? : undefined | string
Defined in index.ts:53
user
• user: string
Defined in index.ts:56