The following query shows an error in the GraphiQL console "Subscription xyz must select only one top level field".
subscription xyz {
abc { id },
pqr { id }
}
However, the query works fine when executed.
@hrj Unfortunately, multiple top level fields are not a part of the GraphQL subscription spec:
https://facebook.github.io/graphql/draft/#sec-Single-root-field
@coco98 I think you should be able to have subscription for a table and its aggregation so I can retrieve new updates while maintaining the total rows of the database..
@slowr Isn't that already possible:
Consider a profile table with columns id, name.
query {
profile_aggregate {
aggregate {
count
}
nodes {
id
name
}
}
}
didn't find inside the documentation that nodes exists inside the aggregate table. thanks for the help!
The funny thing is that, though it shows error, you can still subscribe to multi root queries.
In this case, i recommend to use graphqurl if you want to consume that subscription. ApolloClient doesn't support it (yet)
@hrj Please re-open if there are further questions.
Commenting here - I have a need to retrieve the total count of a particular query, but also provide pagination using limit and offset. With a normal query I can simply remove the offset/limit portion of the arguments, but with I've found that aggregate.count will return the total count constrained to the limit that's set - is there a way to accomplish this with limiting queries but still return the total count of the full query?
@calvinl You should make the aggregate query to get total count separate from the query that selects the nodes.
query {
profile_aggregate {
aggregate {
count
}
}
profile (limit: 10, offset:0)
id
name
}
}
@shahidhk this is for a subscription which only allows one top level node.
Most helpful comment
@hrj Unfortunately, multiple top level fields are not a part of the GraphQL subscription spec:
https://facebook.github.io/graphql/draft/#sec-Single-root-field