Answer the question
In order to leave comments, you need to log in
Prisma.io - how to get the number of records in a model?
There is a GraphQL server written in TypeScript using this example (graphQL-yoga, prisma).
There is schema.graphql
type Game {
id: ID!
name: String!
excerpt: String
}
type Query {
games: [Game!]!
}
Answer the question
In order to leave comments, you need to log in
Late answer, but still.
When you deploy a schema, three types of query are formed for each type (we are talking about Query):
object - a unique object
objects - a list of objects
objectsConnection - a list of objects with quantity data, etc.
In your case it will be
query {
gamesConnection{
aggregate{
count
}
edges{
node{
id
}
}
}
}
{
"data": {
"gamesConnection": {
"aggregate": {
"count": 0
},
"edges": []
}
}
}
query {
gamesConnection (
where: {
name_contains: "Test"
}
first: 2
){
aggregate{
count
}
edges{
node{
id
}
}
}
}
{
"data": {
"gamesConnection": {
"aggregate": {
"count": 15
},
"edges": [{id:"dsfdsf"}, {"id":"sdfsdgds}]
}
}
}
query games (
$where: GameWhereInput
$first: Int
){
gamesConnection (
where: $where
){
aggregate{
count
}
}
games (
where: $where
first: $first
){
id
name
}
}
{
"data": {
"gamesConnection": {
"aggregate": {
"count": 0
}
},
"games": []
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question