这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2971c26
add _st_* operators to geography_comparison_exp
shahidhk Mar 12, 2019
ec3e275
add geography boolexp to rql
shahidhk Mar 12, 2019
d31d448
refactor to reduce loc
shahidhk Mar 12, 2019
a259e27
add geography support to console permission builder
shahidhk Mar 12, 2019
e8b08b5
add st_d_within_geography_input type and update desc
shahidhk Mar 12, 2019
5cc2a44
rename the default stdwithin var to reflect geometry
shahidhk Mar 12, 2019
ae133ab
add _st_d_within_geography support to the query
shahidhk Mar 12, 2019
39d512a
add only st_d_within and st_intersects to geography types
shahidhk Mar 13, 2019
551dcdf
fix a typo
shahidhk Mar 13, 2019
5e507dd
add tests for spatial operators on geography column
shahidhk Mar 13, 2019
49504b9
fix some indentation
shahidhk Mar 13, 2019
0ed27ea
update docs
shahidhk Mar 13, 2019
f8280b2
generate correct types in v1/query
shahidhk Mar 13, 2019
1533aef
add permissions operators for geography type
rikinsk Mar 14, 2019
6fc165d
Merge branch 'master' into add-geography-support
shahidhk Mar 18, 2019
0212480
fix review comments
shahidhk Mar 18, 2019
bcdc80b
Merge branch 'add-geography-support' of github.com:shahidhk/graphql-e…
shahidhk Mar 18, 2019
9a3c15d
Merge branch 'master' into add-geography-support
shahidhk Mar 19, 2019
6e863ee
Merge branch 'master' into add-geography-support
shahidhk Mar 19, 2019
9d33ad5
Merge branch 'master' into add-geography-support
shahidhk Mar 19, 2019
2839d4e
wip: add use_spheroid to st_d_within_geography input
shahidhk Mar 19, 2019
6af2ad0
Merge branch 'add-geography-support' of github.com:shahidhk/graphql-e…
shahidhk Mar 19, 2019
d907b27
make use_spheroid optional
shahidhk Mar 19, 2019
7168e1e
Merge branch 'master' into add-geography-support
shahidhk Mar 20, 2019
6f0e810
parse use_speroid and its default value
shahidhk Mar 20, 2019
8fda7ab
Merge branch 'master' into add-geography-support
shahidhk Mar 21, 2019
2b6b8fd
update tests
shahidhk Mar 21, 2019
76f4666
add geometry and geography to reference types
shahidhk Mar 22, 2019
8e6c6e5
Merge branch 'master' into add-geography-support
shahidhk Mar 22, 2019
ce63293
fix non-nullable fields with default value
shahidhk Mar 22, 2019
ad13050
Merge branch 'master' into add-geography-support
shahidhk Mar 25, 2019
fcc431b
add tests for v1/query select with where on geography column
shahidhk Mar 25, 2019
21e45d4
Update postgresql-types.rst
rikinsk Mar 25, 2019
9bd5187
add tests where geography ops are used in permissions
shahidhk Mar 25, 2019
33ff74c
Merge branch 'add-geography-support' of github.com:shahidhk/graphql-e…
shahidhk Mar 25, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
genericOperators,
textColumnOperators,
jsonColumnOperators,
topologyColumnOperators,
geometryColumnOperators,
geographyColumnOperators,
PGTypes,
} from './utils';

