Module: ShopifyOracle::Mutations

Defined in:
lib/shopify_oracle/mutations.rb

Constant Summary collapse

SUBSCRIPTION_DRAFT_UPDATE_MUTATION =
<<~GRAPHQL
  mutation($draftId: ID!, $input: SubscriptionDraftInput!) {
      subscriptionDraftUpdate(
        draftId: $draftId,
        input: $input
      ) {
        draft {
          id
        }
        userErrors {
          field
          message
        }
      }
    }
GRAPHQL
SUBSCRIPTION_DRAFT_COMMIT_MUTATION =
<<~GRAPHQL
  mutation($draftId: ID!) {
    subscriptionDraftCommit(draftId: $draftId) {
      contract {
        id
      }
      userErrors {
        field
        message
      }
    }
  }
GRAPHQL
ADD_LINE_ITEM_TO_SUBSCRIPTION_DRAFT_MUTATION =
<<~GRAPHQL.freeze
  #{ShopifyOracle::Fragments::LINE_ADDED}

  mutation subscriptionDraftLineAdd($draftId: ID!, $input: SubscriptionLineInput!) {
    subscriptionDraftLineAdd(draftId: $draftId, input: $input) {
      draft {
        id
      }
      lineAdded {
        ...LineAdded
      }
      userErrors {
        field
        message
      }
    }
  }
GRAPHQL
CREATE_SUBSCRIPTION_CONTRACT_V2_MUTATION =
<<~GRAPHQL
  mutation($customerId: ID!, $customerPaymentMethodId: ID!) {
    subscriptionContractCreate(
      input: {
        customerId: $customerId,
        nextBillingDate: "2022-09-01"
        currencyCode: GBP
        contract: {
          note: "Dear Sam, I hope you enjoy this gift."
          status: ACTIVE
          paymentMethodId: $customerPaymentMethodId
          billingPolicy: { interval: MONTH, intervalCount: 1, minCycles: 3 }
          deliveryPolicy: { interval: MONTH, intervalCount: 1 }
          deliveryPrice: 14.99
          deliveryMethod: {
            shipping: {
              address: {
                firstName: "John"
                lastName: "McDonald"
                address1: "33 New Montgomery St"
                address2: "#750"
                city: "San Francisco"
                province: "California"
                country: "USA"
                zip: "94105"
              }
            }
          }
        }
      }
    ) {
      draft {
        id
      }
      userErrors {
        field
        message
      }
    }
  }
GRAPHQL
CREATE_SUBSCRIPTION_CONTRACT_MUTATION =
<<~GRAPHQL.freeze
  #{ShopifyOracle::Fragments::SUBSCRIPTION_DRAFT}

  mutation subscriptionContractCreate($input: SubscriptionContractCreateInput!) {
    subscriptionContractCreate(input: $input) {
      draft {
        ...SubscriptionDraft
      }
      userErrors {
        field
        message
      }
    }
  }
GRAPHQL
ADD_VARIANTS_TO_SELLING_PLAN_GROUP_MUTATION =
<<~GRAPHQL
  mutation($sellingPlanGroup: ID!, $variants: [ID!]!) {
    sellingPlanGroupAddProductVariants(
      id: $sellingPlanGroup,
      productVariantIds: $variants
    ) {
      sellingPlanGroup {
        id
        productVariantCount
        productVariants(first: 10) {
          edges {
            node {
              id
              title
              inventoryQuantity
              product {
                id
                title
                totalInventory
              }
            }
          }
        }
      }
      userErrors {
        field
        message
      }
    }
  }
GRAPHQL
ADD_PRODUCTS_TO_SELLING_PLAN_GROUP_MUTATION =
<<~GRAPHQL
  mutation($sellingPlanGroup: ID!, $products: [ID!]!) {
    sellingPlanGroupAddProducts(
      id: $sellingPlanGroup,
      productIds: $products
    ) {
      sellingPlanGroup {
        id
        productVariantCount
        productVariants(first: 10) {
          edges {
            node {
              id
              title
              inventoryQuantity
              product {
                id
                title
                totalInventory
              }
            }
          }
        }
      }
      userErrors {
        field
        message
      }
    }
  }
GRAPHQL
EDIT_SELLING_PLAN_GROUP_NAME_MUTATION =
<<~GRAPHQL
  mutation($sellingPlanGroup: ID!, $name: String!) {
    sellingPlanGroupUpdate(
      id: $sellingPlanGroup
      input: { name: $name }
    ) {
      sellingPlanGroup {
        id
        name
      }
      userErrors {
        field
        message
      }
    }
  }
GRAPHQL
CREATE_SELLING_PLAN_GROUP_MUTATION =
<<~GRAPHQL
  mutation($name: String!) {
    sellingPlanGroupCreate(
      input: {
        name: $name,
        merchantCode: "subscribe-and-save"
        options: ["Delivery every"]
        position: 1
        sellingPlansToCreate: [
          {
            name: "Delivered every week"
            options: "1 Week(s)"
            position: 1
            billingPolicy: { recurring: { interval: WEEK, intervalCount: 1 } }
            deliveryPolicy: { recurring: { interval: WEEK, intervalCount: 1 } }
            pricingPolicies: [
              {
                fixed: {
                  adjustmentType: PERCENTAGE
                  adjustmentValue: { percentage: 15.0 }
                }
              }
            ]
          }
          {
            name: "Delivered every six weeks"
            options: "6 Week(s)"
            position: 2
            billingPolicy: { recurring: { interval: WEEK, intervalCount: 6 } }
            deliveryPolicy: { recurring: { interval: WEEK, intervalCount: 6 } }
            pricingPolicies: [
              {
                fixed: {
                  adjustmentType: PERCENTAGE
                  adjustmentValue: { percentage: 10.0 }
                }
              }
            ]
          }
          {
            name: "Delivered every three weeks"
            options: "3 Week(s)"
            position: 3
            billingPolicy: { recurring: { interval: WEEK, intervalCount: 3 } }
            deliveryPolicy: { recurring: { interval: WEEK, intervalCount: 3 } }
            pricingPolicies: [
              {
                fixed: {
                  adjustmentType: PERCENTAGE
                  adjustmentValue: { percentage: 5.0 }
                }
              }
            ]
          }
        ]
      }
      resources: { productIds: [], productVariantIds: [] }
    ) {
      sellingPlanGroup {
        id
      }
      userErrors {
        field
        message
      }
    }
  }
GRAPHQL