简体   繁体   English

如何使用 Hasura GraphQL 查询 postgres RangeField

[英]How to query postgres RangeField using Hasura GraphQL

Python3 Python3
django==3.0.5 django==3.0.5
Hasura v1.1.1哈苏拉 v1.1.1
postgres==11.3 postgres==11.3

I am trying to use Hasura filter on the IntegerRangeField() and DecimalRangeField() , but stuck at first one我正在尝试在IntegerRangeField() and DecimalRangeField()上使用Hasura过滤器,但停留在第一个

from django.contrib.postgres.fields import DecimalRangeField, IntegerRangeField
from django.db import models

class MyModel(modles.Model):
   age = IntegerRangeField()
   ...

In browser I query with this payload在浏览器中,我使用此有效负载进行查询

query MyQuery {
  insurance_life_premium(where: {age: {_eq: "47"}}) {
    percentage_rate
    plan_id
    policy_term
    premium
    sum_insured
  }
}

It raises error它引发错误

{
  "errors": [
    {
      "extensions": {
        "path": "$",
        "code": "data-exception"
      },
      "message": "malformed range literal: \"47\""
    }
  ]
}

I confirm that my database has valid data我确认我的数据库有有效数据

In [1]: Premium.objects.filter(age__contains=47)
Out[1]: <QuerySet [<Premium: Premium object (1)>, <Premium: Premium object (60)>, <Premium: , <Premium: Premium object (878)>, '...(remaining elements truncated)...']>

In terminal it mentions about parentheses在终端它提到了parentheses

hasura_1    | {"type":"http-log","timestamp":"2020-04-29T17:19:08.094+0000","level":"error","detail":{"operation":{"user_vars":{"x-hasura-role":"admin"},"error":{"path":"$","error":"malformed range literal: \"47\"","code":"data-exception"},"request_id":"aab2de87-1095-423e-9eb1-dae34926b226","response_size":78,"query":{"operationName":"MyQuery","query":"query MyQuery {\n  insurance_life_premium(where: {age: {_eq: \"47\"}}) {\n    percentage_rate\n    plan_id\n    policy_term\n    premium\n    sum_insured\n  }\n}\n"}},"http_info":{"status":200,"http_version":"HTTP/1.1","url":"/v1/graphql","ip":"172.22.0.1","method":"POST","content_encoding":null}}}
postgres_1  | 2020-04-29 17:19:08.095 UTC [34] ERROR:  malformed range literal: "47"
postgres_1  | 2020-04-29 17:19:08.095 UTC [34] DETAIL:  Missing left parenthesis or bracket.
postgres_1  | 2020-04-29 17:19:08.095 UTC [34] STATEMENT:  SELECT  coalesce(json_agg("root" ), '[]' ) AS "root" FROM  (SELECT  row_to_json((SELECT  "_1_e"  FROM  (SELECT  "_0_root.base"."percentage_rate" AS "percentage_rate", "_0_root.base"."plan_id" AS "plan_id", "_0_root.base"."policy_term" AS "policy_term", "_0_root.base"."premium" AS "premium", "_0_root.base"."sum_insured" AS "sum_insured"       ) AS "_1_e"      ) ) AS "root" FROM  (SELECT  *  FROM "public"."insurance_life_premium"  WHERE (("public"."insurance_life_premium"."age") = ($2))     ) AS "_0_root.base"      ) AS "_2_root"
query MyQuery {
  insurance_life_premium(where: {age: {_eq: "[46]"}}) {
    percentage_rate
    plan_id
    policy_term
    premium
    sum_insured
  }
}

Same error同样的错误

 "message": "malformed range literal: \"[46]\""

I had tried {age: {_in: "(47,]"}} and combination of bracket and square bracket. It return to me blank list我试过{age: {_in: "(47,]"}}以及括号和方括号的组合。它返回给我空白列表

At this moment.在这一刻。 It does not support yet目前还不支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM