tfoxy / graphene-django-optimizer

Optimize database access inside graphene queries
MIT License
428 stars 84 forks source link

Is Django 4.1.5 supported? #91

Open dharani7998 opened 1 year ago

dharani7998 commented 1 year ago

Hi, I was trying out the query optimizer for my POC but even a simple query returned an error.

class ProductType(DjangoObjectType):
    class Meta:
        model = Product
        fields = ALL_FIELDS

class Query(graphene.ObjectType):
    products = graphene.List(ProductType)

    def resolve_products(root, info):
        return gql_optimizer.query(Product.objects.all(), info)
{
  "errors": [
    {
      "message": "There is no current event loop in thread 'Thread-1 (process_request_thread)'.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "products"
      ]
    }
  ],
  "data": {
    "products": null
  }
}

And can you also please add an example of how to use it with the relay interface? When I tried it, it returned an error.

class ProductNode(DjangoObjectType):
    class Meta:
        model = Product
        filter_fields = "__all__"
        interfaces = (relay.Node,)

class Query(graphene.ObjectType):
    products = DjangoFilterConnectionField(ProductNode)

    def resolve_products(root, info):
        return gql_optimizer.query(Product.objects.all(), info)
{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field BrandNodeConnection.edges.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "brands",
        "edges"
      ]
    }
  ],
  "data": {
    "brands": null
  }
}

python==3.10.8

Django==4.1.5 graphene==3.2.1 graphene-django==3.0.0 graphene-django-optimizer==0.9.1

gdvalderrama commented 1 year ago

Going from Django 3.2 to 4.2 this dependency breaks