Expand Down Expand Up @@ -424,7 +425,8 @@ class PermissionBuilder extends React.Component {
_val = Number(val);
} else if (
(PGTypes.json.includes(valueType) ||
PGTypes.postgis.includes(valueType)) &&
PGTypes.geometry.includes(valueType) ||
PGTypes.geography.includes(valueType)) &&
isJsonString(val)
) {
_val = JSON.parse(val);
Expand Down Expand Up @@ -453,7 +455,8 @@ class PermissionBuilder extends React.Component {
input = renderBoolSelect(dispatchInput, value);
} else if (
PGTypes.json.includes(valueType) ||
PGTypes.postgis.includes(valueType)
PGTypes.geometry.includes(valueType) ||
PGTypes.geography.includes(valueType)
) {
input = inputBox();
suggestion = jsonSuggestion();
Expand Down Expand Up @@ -509,8 +512,10 @@ class PermissionBuilder extends React.Component {
operators = textColumnOperators;
} else if (PGTypes.json.includes(valueType)) {
operators = jsonColumnOperators;
} else if (PGTypes.postgis.includes(valueType)) {
operators = topologyColumnOperators;
} else if (PGTypes.geometry.includes(valueType)) {
operators = geometryColumnOperators;
} else if (PGTypes.geography.includes(valueType)) {
operators = geographyColumnOperators;
} else {
operators = genericOperators;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const PGTypes = {
'interval',
],
json: ['json', 'jsonb'],
postgis: ['geometry'],
geometry: ['geometry'],
geography: ['geography'],
};

export const notBoolOperators = ['_not'];
Expand Down Expand Up @@ -55,25 +56,29 @@ export const textOnlyColumnOperators = [

export const jsonColumnOperators = ['_contains', '_contained_in'];

export const topologyColumnOperators = [
export const geometryOnlyColumnOperators = [
'_st_contains',
'_st_crosses',
'_st_equals',
'_st_intersects',
'_st_overlaps',
'_st_touches',
'_st_within',
'_st_d_within',
];

export const geographyColumnOperators = ['_st_d_within', '_st_intersects'];

export const boolOperators = notBoolOperators.concat(andOrBoolOperators);

export const geometryColumnOperators = geographyColumnOperators.concat(
geometryOnlyColumnOperators
);

export const columnOperators = genericSimpleColumnOperators
.concat(genericArrayColumnOperators)
.concat(genericBoolColumnOperators)
.concat(textOnlyColumnOperators)
.concat(jsonColumnOperators)
.concat(topologyColumnOperators);
.concat(geometryColumnOperators);

export const genericOperators = genericSimpleColumnOperators
.concat(genericArrayColumnOperators)
Expand Down Expand Up @@ -104,7 +109,7 @@ export function isBoolTypeColumnOperator(value) {
}

export function isJsonTypeColumnOperator(value) {
return jsonColumnOperators.concat(topologyColumnOperators).includes(value);
return jsonColumnOperators.concat(geometryColumnOperators).includes(value);
}

export function isColumnOperator(value) {
Expand Down
2 changes: 2 additions & 0 deletions docs/graphql/manual/api-reference/pgtypes.csv
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ json,,textual JSON data,JSON_
jsonb,,"binary JSON data, decomposed",JSONB_
line,,infinite line on a plane,Implicit_
lseg,,line segment on a plane, Implicit_
geometry,,PostGIS Geometry type, Geometry_
geography,,PostGIS Geography type, Geography_
macaddr,,MAC (Media Access Control) address, Implicit_
macaddr8,,MAC (Media Access Control) address (EUI-64 format), Implicit_
money,,currency amount,Implicit_
Expand Down
75 changes: 74 additions & 1 deletion docs/graphql/manual/api-reference/postgresql-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ E.g.
}
}

variable:
variables:

.. code-block:: json

Expand All @@ -227,6 +227,79 @@ variable:
}
}

.. _Geometry:

Geometry
--------

GraphQL custom scalar type ``geometry`` is generated for a ``GEOMETRY`` column
on a PostGIS enabled Postgres instance. Value should be given as GeoJSON.

E.g.

.. code-block:: graphql

mutation insertGeometry($point: geometry!) {
insert_test(
objects: [{
geometry_col: $point
}]
) {
affected_rows
returning {
geometry_col
}
}
}

variables:

.. code-block:: json

{
"point": {
"type": "Point",
"coordinates": [0, 0]
}
}


.. _Geography:

Geography
--------

GraphQL custom scalar type ``geography`` is generated for a ``GEOGRAPHY`` column
on a PostGIS enabled Postgres instance. Value should be given as GeoJSON.

E.g.

.. code-block:: graphql

mutation insertGeography($point: geography!) {
insert_test(
objects: [{
geography_col: $point
}]
) {
affected_rows
returning {
geography_col
}
}
}

variables:

.. code-block:: json

{
"point": {
"type": "Point",
"coordinates": [0, 0]
}
}

.. _Implicit:

Implicitly Supported types
Expand Down
6 changes: 4 additions & 2 deletions docs/graphql/manual/queries/query-filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,11 @@ PostGIS topology operators (_st_contains, _st_crosses, etc.)
The ``_st_contains``, ``_st_crosses``, ``_st_equals``, ``_st_intersects``, ``_st_overlaps``, ``_st_touches``,
``_st_within`` and ``_st_d_within`` operators are used to filter based on ``geometry`` like columns.

``_st_d_within`` and ``_st_intersects`` can be used on ``geography`` columns also.

For more details on what these operators do, refer to `PostGIS docs <http://postgis.net/workshops/postgis-intro/spatial_relationships.html>`__.

Use JSON (`GeoJSON <https://tools.ietf.org/html/rfc7946>`__) representation of ``geometry`` values in
Use JSON (`GeoJSON <https://tools.ietf.org/html/rfc7946>`__) representation of ``geometry`` and ``geography`` values in
``variables`` as shown in the following examples:


Expand Down Expand Up @@ -644,7 +646,7 @@ Fetch a list of geometry values which are within the given ``polygon`` value:

Example: _st_d_within
^^^^^^^^^^^^^^^^^^^^^
Fetch a list of geometry values which are 3 units from given ``point`` value:
Fetch a list of ``geometry`` values which are 3 units from given ``point`` value:

.. graphiql::
:view_only:
Expand Down
2 changes: 1 addition & 1 deletion server/src-lib/Hasura/EncJSON.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

module Hasura.EncJSON
( EncJSON
, encJToLBS
, encJFromBuilder
, encJToLBS
, encJFromJValue
, encJFromChar
, encJFromText
Expand Down
80 changes: 61 additions & 19 deletions server/src-lib/Hasura/GraphQL/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,25 @@ mkCompExpTy :: PGColType -> G.NamedType
mkCompExpTy =
G.NamedType . mkCompExpName

-- TODO(shahidhk) this should ideally be st_d_within_geometry
{-
input st_d_within_input {
distance: Float!
from: geometry!
}
-}
stDWithinGeometryInpTy :: G.NamedType
stDWithinGeometryInpTy = G.NamedType "st_d_within_input"

stDWithinInpTy :: G.NamedType
stDWithinInpTy = G.NamedType "st_d_within_input"
{-
input st_d_within_geography_input {
distance: Float!
from: geography!
use_spheroid: Bool!
}
-}
stDWithinGeographyInpTy :: G.NamedType
stDWithinGeographyInpTy = G.NamedType "st_d_within_geography_input"


--- | make compare expression input type
Expand All @@ -197,7 +207,10 @@ mkCompExpInp colTy =
, map (mk $ G.toLT colScalarTy) listOps
, bool [] (map (mk $ mkScalarTy PGText) stringOps) isStringTy
, bool [] (map jsonbOpToInpVal jsonbOps) isJsonbTy
, bool [] (stDWithinOpInpVal : map geomOpToInpVal geomOps) isGeometryTy
, bool [] (stDWithinGeoOpInpVal stDWithinGeometryInpTy :
map geoOpToInpVal (geoOps ++ geomOps)) isGeometryType
, bool [] (stDWithinGeoOpInpVal stDWithinGeographyInpTy :
map geoOpToInpVal geoOps) isGeographyType
, [InpValInfo Nothing "_is_null" Nothing $ G.TypeNamed (G.Nullability True) $ G.NamedType "Boolean"]
]) HasuraType
where
Expand Down Expand Up @@ -252,18 +265,28 @@ mkCompExpInp colTy =
)
]

