From 955f88d5ecc31783a0245fff0b5d5380c6a9d876 Mon Sep 17 00:00:00 2001 From: rakeshkky <12475069+rakeshkky@users.noreply.github.com> Date: Fri, 17 Apr 2020 17:27:20 +0530 Subject: [PATCH 1/3] fix creating relationships for custom object types with fields reusing Postgres scalars, close #4447 --- CHANGELOG.md | 6 ++- server/src-lib/Hasura/RQL/DDL/CustomTypes.hs | 27 ++++++---- .../custom-types/list_type_relationship.yaml | 52 +++++++++++++++++++ .../actions/custom-types/reuse_pgscalars.yaml | 6 +++ .../queries/actions/custom-types/setup.yaml | 5 ++ server/tests-py/test_actions.py | 7 ++- 6 files changed, 90 insertions(+), 13 deletions(-) create mode 100644 server/tests-py/queries/actions/custom-types/list_type_relationship.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 3123472b2ce44..41f43c2a79006 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,13 @@ ## Next release +## `v1.2.0-beta.5` + +- server: fix creating relationships for custom object types with fields reusing Postgres scalars (close #4447) + ## `v1.2.0-beta.4` -### add query support in actions +### add query support in actions (close #4032) (#4309) diff --git a/server/src-lib/Hasura/RQL/DDL/CustomTypes.hs b/server/src-lib/Hasura/RQL/DDL/CustomTypes.hs index eca1f928b3aa1..fe12adfdef94f 100644 --- a/server/src-lib/Hasura/RQL/DDL/CustomTypes.hs +++ b/server/src-lib/Hasura/RQL/DDL/CustomTypes.hs @@ -144,8 +144,7 @@ validateCustomTypeDefinitions tableCache customTypes allPGScalars = execWriterT unless (null duplicateFieldNames) $ dispute $ pure $ ObjectDuplicateFields objectTypeName duplicateFieldNames - scalarFields <- fmap (Map.fromList . catMaybes) $ - for fields $ \objectField -> do + scalarFields <- fmap Map.fromList $ for fields $ \objectField -> do let fieldType = _ofdType objectField fieldBaseType = G.getBaseType $ unGraphQLType fieldType fieldName = _ofdName objectField @@ -171,10 +170,7 @@ validateCustomTypeDefinitions tableCache customTypes allPGScalars = execWriterT dispute $ pure $ ObjectFieldTypeDoesNotExist objectTypeName fieldName fieldBaseType - -- collect all non list scalar types of this object - if (not (isListType fieldType) && Set.member fieldBaseType scalarTypes) - then pure $ Just (fieldName, fieldBaseType) - else pure Nothing + pure (fieldName, fieldType) for_ relationships $ \relationshipField -> do let relationshipName = _trName relationshipField @@ -189,10 +185,14 @@ validateCustomTypeDefinitions tableCache customTypes allPGScalars = execWriterT -- check that the column mapping is sane forM_ (Map.toList fieldMapping) $ \(fieldName, columnName) -> do - -- the field should be a non-list type scalar - when (Map.lookup fieldName scalarFields == Nothing) $ - dispute $ pure $ ObjectRelationshipFieldDoesNotExist - objectTypeName relationshipName fieldName + case Map.lookup fieldName scalarFields of + Nothing -> dispute $ pure $ ObjectRelationshipFieldDoesNotExist + objectTypeName relationshipName fieldName + Just fieldType -> + -- the field should be a non-list type scalar + when (isListType fieldType) $ + dispute $ pure $ ObjectRelationshipFieldListType + objectTypeName relationshipName fieldName -- the column should be a column of the table when (getPGColumnInfoM remoteTableInfo (fromPGCol columnName) == Nothing) $ @@ -227,6 +227,9 @@ data CustomTypeValidationError | ObjectRelationshipFieldDoesNotExist !ObjectTypeName !RelationshipName !ObjectFieldName -- ^ The field specified in the relationship mapping does not exist + | ObjectRelationshipFieldListType + !ObjectTypeName !RelationshipName !ObjectFieldName + -- ^ The field specified in the relationship mapping is a list type | ObjectRelationshipColumnDoesNotExist !ObjectTypeName !RelationshipName !QualifiedTable !PGCol -- ^ The column specified in the relationship mapping does not exist @@ -271,6 +274,10 @@ showCustomTypeValidationError = \case "the field " <> fieldName <<> " for relationship " <> relName <<> " in object type " <> objType <<> " does not exist" + ObjectRelationshipFieldListType objType relName fieldName -> + "the type of the field " <> fieldName <<> " for relationship " <> relName + <<> " in object type " <> objType <<> " is a list type" + ObjectRelationshipColumnDoesNotExist objType relName remoteTable column -> "the column " <> column <<> " of remote table " <> remoteTable <<> " for relationship " <> relName <<> " of object type " <> objType diff --git a/server/tests-py/queries/actions/custom-types/list_type_relationship.yaml b/server/tests-py/queries/actions/custom-types/list_type_relationship.yaml new file mode 100644 index 0000000000000..f081c00036496 --- /dev/null +++ b/server/tests-py/queries/actions/custom-types/list_type_relationship.yaml @@ -0,0 +1,52 @@ +description: Set custom types; relationships for objects with list type fields +url: /v1/query +status: 400 +response: + internal: + - definition: + input_objects: + objects: + - name: User + relationships: + - remote_table: + schema: public + name: user + name: Names + type: array + field_mapping: + names: name + description: + fields: + - arguments: + name: user_id + type: uuid! + description: + - arguments: + name: names + type: '[String!]' + description: + scalars: + enums: + reason: validation for the given custom types failed because the type of the field + "names" for relationship "Names" in object type "User" is a list type + type: custom_types + path: $.args + error: validation for the given custom types failed because the type of the field + "names" for relationship "Names" in object type "User" is a list type + code: constraint-violation +query: + type: set_custom_types + args: + objects: + - name: User + fields: + - name: user_id + type: uuid! + - name: names + type: '[String!]' + relationships: + - name: Names + type: array + remote_table: user + field_mapping: + names: name diff --git a/server/tests-py/queries/actions/custom-types/reuse_pgscalars.yaml b/server/tests-py/queries/actions/custom-types/reuse_pgscalars.yaml index 892da3a37f569..0c60992851728 100644 --- a/server/tests-py/queries/actions/custom-types/reuse_pgscalars.yaml +++ b/server/tests-py/queries/actions/custom-types/reuse_pgscalars.yaml @@ -11,6 +11,12 @@ query: type: uuid! - name: location type: geography + relationships: + - name: user + type: object + remote_table: user + field_mapping: + user_id: id input_objects: - name: UserInput fields: diff --git a/server/tests-py/queries/actions/custom-types/setup.yaml b/server/tests-py/queries/actions/custom-types/setup.yaml index dfdecff8bcc0c..aa7af91da7ce0 100644 --- a/server/tests-py/queries/actions/custom-types/setup.yaml +++ b/server/tests-py/queries/actions/custom-types/setup.yaml @@ -18,6 +18,11 @@ args: location geography ); +- type: track_table + args: + name: user + schema: public + - type: set_custom_types args: objects: diff --git a/server/tests-py/test_actions.py b/server/tests-py/test_actions.py index a9bc30235d7cc..ca0ef8b7f3276 100644 --- a/server/tests-py/test_actions.py +++ b/server/tests-py/test_actions.py @@ -359,11 +359,14 @@ class TestSetCustomTypes: def dir(cls): return 'queries/actions/custom-types' - def test_resuse_pgscalars(self, hge_ctx): + def test_reuse_pgscalars(self, hge_ctx): check_query_f(hge_ctx, self.dir() + '/reuse_pgscalars.yaml') - def test_resuse_unknown_pgscalar(self, hge_ctx): + def test_reuse_unknown_pgscalar(self, hge_ctx): check_query_f(hge_ctx, self.dir() + '/reuse_unknown_pgscalar.yaml') def test_create_action_pg_scalar(self, hge_ctx): check_query_f(hge_ctx, self.dir() + '/create_action_pg_scalar.yaml') + + def test_list_type_relationship(self, hge_ctx): + check_query_f(hge_ctx, self.dir() + '/list_type_relationship.yaml') From 874ea8d939ebc1445ce6b3c50c10ef1f51e6c9a4 Mon Sep 17 00:00:00 2001 From: Tirumarai Selvan Date: Wed, 22 Apr 2020 10:19:30 +0530 Subject: [PATCH 2/3] fix changelog entry --- CHANGELOG.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a69e16f280af0..813c58ad33b95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - server: support special characters in JSON path query argument with bracket `[]` notation, e.g `obj['Hello World!']` (#3890) (#4482) - server: add graphql-engine support for timestamps without timezones (fix #1217) - server: support inserting unquoted bigint, and throw an error if value overflows the bounds of the integer type (fix #576) (fix #4368) +- server: fix creating relationships for custom object types with fields reusing Postgres scalars (close #4447) - console: change react ace editor theme to eclipse (close #4437) - console: fix columns reordering for relationship tables in data browser (#4483) - console: format row count in data browser for readablity (#4433) @@ -18,9 +19,6 @@ - console: prevent trailing spaces while creating new role (close #3871) (#4497) - docs: add API docs for using environment variables as webhook urls in event triggers -## `v1.2.0-beta.5` - -- server: fix creating relationships for custom object types with fields reusing Postgres scalars (close #4447) ## `v1.2.0-beta.4` From add43318489f1c4f2d1d5a655c15f0d2e6b382bd Mon Sep 17 00:00:00 2001 From: Tirumarai Selvan Date: Fri, 24 Apr 2020 10:17:52 +0530 Subject: [PATCH 3/3] rearrange entries --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eaada83940ff3..896cfdca5e13a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ For example, see [here](https://hasura.io/docs/1.0/graphql/manual/api-reference/ - server: support special characters in JSON path query argument with bracket `[]` notation, e.g `obj['Hello World!']` (#3890) (#4482) - server: add graphql-engine support for timestamps without timezones (fix #1217) - server: support inserting unquoted bigint, and throw an error if value overflows the bounds of the integer type (fix #576) (fix #4368) +- server: fix creating relationships for custom object types with fields reusing Postgres scalars (close #4447) (#4455) +- server: fix recreating action's permissions (close #4377) - console: while deriving action, map selection set of parent mutation to action's returning type (#4530) - console: change react ace editor theme to eclipse (close #4437) - console: fix columns reordering for relationship tables in data browser (#4483) @@ -46,9 +48,7 @@ For example, see [here](https://hasura.io/docs/1.0/graphql/manual/api-reference/ - console: fix row delete for relationships in data browser (#4433) - console: prevent trailing spaces while creating new role (close #3871) (#4497) - docs: add API docs for using environment variables as webhook urls in event triggers -- server: fix recreating action's permissions (close #4377) - docs: add reference docs for CLI (clsoe #4327) (#4408) -- server: fix creating relationships for custom object types with fields reusing Postgres scalars (close #4447) (#4455) ## `v1.2.0-beta.4`