Переглянути джерело

Define more queries

- collection(handle: String id: ID): Collection
- products(
        after: String
        before: String
        first: Int
        last: Int
        query: String
        reverse: Boolean = false
        sortKey: ProductSortKeys = ID
    ): ProductConnection!
Alexey Kim 2 роки тому
батько
коміт
283e86e560
3 змінених файлів з 51 додано та 0 видалено
  1. 4 0
      graphql/query_collections.go
  2. 5 0
      graphql/query_product.go
  3. 42 0
      graphql/schema.graphql

+ 4 - 0
graphql/query_collections.go

@@ -10,6 +10,10 @@ import (
 	"gshopper.com/gshopify/products/graphql/helper"
 )
 
+func (r *queryResolver) Collection(ctx context.Context, handle *string, id *string) (*generated.Collection, error) {
+	panic("not implemented")
+}
+
 func (r *queryResolver) Collections(ctx context.Context,
 	after *string, before *string, first *int, last *int, query *string, reverse *bool, sort *generated.CollectionSortKeys) (*generated.CollectionConnection, error) {
 	var (

+ 5 - 0
graphql/query_product.go

@@ -42,6 +42,11 @@ func (r *queryResolver) Product(ctx context.Context, handle *string, id *string)
 	return product, nil
 }
 
+func (r *queryResolver) Products(ctx context.Context,
+	after *string, before *string, first *int, last *int, query *string, reverse *bool, sortKey *generated.ProductSortKeys) (*generated.ProductConnection, error) {
+	panic("not implemented")
+}
+
 func (r *productResolver) Description(_ context.Context, product *generated.Product, truncateAt *int) (string, error) {
 	return fun.TruncateAt(
 		bluemonday.StrictPolicy().Sanitize(string(product.DescriptionHTML)),

+ 42 - 0
graphql/schema.graphql

@@ -35,6 +35,8 @@ union SellingPlanCheckoutChargeValue = MoneyV2 | SellingPlanCheckoutChargePercen
 union SellingPlanPriceAdjustmentValue = SellingPlanFixedAmountPriceAdjustment | SellingPlanFixedPriceAdjustment | SellingPlanPercentagePriceAdjustment
 
 type Query {
+    collection(handle: String id: ID): Collection
+
     collections(
         after: String,
         before: String,
@@ -46,6 +48,16 @@ type Query {
     ): CollectionConnection!
 
     product(handle: String id: ID): Product
+
+    products(
+        after: String
+        before: String
+        first: Int
+        last: Int
+        query: String
+        reverse: Boolean = false
+        sortKey: ProductSortKeys = ID
+    ): ProductConnection!
 }
 
 # An auto-generated type for paginating through multiple Collections.
@@ -877,6 +889,36 @@ input ProductFilter {
     variantMetafield: MetafieldFilter
 }
 
+enum ProductSortKeys {
+    # Sort by the `title` value.
+    TITLE
+
+    # Sort by the `product_type` value.
+    PRODUCT_TYPE
+
+    # Sort by the `vendor` value.
+    VENDOR
+
+    # Sort by the `updated_at` value.
+    UPDATED_AT
+
+    # Sort by the `created_at` value.
+    CREATED_AT
+
+    # Sort by the `best_selling` value.
+    BEST_SELLING
+
+    # Sort by the price value.
+    PRICE
+
+    # Sort by the id value.
+    ID
+
+    # Sort by relevance to the search terms when the query parameter is specified on the connection.
+    # Don't use this sort key when no search query is specified.
+    RELEVANCE
+}
+
 # A filter used to view a subset of products in a collection matching a specific price range.
 input PriceRangeFilter {
     # The minimum price in the range. Defaults to zero.