-- Geometry related ops
stDWithinOpInpVal =
InpValInfo (Just stDWithinDesc) "_st_d_within" Nothing $ G.toGT stDWithinInpTy
stDWithinDesc =
"is the column within a distance from a geometry value"
stDWithinGeoOpInpVal ty =
InpValInfo (Just stDWithinGeoDesc) "_st_d_within" Nothing $ G.toGT ty
stDWithinGeoDesc =
"is the column within a distance from a " <> colTyDesc <> " value"

isGeometryTy = case colTy of
-- Geometry related ops
isGeometryType = case colTy of
PGGeometry -> True
_ -> False

geomOpToInpVal (op, desc) =
InpValInfo (Just desc) op Nothing $ G.toGT $ mkScalarTy PGGeometry
-- Geography related ops
isGeographyType = case colTy of
PGGeography -> True
_ -> False

geoOpToInpVal (op, desc) =
InpValInfo (Just desc) op Nothing $ G.toGT $ mkScalarTy colTy

colTyDesc = G.Description $ T.pack $ show colTy

-- operators applicable only to geometry types
geomOps :: [(G.Name, G.Description)]
geomOps =
[
( "_st_contains"
Expand All @@ -275,9 +298,6 @@ mkCompExpInp colTy =
, ( "_st_equals"
, "is the column equal to given geometry value. Directionality is ignored"
)
, ( "_st_intersects"
, "does the column spatially intersect the given geometry value"
)
, ( "_st_overlaps"
, "does the column 'spatially overlap' (intersect but not completely contain) the given geometry value"
)
Expand All @@ -289,6 +309,14 @@ mkCompExpInp colTy =
)
]

