adding count to query
See original GitHub issueI’m using the following code and would like to to have variable “count” (number of total results) in my response – but I have no idea on how to solve it (already did quite some research).
class EntryNode(DjangoNode):
class Meta:
model = Entry
class Query(ObjectType):
all_entries = DjangoFilterConnectionField(EntryNode)
class Meta:
abstract = True
Query
{allEntries(first:5) {
pageInfo{hasPreviousPage, hasNextPage},
edges{node{id,user{id,username},title,category{id,name}}}
}}
Results I’d like to have an additional variable “count” (either within “allEntries” or even better as a part of “pageInfo”)
{
"data": {
"allEntries": {
"pageInfo": {
"hasPreviousPage": false,
"hasNextPage": false,
"count": ???,
},
"count": ???,
"edges": [
{
"node": {
"id": "RW50cnlOb2RlOjUy",
...
}
}
]
}
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
How to insert a count column into a sql query - Stack Overflow
SELECT COUNT (DISTINCT column_name) FROM table_name;. COUNT(DISTINCT) works with ORACLE and Microsoft SQL Server, but not with Microsoft Access.
Read more >Count data by using a query - Microsoft Support
Add a Total row · Open your query in Datasheet view. To do so for a database in the . · On the...
Read more >SQL: COUNT Function - TechOnTheNet
The SQL COUNT function is used to count the number of rows returned in a SELECT statement. Syntax. The syntax for the COUNT...
Read more >SQL COUNT() with GROUP by - w3resource
The use of COUNT() function in conjunction with GROUP BY is useful for characterizing our data under various groupings. A combination of same ......
Read more >SQL Count – How to Select, Sum, and Average Rows in SQL
If you need to add a group of numbers in your table you can use the SUM function in SQL. This is the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @sehmaschine, this is how I approached the same issue in swapi-graphene.
Example swapi-graphene totalCount query.
Implementation: https://github.com/graphql-python/swapi-graphene/blob/master/starwars/schema.py#L18-L22
And then use connection_type in your EntryNode:
Hope it helps!
[Reopen this issue if you run into some errors or have more questions in the process].
I arrived here by Google first but ultimately found the
total_count
implementation at this thread easier to follow and use: https://github.com/graphql-python/graphene-django/issues/162