Malformed Cursor (shopify graphql api query)

Malformed Cursor (shopify graphql api query)


0

I am trying to fetch collections (paginated) from my shopify store using graphql query, i have written this route:

async function (req: CustomRequest, res: Response) {
const shopUrl: string = req.shopUrl || "";
const accessToken: string = req.accessToken || "";

let { count, after }: any = req.query;
const params = new URLSearchParams();

if(!count){
  count = defaultCount;
}

const paginationParams = after ? `, after: ${JSON.stringify(after)}` : '';
console.log("count: "+ String(count), "params: "+ paginationParams);

const query = `query {
  collections(first: ${count}, sortKey: UPDATED_AT, reverse: true${paginationParams}) {
    pageInfo {
      hasNextPage
      endCursor
    }
    edges {
      node {
        id
        title
        handle
        updatedAt
        productsCount
        image {
          url
          width
          height
        }
      }
    }
  }
}`;

console.log(query);
params.set("query", query);
const collections = await fetchCollections(
  shopUrl,
  accessToken,
  params,
  res
);

return collections;

At execution its logging:

{
  data: null,
  errors: [
    { message: 'Malformed cursor', locations: [Array], path: [Array] }
  ],
  extensions: {
    cost: {
      requestedQueryCost: 4,
      actualQueryCost: 2,
      throttleStatus: [Object]
    }
  }
}

after variable is a string only, and the shopify store has a lot of collections to display. when i set the paginationParams as empty string it’s working.


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *