/// <summary> /// Generates a query to receive a page of <c>collections</c> from a Shopify store. The generated query will query the following on collections: /// - id /// - title /// - description /// - descriptionHtml /// - updatedAt /// - image /// - altText /// - src /// - products /// - id /// /// Note that <c>shop.collections</c> is a Connection (GraphQL paginated data structure). <see ref="ShopifyClient.collections">collections </see> /// </summary> /// <param name="callback">callback that will receive responses from server</param> /// <param name="first">can be used to limit how many products are returned. For instance 10 would return only 10 collections</param> /// <param name="after"> /// is used to load subsequent pages. Basically it's a cursor variable to define what page to load next. For example, when used with <c>first: 10</c> and <c>after: "abc"</c>, only the first 10 /// collections would be loaded after cursor <c>"abc"</c>. If no <c>after</c> is passed the first page of collections will be loaded. /// </param> /// \code /// // Example that queries all collections on a shop /// ShopifyBuy.Client().collections((collections, error) => { /// Debug.Log(collections[0].title()); /// Debug.Log(collections.Count); /// }); /// \endcode public void collections(CollectionsPaginatedHandler callback, int?first = null, string after = null) { if (first == null) { first = DefaultQueries.MaxCollectionsPageSize; } GetCollectionsList((collections, error, afterGetProductsList) => { // Short circuit if we have an error. if (error != null) { callback(null, error, null); return; } List <ConnectionQueryInfo> connectionInfos = new List <ConnectionQueryInfo> () { new ConnectionQueryInfo( getConnection: (c) => ((Collection)c).products(), query: (c, productsAfter) => { ((CollectionQuery)c).products(pc => DefaultQueries.collections.ProductConnection(pc), first: DefaultQueries.MaxPageSize, after: productsAfter ); } ) }; ConnectionLoader loader = new ConnectionLoader(Loader); List <Node> nodes = collections.ConvertAll(p => (Node)p); loader.QueryConnectionsOnNodes(nodes, connectionInfos, BuildCollectionQueryOnNode, (nodesResult, responseError) => { callback(nodesResult.ConvertAll(n => (Collection)n), responseError, afterGetProductsList); }); }, first: first, after: after); }
private void GetConnectionsForProducts(List <Product> products, ProductsHandler callback) { List <ConnectionQueryInfo> connectionInfos = new List <ConnectionQueryInfo> () { new ConnectionQueryInfo( getConnection: (p) => ((Product)p).images(), query: (p, imagesAfter) => { ((ProductQuery)p).images(ic => DefaultQueries.products.ImageConnection(ic), first: DefaultQueries.MaxPageSize, after: imagesAfter ); } ), new ConnectionQueryInfo( getConnection: (p) => ((Product)p).variants(), query: (p, variantsAfter) => { ((ProductQuery)p).variants(vc => DefaultQueries.products.ProductVariantConnection(vc, DefaultImageResolutions), first: DefaultQueries.MaxPageSize, after: variantsAfter ); } ), new ConnectionQueryInfo( getConnection: (p) => ((Product)p).collections(), query: (p, collectionsAfter) => { ((ProductQuery)p).collections(cc => DefaultQueries.products.CollectionConnection(cc), first: DefaultQueries.MaxPageSize, after: collectionsAfter ); } ) }; foreach (string alias in DefaultImageResolutions.Keys) { string currentAlias = alias; connectionInfos.Add(new ConnectionQueryInfo( getConnection: (p) => ((Product)p).images(currentAlias), query: (p, imagesAfter) => { ((ProductQuery)p).images(ic => DefaultQueries.products.ImageConnection(ic), first: DefaultQueries.MaxPageSize, after: imagesAfter, maxWidth: DefaultImageResolutions[currentAlias], maxHeight: DefaultImageResolutions[currentAlias], alias: currentAlias ); } )); } ConnectionLoader loader = new ConnectionLoader(Loader); List <Node> nodes = products.ConvertAll(p => (Node)p); loader.QueryConnectionsOnNodes(nodes, connectionInfos, BuildProductQueryOnNode, (nodesResult, error) => { callback(nodesResult.ConvertAll(n => (Product)n), error); }); }
private void GetConnectionsForProducts(List <Product> products, ProductsHandler callback) { List <ConnectionQueryInfo> connectionInfos = new List <ConnectionQueryInfo> () { new ConnectionQueryInfo( getConnection: (p) => ((Product)p).images(), query: (p, imagesAfter) => { ((ProductQuery)p).images(ic => DefaultQueries.products.ImageConnection(ic, DefaultImageResolutions), first: DefaultQueries.MaxPageSize, after: imagesAfter ); } ), new ConnectionQueryInfo( getConnection: (p) => ((Product)p).variants(), query: (p, variantsAfter) => { ((ProductQuery)p).variants(vc => DefaultQueries.products.ProductVariantConnection(vc, DefaultImageResolutions), first: DefaultQueries.MaxPageSize, after: variantsAfter ); } ), new ConnectionQueryInfo( getConnection: (p) => ((Product)p).collections(), query: (p, collectionsAfter) => { ((ProductQuery)p).collections(cc => DefaultQueries.products.CollectionConnection(cc), first: DefaultQueries.MaxPageSize, after: collectionsAfter ); } ) }; ConnectionLoader loader = new ConnectionLoader(Loader); List <Node> nodes = products.ConvertAll(p => (Node)p); loader.QueryConnectionsOnNodes(nodes, connectionInfos, BuildProductQueryOnNode, (nodesResult, error) => { callback(nodesResult.ConvertAll(n => (Product)n), error); }); }