Comments (5)
Hey @yergom !
I think that the issue is because you defined it using gql.field
instead of gql.django.field
. Could you try that?
Also, it should work with just node: gql.Node = gql.django.node()
(please tell me if it doesn't)
But if you have non django types implementing the Node
interface, then the resolver would need to workaround that. It should not be complicated 3 to 5 lines of code should do that and I can tell you want exactly needs to be done, but lets see if you really need that first =P
from strawberry-django-plus.
I've tried both options, and none of them optimize the query. The reproduction steps are fairly simple. Given the following model:
class Container(models.Model):
name = models.TextField()
class Item(models.Model):
name = models.TextField()
container = models.ForeignKey(Container, related_name="items", on_delete=models.CASCADE)
@gql.django.type(Item)
class ItemType(gql.Node):
name: gql.auto
container: "ContainerType"
@gql.django.type(Container)
class ContainerType(gql.Node):
name: gql.auto
items: List[ItemType]
@gql.type
class Query:
node: gql.Node = gql.django.node()
@gql.django.connection
def all_containers(self) -> Iterable[ContainerType]:
return Container.objects.all()
And instantiating 1 container with 10 items, the following query:
query all {
allContainers{
edges{
node{
id
name
items{
name
}
}
}
}
}
requires 3 sql queries (1 for counting, 1 for getting the container id/name, and 1 for the prefetch of Items), whereas the following query:
query node{
node(id:"UD"){
... on Container{
name
items{
name
}
}
}
}
is creating 13 sql queries. So no prefetch
and no only
optimization.
from strawberry-django-plus.
Hey @yergom ,
Just to ask you if you had any luck working around your issue? I unfortunately didn't have much time those days to check this. Will try to do soon though.
from strawberry-django-plus.
Hey @bellini666, unfortunately I haven't had time either. For now, my (poor's man) solution is to create independent query fields per type, which is obviously not ideal.
from strawberry-django-plus.
@yergom this should be fixed in the release 1.11 that I'm doing atm. Please reopen if it is not.
from strawberry-django-plus.
Related Issues (20)
- Querying both sides of a OneToOneField at the same time is an error HOT 5
- Can't make a union of `gql.Connection | OperationMessage` HOT 1
- Headers are not passed to `self.client.post` in `TestClient.request` HOT 1
- Can't make a union of `gql.Connection | OperationMessage` (part 2) HOT 9
- clash with the novel strawberry.relay module (GlobalId)
- relay: compatibility with the new strawberry.relay module HOT 2
- more SQLs then expected HOT 6
- need for an async resolvers.update HOT 1
- NameError with lazy types in relay connection annotations
- input_mutation: TypeError: MutateContentInput fields cannot be resolved HOT 9
- filters not showing up HOT 1
- Optimise manually prefetched field HOT 1
- Got an unexpected keyword argument 'filters' HOT 2
- NodeExtension broken with Strawberry HOT 1
- class inheritance not being detected? HOT 8
- hard dependency on contenttypes framework in optimizer
- hard dependency on django.contrib.auth HOT 1
- Using input_mutation with a None return type throws an exception HOT 1
- Query resolution is really slow HOT 15
- This repo has been merged into strawberry-graphql-django and it is now deprecated HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strawberry-django-plus.