-
Notifications
You must be signed in to change notification settings - Fork 769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Add DjangoInstanceField to allow reuse queryset on DjangoObjectType #1133
base: main
Are you sure you want to change the base?
Conversation
This looks like an alternative approach to #1112 ; I see a couple benefits with the approach here:
However, the approach in #1112 works with relay ids (if the DjangoObjectType opts into the relay interface), this does not. |
…ype with relay id and Foreign Key support
0e46aa7
to
fbdc10f
Compare
@zbyte64 I also unified the OneToOneRel field to use the DjangoInstance. In this case we will need to make the extra query because Django does provide the ID of the reverse relation. Please let me know what do you think. I'm using this approach in my project and it is working so far well. |
6580700
to
e98fa5d
Compare
else: | ||
description = get_django_field_description(field) | ||
|
||
return DjangoInstanceField( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also lookup the primary field of the model and pass the result in as unique_fields
? I could see a model having a different primary key field name and I think that would cause this to break
We're going to want to add two unit tests:
|
@zbyte64 I will have to add some extra code that I did before addressing some issues with some variables names but I’ll be able to do it next week |
Hello @sebsasto ! Planning to update this PR? |
There are some scenarios in which you want to use the queryset inside
DjangoObjectType
as a pre-filter to return a single object.In these cases you might not want to do the whole check again in the resolver to do the filtering of the queryset. This new Field allow to use the
DjangoObjectType
queryset inside the resolver.Example:
In this case will try to get the object that is_active and have the id.
Example 2:
In this case the object there will be 2 filters in the queryset and then if will try to get the instance with the unique_field.