-- operators applicable to geometry and geography types
geoOps =
[
( "_st_intersects"
, "does the column spatially intersect the given " <> colTyDesc <> " value"
)
]

ordByTy :: G.NamedType
ordByTy = G.NamedType "order_by"

Expand Down Expand Up @@ -338,7 +366,8 @@ mkGCtx tyAgg (RootFlds flds) insCtxMap =
, TIObj <$> mutRootM
, TIObj <$> subRootM
, TIEnum <$> ordByEnumTyM
, TIInpObj <$> stDWithinInpM
, TIInpObj <$> stDWithinGeometryInpM
, TIInpObj <$> stDWithinGeographyInpM
] <>
scalarTys <> compTys <> defaultTypes
-- for now subscription root is query root
Expand Down Expand Up @@ -367,11 +396,24 @@ mkGCtx tyAgg (RootFlds flds) insCtxMap =
$ G.toGT $ G.toNT $ G.NamedType "String"
]

stDWithinInpM = bool Nothing (Just stDWithinInp) (PGGeometry `elem` colTys)
stDWithinInp =
mkHsraInpTyInfo Nothing stDWithinInpTy $ fromInpValL
-- _st_d_within has to stay with geometry type
stDWithinGeometryInpM =
bool Nothing (Just $ stDWithinGeomInp) (PGGeometry `elem` colTys)
-- _st_d_within_geography is created for geography type
stDWithinGeographyInpM =
bool Nothing (Just $ stDWithinGeogInp) (PGGeography `elem` colTys)

stDWithinGeomInp =
mkHsraInpTyInfo Nothing stDWithinGeometryInpTy $ fromInpValL
[ InpValInfo Nothing "from" Nothing $ G.toGT $ G.toNT $ mkScalarTy PGGeometry
, InpValInfo Nothing "distance" Nothing $ G.toNT $ G.toNT $ mkScalarTy PGFloat
, InpValInfo Nothing "distance" Nothing $ G.toNT $ mkScalarTy PGFloat
]
stDWithinGeogInp =
mkHsraInpTyInfo Nothing stDWithinGeographyInpTy $ fromInpValL
[ InpValInfo Nothing "from" Nothing $ G.toGT $ G.toNT $ mkScalarTy PGGeography
, InpValInfo Nothing "distance" Nothing $ G.toNT $ mkScalarTy PGFloat
, InpValInfo
Nothing "use_spheroid" (Just $ G.VCBoolean True) $ G.toGT $ mkScalarTy PGBoolean
]

emptyGCtx :: GCtx
Expand Down
Loading