Comments (7)
When starting with this library you may have been tempted to use DjangoFilterPaginateListField as that looks like it does everything you need (which is what I did), but it is actually the combination of DjangoListObjectField and a customised DjangoListObjectType that gives you everything and a total count.
eg.
Set up your model Type:
class MyModelType(DjangoObjectType):
class Meta:
model = MyModel
fields = (your fields here)
filter_fields = {
All your filters here
}
Set up your model list type
class MyModelListType(DjangoListObjectType):
class Meta:
model = MyModel
Then set up your main query
class Query(graphene.ObjectType):
my_models = DjangoListObjectField(
MyModelListType,
description="Lists all my models",
)
Your gql query will look like this
query{
myModels {
results {
id
}
totalCount
}
}
and you'll get back
{
"data": {
"myModels": {
"results": [
{
id: 1
}
},
{
id: 2
}
],
"totalCount": 2
}
}
}
from graphene-django-extras.
I've just worked this out myself, so no worries. I'm going to post some notes in case someone else needs guidance.
from graphene-django-extras.
Thanks for figuring this out! It would be nice to have this in the docs.
from graphene-django-extras.
@paulsermon-gemfair were you able to get foreign fields to work with DjangoListObjectType
?
from graphene-django-extras.
@paulsermon-gemfair were you able to get foreign fields to work with
DjangoListObjectType
?
This should be largely automatic as long as the foreign key model has a type defined. I think.
from graphene-django-extras.
Thats what I thought as well, but I haven't been able to get it to work for me 🤷
from graphene-django-extras.
You can try using the DjangoFilterPaginateListField within a type eg:
class MyObjectType(DjangoObjectType):
things = DjangoFilterPaginateListField(
ThingObjectType,
)
that seems to work automatically for me too.
from graphene-django-extras.
Related Issues (20)
- Dynamic Schema generation
- Travis rewrite to GitHub Actions HOT 2
- TODO
- Tried installing graphene-django-extras, but get errors about incompatibility HOT 3
- ImportError: cannot import name 'force_text' from 'django.utils.encoding' HOT 1
- Regarding UnionTypes
- When using a model with a UUID Field as ID the update method does not provide a UUID Field HOT 1
- No type registered for model: <model>
- Getting duplicate results on a filter across multiple fields. Cannot add distinct.
- still maintained? HOT 5
- python error: can only concatenate list (not "tuple") to list in __init__.py
- Updates removing other fields if not supplied: Might not be specific to graphene-django-extras
- ImportError: cannot import name 'JSONField' from 'graphene_django.compat'
- AssertionError: Page value for PageGraphqlPagination must be a non-zero value
- Filtering on enum fields returns all results HOT 1
- Logs received not informative
- DjangoListObjectType BigInt Error
- Filter error HOT 2
- Pagination Total Count in DjangoFilterPaginateListField
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 graphene-django-extras.