Comments (3)
Hey @hiporox ,
Although I understand your use case there, I'm thinking how often this happens to justify this change.
I mean, if you have something that can be prefetched with a name of related_models
, I would say that semantically it is very unlikely that you will want to return anything different than a list/relay connection in its resolver. In your example, it seems to me that the name should be related_models_active
.
But having said that, right now the optimizer will optimize the field, using hints from the field, then from the @model_property
and then from inspecting the model field and merge all of those. Instead, we should probably get only the first one of those. So, in your case here, it would not optimize anything (but you could pass hints to the field to have it optimized if you want)
What do you think?
from strawberry-django-plus.
@bellini666 That suggestion sounds like a great fix.
As for the use case I have is applying a filter to the sub-object, where I don't know exactly what the filter will contain. A query like:
{
model {
id
relatedModels (filters: { ... } ) {
id
}
}
I am doing this with the following:
from strawberry_django.filters import apply as apply_gql_filter
@gql.django.type(Model)
class ModelType:
id: strawberry.ID
@gql.django.field
def related_models(self, info, filter: RelatedModelFilter = UNSET) -> List[RelatedModelType]:
return apply_gql_filter(filter, self.related_models)
I agree that if I knew what the filters that would be applied were, that this would not be necessary, as I could do something like active_related_models
, but having to name it something like filtered_related_model
feels a little weird.
from strawberry-django-plus.
@hiporox I tried to implement my suggestion but in the end it would complicate the code a lot because of the automatic field creation by annotations.
I decided to add a new disable_optimization
keyword to the field, so you can gql.django.field(disable_optimization=True)
and it should disable it.
Maybe we should revisit this in the future to solve this in a more robust way, but for now this should be enough and should solve your issue. Please reopen this if that's not the case.
from strawberry-django-plus.
Related Issues (20)
- Unset input field value broken after strawberry >= 0.133.1 HOT 3
- Allow customization of model relations for the query optimizer HOT 7
- Unable to access model's foreign key field directly in Strawberry type HOT 4
- `AttributeError: 'NoneType' object has no attribute 'return_type'` on connection fields HOT 4
- Permission Directives when deploying scema through GraphQLHTTPConsumer HOT 2
- Optimizer throws an exception for union queries HOT 1
- AttributeError with strawberry-graphql 0.140.3: type object 'str' has no attribute 'resolve'
- Optimizier omits slicing of connection query set HOT 1
- DjangoOptimizerExtension not optimizing when fragments are used and field is queried twice HOT 2
- Regression with mypy from #137 HOT 1
- CUD mutations Input vs NodeInput HOT 5
- FieldError when using select_related with enable_only_optimization HOT 4
- matching query does not exist error when relational field does not exist HOT 1
- Query optimization based on type hints for non-model fields? HOT 4
- Prefetch related selects all the fields on the model instead of the ones specified in the gql query HOT 2
- Cursor Pagination without relay HOT 2
- HasObjPerm directive on a update mutation fails updating the cache, due to unhashable type OperationInfo HOT 7
- Optimizer causes duplicate query when filtering or paginating a related field HOT 11
- Non-obvious moments when overloading the Connection HOT 1
- InputMutation / Mutation not working with List return type HOT 3
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.