这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -46,9 +48,9 @@ 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)


## `v1.2.0-beta.4`

### add query support in actions
Expand Down
27 changes: 17 additions & 10 deletions server/src-lib/Hasura/RQL/DDL/CustomTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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) $
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions server/tests-py/queries/actions/custom-types/setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ args:
location geography
);

- type: track_table
args:
name: user
schema: public

- type: set_custom_types
args:
objects:
Expand Down
7 changes: 5 additions & 2 deletions server/tests-py/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,18 @@ 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')

@pytest.mark.usefixtures('per_class_tests_db_state')
class TestActionsMetadata:

Expand Down