如何使用django-graphql-geojson-distance_Lte过滤器问题

时间:2019-09-25 14:25:25

标签: django graphql geojson

我想像描述的自述文件https://github.com/flavors/django-graphql-geojson中那样使用distance_Lte过滤器。但是我没有得到预期的结果。有人可以告诉我我的失败是什么吗?

我的django类:

class Location(models.Model):
    calendar = models.ForeignKey(Calendar, on_delete=models.CASCADE)
    name = models.CharField(max_length=255)
    location = models.PointField(srid=4326, unique=True)
    address = models.CharField(max_length=100)
    city = models.CharField(max_length=50)

class LocationType(GeoJSONType):
    class Meta:
        model = Location
        geojson_field = 'location'
        filterset_class = LocationFilter
        interfaces = (relay.Node,)
        exclude = []

class LocationFilter(GeometryFilterSet):
    class Meta:
        model = Location
        fields = {
            'city': ['exact', 'icontains', 'istartswith'],
            'location': ['exact', 'intersects', 'distance_lte']
        }

class Query(graphene.ObjectType):
    location = relay.Node.Field(LocationType)
    locations = DjangoFilterConnectionField(LocationType)

我的graphql查询:

query{
  locations(location_DistanceLte:{geometry:"{'type': 'Point', 'coordinates': [13.28702,52.4581]}", value:400, unit:"km"}){
    edges{
      node {
        id
      }
    }
  }
}

错误消息:

{
  "errors": [
    {
      "message": "Argument \"location_DistanceLte\" has invalid value {geometry: \"{'type': 'Point', 'coordinates': [13.28702,52.4581]}\", value: 400, unit: \"km\"}.\nExpected type \"Geometry\", found {Geometry: \"{'type': 'Point', 'coordinates': [13.28702,52.4581]}\", value: 400, unit: \"km\"}.",
      "locations": [
        {
          "line": 2,
          "column": 34
        }
      ]
    }
  ]
}

我不知道,我做错了什么。如果您能提供帮助,那将很好。

谢谢

0 个答案:

没有答案