mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-10-06 14:58:09 +03:00
This commit is contained in:
parent
33b8c3dcc7
commit
39bc3acffd
@ -226,10 +226,7 @@ fromScalarTyDef (G.ScalarTypeDefinition descM n _) loc =
|
||||
"Float" -> return PGFloat
|
||||
"String" -> return PGText
|
||||
"Boolean" -> return PGBoolean
|
||||
-- TODO: is this correct?
|
||||
"ID" -> return $ PGUnknown "ID" --PGText
|
||||
-- FIXME: is this correct for hasura scalar also?
|
||||
_ -> return $ PGUnknown $ G.unName n --throwError $ "unexpected type: " <> G.unName n
|
||||
_ -> return $ txtToPgColTy $ G.unName n
|
||||
|
||||
data TypeInfo
|
||||
= TIScalar !ScalarTyInfo
|
||||
|
@ -293,56 +293,61 @@ instance ToJSON PGColType where
|
||||
instance ToSQL PGColType where
|
||||
toSQL pct = fromString $ show pct
|
||||
|
||||
|
||||
txtToPgColTy :: Text -> PGColType
|
||||
txtToPgColTy t = case t of
|
||||
"serial" -> PGSerial
|
||||
"bigserial" -> PGBigSerial
|
||||
|
||||
"smallint" -> PGSmallInt
|
||||
"int2" -> PGSmallInt
|
||||
|
||||
"integer" -> PGInteger
|
||||
"int4" -> PGInteger
|
||||
|
||||
"bigint" -> PGBigInt
|
||||
"int8" -> PGBigInt
|
||||
|
||||
"real" -> PGFloat
|
||||
"float4" -> PGFloat
|
||||
|
||||
"double precision" -> PGDouble
|
||||
"float8" -> PGDouble
|
||||
|
||||
"numeric" -> PGNumeric
|
||||
"decimal" -> PGNumeric
|
||||
|
||||
"boolean" -> PGBoolean
|
||||
"bool" -> PGBoolean
|
||||
|
||||
"character" -> PGChar
|
||||
|
||||
"varchar" -> PGVarchar
|
||||
"character varying" -> PGVarchar
|
||||
|
||||
"text" -> PGText
|
||||
"citext" -> PGText
|
||||
|
||||
"date" -> PGDate
|
||||
|
||||
"timestamptz" -> PGTimeStampTZ
|
||||
"timestamp with time zone" -> PGTimeStampTZ
|
||||
|
||||
"timetz" -> PGTimeTZ
|
||||
"time with time zone" -> PGTimeTZ
|
||||
|
||||
"json" -> PGJSON
|
||||
"jsonb" -> PGJSONB
|
||||
|
||||
"geometry" -> PGGeometry
|
||||
"geography" -> PGGeography
|
||||
_ -> PGUnknown t
|
||||
|
||||
|
||||
instance FromJSON PGColType where
|
||||
parseJSON (String "serial") = return PGSerial
|
||||
parseJSON (String "bigserial") = return PGBigSerial
|
||||
parseJSON (String t) = return $ txtToPgColTy t
|
||||
parseJSON _ = fail "Expecting a string for PGColType"
|
||||
|
||||
parseJSON (String "smallint") = return PGSmallInt
|
||||
parseJSON (String "int2") = return PGSmallInt
|
||||
|
||||
parseJSON (String "integer") = return PGInteger
|
||||
parseJSON (String "int4") = return PGInteger
|
||||
|
||||
parseJSON (String "bigint") = return PGBigInt
|
||||
parseJSON (String "int8") = return PGBigInt
|
||||
|
||||
parseJSON (String "real") = return PGFloat
|
||||
parseJSON (String "float4") = return PGFloat
|
||||
|
||||
parseJSON (String "double precision") = return PGDouble
|
||||
parseJSON (String "float8") = return PGDouble
|
||||
|
||||
parseJSON (String "numeric") = return PGNumeric
|
||||
parseJSON (String "decimal") = return PGNumeric
|
||||
|
||||
parseJSON (String "boolean") = return PGBoolean
|
||||
parseJSON (String "bool") = return PGBoolean
|
||||
|
||||
parseJSON (String "character") = return PGChar
|
||||
|
||||
parseJSON (String "varchar") = return PGVarchar
|
||||
parseJSON (String "character varying") = return PGVarchar
|
||||
|
||||
parseJSON (String "text") = return PGText
|
||||
parseJSON (String "citext") = return PGText
|
||||
|
||||
parseJSON (String "date") = return PGDate
|
||||
|
||||
parseJSON (String "timestamptz") = return PGTimeStampTZ
|
||||
parseJSON (String "timestamp with time zone") = return PGTimeStampTZ
|
||||
|
||||
parseJSON (String "timetz") = return PGTimeTZ
|
||||
parseJSON (String "time with time zone") = return PGTimeTZ
|
||||
|
||||
parseJSON (String "json") = return PGJSON
|
||||
parseJSON (String "jsonb") = return PGJSONB
|
||||
|
||||
parseJSON (String "geometry") = return PGGeometry
|
||||
parseJSON (String "geography") = return PGGeography
|
||||
|
||||
parseJSON (String t) = return $ PGUnknown t
|
||||
parseJSON _ =
|
||||
fail "Expecting a string for PGColType"
|
||||
|
||||
pgTypeOid :: PGColType -> PQ.Oid
|
||||
pgTypeOid PGSmallInt = PTI.int2
|
||||
|
@ -100,6 +100,17 @@ class UserGraphQL(RequestHandler):
|
||||
res = user_schema.execute(req.json['query'])
|
||||
return mkJSONResp(res)
|
||||
|
||||
class timestamptz(graphene.types.Scalar):
|
||||
@staticmethod
|
||||
def serialize(t):
|
||||
return "2018-12-20"
|
||||
@staticmethod
|
||||
def parse_literal(s):
|
||||
return "2018-12-20"
|
||||
@staticmethod
|
||||
def parse_value(s):
|
||||
return "2018-12-20"
|
||||
|
||||
class Country(graphene.ObjectType):
|
||||
name = graphene.String()
|
||||
|
||||
@ -130,11 +141,14 @@ class CountryGraphQL(RequestHandler):
|
||||
class person(graphene.ObjectType):
|
||||
id = graphene.Int(required=True)
|
||||
name = graphene.String()
|
||||
created = graphene.Field(timestamptz)
|
||||
|
||||
def resolve_id(self, info):
|
||||
return 42
|
||||
def resolve_name(self, info):
|
||||
return 'Arthur Dent'
|
||||
def resolve_created(self, info):
|
||||
return '2018-12-20'
|
||||
|
||||
class PersonQuery(graphene.ObjectType):
|
||||
person_ = graphene.Field(person)
|
||||
|
@ -5,7 +5,8 @@ args:
|
||||
sql: |
|
||||
CREATE TABLE person (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name TEXT
|
||||
name TEXT,
|
||||
created TIMESTAMPTZ
|
||||
);
|
||||
|
||||
- type: track_table
|
||||
|
@ -149,10 +149,10 @@ class TestAddRemoteSchemaTbls:
|
||||
assert st_code == 500, resp
|
||||
assert resp['code'] == 'postgres-error'
|
||||
|
||||
def test_add_schema_same_type(self, hge_ctx):
|
||||
def test_add_schema_same_type_containing_same_scalar(self, hge_ctx):
|
||||
"""
|
||||
test types get merged when remote schema has type with same name and
|
||||
same structure
|
||||
same structure + a same custom scalar
|
||||
"""
|
||||
st_code, resp = hge_ctx.v1q_f(self.dir + '/person_table.yaml')
|
||||
assert st_code == 200, resp
|
||||
|
Loading…
Reference in New Issue
Block a user