How to limit the number of items of nested array in Apollo graphQL / Apollo Link Rest? - graphql

I Have a query like this
`
query {
doctors #rest(type: "doctors", path: "/doctors/") {
Result {
Id
FirstName
LastName
Items (limit: 10) {
id
title
}
}
}
`
I want to get only 10 items from the Items, but I get the full list!
Is This doable or not?
Thank you.

Related

Size for FaunaDB GraphQL nested query

How do I set the size for a nested query?
For instance, the following will only return max. 50 users for each group.
const query = gql`
query GetGroups {
groups(_size: 100){
data{
_id
name
users(_size: 500){
data{
_id
name
}
}
}
}
}
`
It looks like you wrote your query correctly. You will get a GraphQL error if you provide the _size argument where it is not allowed.
If there are only 50 results showing up when providing a size greater than 50, then there most likely exactly 50 matches.
The GraphQL query you shared will be compiled to FQL that works roughly like the following, and return the result of paginating the nested relationship with the size that you provide.
Let(
v0: Paginate(Match(Index("groups")), { size: 100 }),
{
groups: {
data: Map(
Var("v0"),
Lambda(
"ref",
Let(
{
v1: Paginate(
Match(Index("group_users_by_group"), Var("ref")),
{ size: 500 }
)
},
{
users: Map(Var("v1"), /* ... select fields for users */),
/* ... select other fields for group */
}
)
)
)
}
}
)
If you are still concerned that there is an issue, please contact Fauna support at support.fauna.com or by emailing support#fauna.com, using the email you used to sign up. Then we can take a closer look at your account.

GraphQl request from Strapi only returning 10 items [duplicate]

I am using React with Strapi and GrapqQL in order to retreive my data from Strapi.
Seems that my query retrieves only maximum 10 items. The API is changed with this new version and I am not allowed to use first:100 in the query.
This link 1 is obsolete. I don't know if this is a policy from Strapi's or GraphQL's new version.
1 https://graphql.org/learn/pagination/
const REVIEWS = gql`
query GetReviews {
reviews (sort: "createdAt:desc") {
data{
id
attributes{
title
rating
body
createdAt
categories{
data{
id
attributes
{
name
}
}
}
}
}
}
}
`
The documentation for Strapi v4 is available here.
Could you try with:
const REVIEWS = gql`
query GetReviews {
reviews (sort: "createdAt:desc", pagination: { limit: 100 }) {
data{
id
attributes{
title
rating
body
createdAt
categories{
data{
id
attributes
{
name
}
}
}
}
}
}
}
`
The default and maximum values for pagination[limit] can be configured in the ./config/plugins.js file with the graphql.config.defaultLimit and graphql.config.maxLimit keys.

Shopify API - get bulk products by collection id using graphQL

I need to fetch all products using Shopify API by collection id...
I tried:
mutation {
bulkOperationRunQuery(
query:"""
{
products(query: "tag:women OR collection:172173852808") {
edges{
node{
id
tags
images {
edges {
node {
id
originalSrc
}
}
}
variants(first:10) {
edges{
node{
id
price
compareAtPrice
image{
originalSrc
}
inventoryQuantity
selectedOptions{
name
value
}
sku
title
weight
weightUnit
}
}
}
}
}
}
}
"""
) {
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}
Result Shopify gives me is just product with tags: women and there are no products from collection id 172173852808
How to run a query to get products from one or more specific connections?
If every product in that collection has the tag woman, just change your query to bulk download the collection and its products. Also, before you go and do a bulk query, verify it works without being a bulk query. That usually exposes the problems with the setup.

How can I filter by uid of a linked document / relationship using the prismic graphql api?

I am trying to list a set of articles by their categories, by uid, and I'm assuming that I would have to use the where query, but I'm not able to get that to worked on linked documents.
The issue seems to be that where only accepts a string on a field, but in the case of a linked document you would need to dig down to the uid field.
I'm not sure if I'm using the wrong query, but struggling to find anything in the documentation to help me out.
I tried digging into the category object:
{
allDirectoryServices(
where: { category: { _meta: { uid: "developers" } } }
) {
edges {
node {
name
city
region
country
category {
...on DirectoryTaxonomy {
_meta {
uid
}
name
}
}
}
}
}
}
But that returns an error that it's expecting a string:
"message": "Expected type String, found {_meta: {uid: \"developers\"}}.",
{
allDirectoryServices(
where: { category: "developers"}
) {
edges {
node {
name
city
region
country
category {
...on DirectoryTaxonomy {
_meta {
uid
}
name
}
}
}
}
}
}
This returns no results, obviously.
I asked this question on the Prismic Slack group too, and got the answer from them:
In order to query by a Content Relationship / Link field like this, you need to use the document ID.
where: { category: "WBsLfioAABNUo9Kk" }
Unfortunately it isn’t possible to query by the UID (or any other field).
I imagine they will be updating their documentation soonish, as this isn't covered by it.
Thanks to the Prismic guys!

GraphQL non nested relation

I'm trying to have a representation of nodes on GraphQL more akin to what jsonapi would be like http://jsonapi.org/
What I mean is if we take one of the examples on GraphQL
{
hero {
name
# Queries can have comments!
friends {
name
}
}
}
Have a representation that would be more along these lines
{
hero {
name
# Queries can have comments!
friends {
id
}
},
friends {
id, name
}
}
Is that at all possible in GraphQL
Thanks
It is possible, and there's nothing wrong with having a friends field. In GraphQL terms you can have the following part of the schema:
type User {
id: ID
name: String
firends: [User]
}
type RootQuery {
hero: User
friends(forUserId: ID!): [User]
}
And then you can query this as you like – you can ask for friends separately:
{
friends(forUserId: "12") {
id, name
}
}
But the whole idea of GraphQL is that you don't have to do multiple queries to get the information you need. If you just need a list of users – that's a reasonable query, that most people have (with arguments for pagination and so on). With that said, there's no reason to fetch a list of IDs and to send another fetch query for the data right after that.

Resources