Repository navigation
Django integration implementation - #60
Conversation
|
I've updated graphene with a big refactor using Apart from that I think Other than this and your checklist items everything looks good! |
Discussion can be found here: graphql-python#48 Original gist can be found here: https://gist.github.com/adamcharnock/ad051b419d4c613d40fe
5752c97 to
a5d73ac
Compare
|
Great, I've just rebased the branch. There was only a minor conflict in I was wondering the same thing about I've got some client work coming up next week, so my hope is to have this mostly done in the next few days. |
This is supported for AutoFields, OneToOneFields, and ForeignKey. I have also added the GrapheneFilterSet base class. This provides customsiations needed for Graphene. However, making developers tie their FilterSets to Graphene would not be ideal as it would prevent their use elsewhere. I therefore wrap any FilterSets provided to Graphene with this additional functionality. See `setup_filterset()` for how this is done. Such FilterSets are also created by `custom_filterset_factory()` (in times when a filterset is implicitly required via the `fields` or `order_by` params passed to `DjangoFilterConnectionField`.
|
@syrusakbary I'm thinking about your idea of method decorators. I'm imaging something like this: class Query(ObjectType):
all_accounts = DjangoFilterConnectionField(AccountNode)
@filter_connection(fields=['id', 'name', 'slug'], order_by=['name', 'slug'])
def resolve_all_accounts(self, args, info):
return Account.objects.filter(user=info.context.request_context.user)Is that roughly what you had in mind? Is there any benefit of doing that over doing this (which is now implemented): class Query(ObjectType):
all_accounts = DjangoFilterConnectionField(AccountNode,
fields=['id', 'name', 'slug'],
order_by=['name', 'slug'])
def resolve_all_accounts(self, args, info):
return Account.objects.filter(user=info.context.request_context.user) |
|
I was thinking something similar to the code you wrote, however I just realized the Field should know which arguments it's going to receive (you cannot send random arguments, as have to be created explicitly), so the arguments have to be typed in the Field definition. Adding then So, let's keep it lean and simple, and go with your current implementation without method decorators :) |
I have moved it from `DjangoFilterConnectionField` and pushed it down into `FilterConnectionResolver` where I think it makes more sense for it to live. I have also pulled out `get_filtering_args_from_filterset()` as a utility method.
Graphene should now run fine without django-filter. Tests will also run without django-filter. However, I'm leaving it as a requirement in setup.py's `tests_require` setting as testing without it is probably not to be encouraged.
As pip doesn't seem inclined to pickup on tests_require
This can be customsied via the GRAPHENE_ORDER_BY_FIELD setting, or by extending GrapheneFilterSet. I'm open to this being called 'order_by'.
|
Any views on the ordering field being called |
|
I've been thinking more, and maybe the filter args could be inside a InputObjectType, so instead of requesting: {
posts(first:2, headline__icontains: "peter") {
title
}
}We can do {
posts(first:2, filter: {headline__icontains: "peter"}) {
title
}
}This way, we can implement exclude very easily too, and if we have more args it wont collide with the filter fields. But I'm not pretty convinced yet. |
|
I think having a |
|
How mount works: All the fields when contributed to a class (meaning, when placed as attrs inside a class), hold a relation to the class where is contributed. class MyObjectType(ObjectType):
name = Field(String())So the But, Why referencing or mounting the inner types? class Human(ObjectType):
friends = Field(List('self'))Hope this clarifies a little bit how mounting works! @adamcharnock |
…s not correctly traverse relationships
|
@syrusakbary Great. I've done a little more work on the docs but then got sidetracked by a bug I discovered. It seems that the results are not correctly returned when relationships are traversed (for filtered models only). All results are returned rather than just the results for that relationship. I've spent a couple of hours trying to figure this out, but I've clearly forgotten how a lot of this hangs together since I last came to it. Would you be able to shed any light on this? I'll do some more work on the docs. |
|
I will try to fix the issue with the relations, the test you added really helps! ;) |
|
@syrusakbary Great, thank you! I've just expanded on the django quckstart and added a separate section on filtering. Let me know if you think I've missed anything (or it needs any amends), but other than that I think I'm happy to consider it done. |
|
I've also added an example django app named
|
Improved integration with Django
|
I have to re-read everything and add some test cases. But this could be merged very soon @adamcharnock :) |
|
Brilliant! Thanks so much for taking a look over it. |
|
👍 |
|
I've tested this among with the changes in #79 and this is now good to go. |
Django integration implementation
|
Fantastic! 💃 |
…hon#59-fix-test-django-settings graphql-python#59 fix test django settings
I'm creating this (work in progress) pull request given that #48 seems to have developed a sensible solution.
This pull request currently represents the contents of the original proposed Gist which can be found at:
https://gist.github.com/adamcharnock/ad051b419d4c613d40fe
Todo:
GlobalIDFilterandGlobalIDFieldfieldConsider allowing the new resolvers to be used as function decorators (as per @syrusakbary suggestion)fieldsargument toDjangoFilterConnectionField(as per @syrusakbary suggestion)django-filtershould be an optional packageorderrather thanoMetaclassFiltering should be enabled explicitly (i.e. via Django setting) rather than implicit (via presence ofdjango-filter).Useful, but perhaps for a second phase of development: