mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
This commit is contained in:
parent
66beb02f7b
commit
319606b5ff
@ -220,6 +220,8 @@ type AnnBoolExpUnresolved = AnnBoolExp UnresolvedVal
|
||||
|
||||
-- template haskell related
|
||||
$(makePrisms ''ResolveField)
|
||||
$(makeLenses ''ComputedField)
|
||||
$(makePrisms ''ComputedFieldType)
|
||||
|
||||
data InputFunctionArgument
|
||||
= IFAKnown !FunctionArgName !UnresolvedVal -- ^ Known value
|
||||
|
@ -833,10 +833,11 @@ mkGCtx tyAgg (RootFields queryFields mutationFields) insCtxMap =
|
||||
then Set.union (Set.fromList [PGColumnScalar PGGeometry, PGColumnScalar PGGeography]) colTys
|
||||
else colTys
|
||||
|
||||
additionalScalars =
|
||||
Set.fromList
|
||||
additionalScalars = Set.fromList $
|
||||
-- raster comparison expression needs geometry input
|
||||
(guard anyRasterTypes *> pure PGGeometry)
|
||||
-- scalar computed field return types
|
||||
<> mapMaybe (^? _RFComputedField.cfType._CFTScalar) (Map.elems fldInfos)
|
||||
|
||||
allScalarTypes = (allComparableTypes ^.. folded._PGColumnScalar)
|
||||
<> additionalScalars <> scalars
|
||||
|
@ -8,14 +8,14 @@ import Data.Aeson (eitherDecodeStrict)
|
||||
import Test.Hspec
|
||||
import Test.QuickCheck
|
||||
|
||||
import Hasura.RQL.DDL.Metadata.Generator (genReplaceMetadata)
|
||||
import Hasura.RQL.DDL.Metadata.Types (ReplaceMetadata,
|
||||
replaceMetadataToOrdJSON)
|
||||
import Hasura.EncJSON
|
||||
import Hasura.RQL.DDL.Metadata.Generator (genReplaceMetadata)
|
||||
import Hasura.RQL.DDL.Metadata.Types (ReplaceMetadata, replaceMetadataToOrdJSON)
|
||||
|
||||
spec :: Spec
|
||||
spec = describe "replaceMetadataToOrdJSON" $ do
|
||||
it "produces JSON that can be parsed by the ToJSON instance for ReplaceMetadata" $
|
||||
withMaxSuccess 50 $
|
||||
forAll (resize 3 genReplaceMetadata) $ \metadata ->
|
||||
let encodedString = encJToBS $ AO.toEncJSON $ replaceMetadataToOrdJSON metadata
|
||||
in case eitherDecodeStrict @ReplaceMetadata encodedString of
|
||||
|
@ -0,0 +1,28 @@
|
||||
description: Fetch data from float_test table with scalar computed field of type float8
|
||||
url: /v1/graphql
|
||||
status: 200
|
||||
response:
|
||||
data:
|
||||
float_test:
|
||||
- id: 1
|
||||
first_int: 1
|
||||
second_int: 2
|
||||
sum_float: '3'
|
||||
- id: 2
|
||||
first_int: 3
|
||||
second_int: 2
|
||||
sum_float: '5'
|
||||
- id: 3
|
||||
first_int: 4
|
||||
second_int: 6
|
||||
sum_float: '10'
|
||||
query:
|
||||
query: |
|
||||
query {
|
||||
float_test{
|
||||
id
|
||||
first_int
|
||||
second_int
|
||||
sum_float
|
||||
}
|
||||
}
|
@ -79,6 +79,19 @@ args:
|
||||
)::integer
|
||||
$$ LANGUAGE sql STABLE;
|
||||
|
||||
CREATE TABLE float_test(
|
||||
id serial primary key,
|
||||
first_int integer not null,
|
||||
second_int integer not null
|
||||
);
|
||||
|
||||
INSERT INTO float_test (first_int, second_int)
|
||||
VALUES (1, 2), (3, 2), (4, 6);
|
||||
|
||||
CREATE FUNCTION get_sum(table_row float_test) returns float8 AS $$
|
||||
SELECT table_row.first_int::float8 + table_row.second_int::float8
|
||||
$$ LANGUAGE SQL STABLE;
|
||||
|
||||
- type: track_table
|
||||
args:
|
||||
name: author
|
||||
@ -134,3 +147,15 @@ args:
|
||||
definition:
|
||||
function: locations_distance
|
||||
table_argument: locations_row
|
||||
|
||||
- type: track_table
|
||||
args:
|
||||
name: float_test
|
||||
schema: public
|
||||
|
||||
- type: add_computed_field
|
||||
args:
|
||||
table: float_test
|
||||
name: sum_float
|
||||
definition:
|
||||
function: get_sum
|
||||
|
@ -9,4 +9,6 @@ args:
|
||||
DROP TABLE author;
|
||||
DROP FUNCTION locations_distance(json, locations);
|
||||
DROP TABLE locations;
|
||||
DROP FUNCTION get_sum(float_test);
|
||||
DROP TABLE float_test;
|
||||
cascade: true
|
||||
|
@ -570,6 +570,9 @@ class TestGraphQLQueryComputedFields(DefaultTestSelectQueries):
|
||||
def test_locations(self, hge_ctx, transport):
|
||||
check_query_f(hge_ctx, self.dir() + '/locations.yaml', transport)
|
||||
|
||||
def test_float_test(self, hge_ctx, transport):
|
||||
check_query_f(hge_ctx, self.dir() + '/float_test.yaml', transport)
|
||||
|
||||
@pytest.mark.parametrize('transport', ['http', 'websocket'])
|
||||
class TestGraphQLQueryCaching(DefaultTestSelectQueries):
|
||||
@classmethod
|
||||
|
Loading…
Reference in New Issue
Block a user