question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make count fields plain integers.

See original GitHub issue

TL;DR

In short, I would like us to use a plain GraphQLInt for counts fields. I don’t really see a need to be able to format a count in MP, but would like to know if others have objections.


As we move to TypeScript and convert MP’s schema to type declarations, we’re running into the issue that for many (all?) of the counts fields we have, the resulting type declaration is number | string | boolean, because we are using a custom scalar rather than a specific subtype.

This type declaration is problematic because it would require us to go through hoops to cast the value as a number in order to safely write code like:

const not_for_sale_works = artist.counts.artworks - artist.counts.for_sale_works

The TypeScript compiler will fail with the following error:

error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.

/cc @sweir27 @broskoski @l2succes

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:21 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
broskoskicommented, Feb 16, 2017

@alloy Not automatically. pageInfo only returns cursors (startCursor and endCursor) as well as whether there are more page results or not. See: https://facebook.github.io/relay/graphql/connections.htm#sec-undefined.PageInfo

0reactions
alloycommented, Feb 16, 2017

@broskoski Good point, we can just prefix the int fields. Maybe as another nested field? E.g.

counts {
  raw {
    for_sale_artworks
  }
}

Not a big fan of the word ‘raw’, though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

COUNT function - Microsoft Support
Use the COUNT function to get the number of entries in a number field that is in a range or array of numbers....
Read more >
Google Sheets COUNT and COUNTA functions with formula ...
The COUNT function in Google Sheets allows you to count the number of all cells with numbers within a specific data range.
Read more >
postgresql - sql - count of `true` values - Stack Overflow
Since PostgreSQL 9.4 there's the FILTER clause, which allows for a very concise query to count the true values: select count(*) filter (where...
Read more >
Python's Counter: The Pythonic Way to Count Objects
In this step-by-step tutorial, you'll learn how to use Python's Counter to count several repeated objects at once.
Read more >
How to count the number of lines in a CSV file in Python?
A CSV file stores tabular data (numbers and text) in plain text. ... Each record consists of one or more fields, separated by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found