Properly return schema information about views and PK mutability from the Super Connector

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8786
GitOrigin-RevId: b7cd0dd5736a408a269819ea76dfbe53455060ee
This commit is contained in:
Daniel Chambers 2023-04-19 03:22:47 +10:00 committed by hasura-bot
parent 3332189756
commit 91c88b2109
3 changed files with 16 additions and 17 deletions

View File

@ -38,9 +38,8 @@ function determineScalarType(datatype: Datatype): ScalarTypeKey {
} }
} }
function getColumns(ast: any[], primaryKeys: string[]) : ColumnInfo[] { function getColumns(ast: any[]) : ColumnInfo[] {
return ast.map(column => { return ast.map(column => {
const isPrimaryKey = primaryKeys.includes(column.name);
const isAutoIncrement = column.definition.some((def: any) => def.type === "constraint" && def.autoIncrement === true); const isAutoIncrement = column.definition.some((def: any) => def.type === "constraint" && def.autoIncrement === true);
return { return {
@ -48,7 +47,7 @@ function getColumns(ast: any[], primaryKeys: string[]) : ColumnInfo[] {
type: determineScalarType(column.datatype), type: determineScalarType(column.datatype),
nullable: nullableCast(column.definition), nullable: nullableCast(column.definition),
insertable: MUTATIONS, insertable: MUTATIONS,
updatable: MUTATIONS && !isPrimaryKey, updatable: MUTATIONS,
...(isAutoIncrement ? { value_generated: { type: "auto_increment" } } : {}) ...(isAutoIncrement ? { value_generated: { type: "auto_increment" } } : {})
}; };
}) })
@ -78,7 +77,7 @@ const formatTableInfo = (config: Config) => (info: TableInfoInternal): TableInfo
...primaryKey, ...primaryKey,
...foreignKey, ...foreignKey,
description: info.sql, description: info.sql,
columns: getColumns(columnsDdl, primaryKeys), columns: getColumns(columnsDdl),
insertable: MUTATIONS, insertable: MUTATIONS,
updatable: MUTATIONS, updatable: MUTATIONS,
deletable: MUTATIONS, deletable: MUTATIONS,

View File

@ -173,7 +173,7 @@ schemaInspectionTests = describe "Schema and Source Inspection" $ do
nullable: false nullable: false
type: *_stIntegerType type: *_stIntegerType
insertable: *supportsInserts insertable: *supportsInserts
updatable: false updatable: *supportsUpdates
value_generated: value_generated:
type: auto_increment type: auto_increment
- name: *artistId - name: *artistId

View File

@ -11,7 +11,7 @@
"nullable": false, "nullable": false,
"description": "Genre primary key identifier", "description": "Genre primary key identifier",
"insertable": true, "insertable": true,
"updatable": false, "updatable": true,
"value_generated": { "type": "auto_increment" } "value_generated": { "type": "auto_increment" }
}, },
{ {
@ -39,7 +39,7 @@
"nullable": false, "nullable": false,
"description": "Media Type primary key identifier", "description": "Media Type primary key identifier",
"insertable": true, "insertable": true,
"updatable": false, "updatable": true,
"value_generated": { "type": "auto_increment" } "value_generated": { "type": "auto_increment" }
}, },
{ {
@ -67,7 +67,7 @@
"nullable": false, "nullable": false,
"description": "Artist primary key identifier", "description": "Artist primary key identifier",
"insertable": true, "insertable": true,
"updatable": false, "updatable": true,
"value_generated": { "type": "auto_increment" } "value_generated": { "type": "auto_increment" }
}, },
{ {
@ -103,7 +103,7 @@
"nullable": false, "nullable": false,
"description": "Album primary key identifier", "description": "Album primary key identifier",
"insertable": true, "insertable": true,
"updatable": false, "updatable": true,
"value_generated": { "type": "auto_increment" } "value_generated": { "type": "auto_increment" }
}, },
{ {
@ -159,7 +159,7 @@
"nullable": false, "nullable": false,
"description": "The ID of the track", "description": "The ID of the track",
"insertable": true, "insertable": true,
"updatable": false, "updatable": true,
"value_generated": { "type": "auto_increment" } "value_generated": { "type": "auto_increment" }
}, },
{ {
@ -251,7 +251,7 @@
"nullable": false, "nullable": false,
"description": "Employee primary key identifier", "description": "Employee primary key identifier",
"insertable": true, "insertable": true,
"updatable": false, "updatable": true,
"value_generated": { "type": "auto_increment" } "value_generated": { "type": "auto_increment" }
}, },
{ {
@ -391,7 +391,7 @@
"nullable": false, "nullable": false,
"description": "Customer primary key identifier", "description": "Customer primary key identifier",
"insertable": true, "insertable": true,
"updatable": false, "updatable": true,
"value_generated": { "type": "auto_increment" } "value_generated": { "type": "auto_increment" }
}, },
{ {
@ -515,7 +515,7 @@
"nullable": false, "nullable": false,
"description": "Invoice primary key identifier", "description": "Invoice primary key identifier",
"insertable": true, "insertable": true,
"updatable": false, "updatable": true,
"value_generated": { "type": "auto_increment" } "value_generated": { "type": "auto_increment" }
}, },
{ {
@ -613,7 +613,7 @@
"nullable": false, "nullable": false,
"description": "Invoice Line primary key identifier", "description": "Invoice Line primary key identifier",
"insertable": true, "insertable": true,
"updatable": false, "updatable": true,
"value_generated": { "type": "auto_increment" } "value_generated": { "type": "auto_increment" }
}, },
{ {
@ -665,7 +665,7 @@
"nullable": false, "nullable": false,
"description": "Playlist primary key identifier", "description": "Playlist primary key identifier",
"insertable": true, "insertable": true,
"updatable": false, "updatable": true,
"value_generated": { "type": "auto_increment" } "value_generated": { "type": "auto_increment" }
}, },
{ {
@ -707,7 +707,7 @@
"nullable": false, "nullable": false,
"description": "The ID of the playlist", "description": "The ID of the playlist",
"insertable": true, "insertable": true,
"updatable": false "updatable": true
}, },
{ {
"name": "TrackId", "name": "TrackId",
@ -715,7 +715,7 @@
"nullable": false, "nullable": false,
"description": "The ID of the track", "description": "The ID of the track",
"insertable": true, "insertable": true,
"updatable": false "updatable": true
} }
], ],
"insertable": true, "insertable": true,