hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
30.98k stars 2.75k forks source link

Perform CIDR queries #2113

Closed CR1AT0RS closed 6 days ago

CR1AT0RS commented 5 years ago

I am trying to move my database over to Hasura but its not clear how can I store and use native Postgres functionality of querying and storing CIDR values. For example:

Create table to store INET/CIDR: CREATE TABLE test_cidr ( id SERIAL PRIMARY KEY, ip CIDR UNIQUE, region VARCHAR(1000), service VARCHAR(1000));

Table contents

test_cidr 
ip 
64.6.64.0/24

Select query on Table SELECT * FROM test_cidr WHERE ip >> '152.53.xxx.xx';

This returns a list of CIDR which includes this IP. This works on native Postgres. I am wondering how can I achieve this using implicit datatype?

ecthiender commented 5 years ago

@CR1AT0RS Hasura doesn't support CIDR operators (functions) on its graphql API yet. The console UI also doesn't have the CIDR as a type of column yet.

One workaround for this, for now, could be:

  1. You can use the "SQL" section in "Data" tab to run arbitrary SQL and create tables with CIDR columns.
  2. You can create a Postgres function to take in IP address as input and return required values.
  3. You can use the above created function in the graphql API

Does this help ? I will mark this issue as a feature request for CIDR datatypes and related functions/operators.

tpurschke commented 3 years ago

@0x777 Facing a similar issue here. Can you give feedback if there is any progress around this issue? Would be great to have the following filter query work with cidr logic to return all overlapping ip addresses (in this example all ip addresses in the network 10.2.0.0/16):

query filterNetworkObjects($objIpMatch: cidr) { object(where: {obj_ip: {_gte: $objIpMatch, _lte: $objIpMatch}}) { obj_name obj_ip }

variables: {"objIpMatch": "10.2.0.0/16"}

CR1AT0RS commented 3 years ago

@ecthiender yes I was able to get around it but a native type support would be awesome. Thanks for adding in enhancement tag.

tpurschke commented 3 years ago

@marionschleifer do you think there is any chance this will be implemented in the near future? Our project is really depending on it, so we would need an indication if hasura might be suitable or not. many TIA.

kleingeist1 commented 2 years ago

I agree - this feature would be really helpful,

NilsPur commented 2 years ago

Any news?

tpurschke commented 2 years ago

@coco98 I am wondering if there is a chance this issue might be prioritized?

vkotronis commented 1 year ago

Hello! Is there anything on the roadmap for supporting such filtered queries on CIDR objects? It is a very useful use case for systems that store e.g., IP prefix-related data, using hasura as the GQL middleware.

soupi commented 6 days ago

Hasura v3's ndc-postgres now supports CIDR and other native PostgreSQL types. The CIDR operator '>>' is exposed as the procedure name 'network_sup'.