# An order is a customer's request to purchase one or more products from a shop. You can retrieve and update orders using the Order object.
# Learn more about
# editing an existing order with the GraphQL Admin API.
#
# Only the last 60 days' worth of orders from a store are accessible from the Order object by default. If you want to access older orders,
# then you need to request access to all orders. If your app is granted
# access, then you can add the read_all_orders scope to your app along with read_orders or write_orders.
# Private apps are not affected by this change and are automatically granted the scope.
#
# Caution: Only use this data if it's required for your app's functionality.
# Shopify will restrict access to scopes for apps that don't have a legitimate use for the associated data.
type Order
    implements CommentEventSubject&HasEvents&HasLocalizationExtensions&HasMetafieldDefinitions&HasMetafields&LegacyInteroperability&Node
    @key(fields: "id") {

    # A list of sales agreements associated with the order.
    agreements(
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
        query: String
    ): SalesAgreementConnection!

    # A list of messages that appear on the order page in the Shopify admin.
    alerts: [ResourceAlert!]!

    # The application that created the order.
    app: OrderApp

    # The billing address of the customer.
    billingAddress: MailingAddress

    # Whether the billing address matches the shipping address.
    billingAddressMatchesShippingAddress: Boolean!

    # Whether the order can be manually marked as paid.
    canMarkAsPaid: Boolean!

    # Whether a customer email exists for the order.
    canNotifyCustomer: Boolean!

    # The reason provided when the order was canceled.
    # Returns null if the order wasn't canceled.
    cancelReason: OrderCancelReason

    # The date and time when the order was canceled.
    # Returns null if the order wasn't canceled.
    cancelledAt: DateTime

    # Whether payment for the order can be captured.
    capturable: Boolean!

    # The total order-level discount amount, before returns, in shop and presentment currencies.
    cartDiscountAmountSet: MoneyBag

    # Details about the channel that created the order.
    channelInformation: ChannelInformation

    # The IP address of the API client that created the order.
    clientIp: String

    # Whether the order is closed.
    closed: Boolean!

    # The date and time when the order was closed.
    # Returns null if the order is not closed.
    closedAt: DateTime

    # Whether inventory has been reserved for the order.
    confirmed: Boolean!

    # Date and time when the order was created in Shopify.
    createdAt: DateTime!

    # The shop currency when the order was placed.
    currencyCode: CurrencyCode!

    # The current order-level discount amount after all order updates, in shop and presentment currencies.
    currentCartDiscountAmountSet: MoneyBag!

    # The sum of the quantities for all line items that contribute to the order's current subtotal price.
    currentSubtotalLineItemsQuantity: Int!

    # The sum of the prices for all line items after discounts and returns, in shop and presentment currencies.
    # If taxesIncluded is true, then the subtotal also includes tax.
    currentSubtotalPriceSet: MoneyBag!

    # A list of all tax lines applied to line items on the order, after returns.
    # Tax line prices represent the total price for all tax lines with the same rate and title.
    currentTaxLines: [TaxLine!]!

    # The total amount discounted on the order after returns, in shop and presentment currencies.
    # This includes both order and line level discounts.
    currentTotalDiscountsSet: MoneyBag!

    # The total amount of duties after returns, in shop and presentment currencies.
    # Returns null if duties aren't applicable.
    currentTotalDutiesSet: MoneyBag

    # The total price of the order, after returns, in shop and presentment currencies.
    # This includes taxes and discounts.
    currentTotalPriceSet: MoneyBag!

    # The sum of the prices of all tax lines applied to line items on the order, after returns, in shop and presentment currencies.
    currentTotalTaxSet: MoneyBag!

    # The total weight of the order after returns, in grams.
    currentTotalWeight: UnsignedInt64!

    # A list of the custom attributes added to the order.
    customAttributes: [Attribute!]!

    # The customer that placed the order.
    customer: Customer

    # Whether the customer agreed to receive marketing materials.
    customerAcceptsMarketing: Boolean!

    # The customer's visits and interactions with the online store before placing the order.
    customerJourneySummary: CustomerJourneySummary

    # A two-letter or three-letter language code, optionally followed by a region modifier.
    customerLocale: String

    # A list of discounts that are applied to the order, not including order edits and refunds.
    discountApplications(
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
    ): DiscountApplicationConnection!

    # The discount code used for the order.
    discountCode: String

    # The discount codes used for the order.
    discountCodes: [String!]!

    # The primary address of the customer.
    # Returns null if neither the shipping address nor the billing address was provided.
    displayAddress: MailingAddress

    # The financial status of the order that can be shown to the merchant.
    # This field does not capture all the details of an order's financial state. It should only be used for display summary purposes.
    displayFinancialStatus: OrderDisplayFinancialStatus

    # The fulfillment status for the order that can be shown to the merchant.
    # This field does not capture all the details of an order's fulfillment state. It should only be used for display summary purposes.
    # For a more granular view of the fulfillment status, refer to the FulfillmentOrder object.
    displayFulfillmentStatus: OrderDisplayFulfillmentStatus!

    # A list of the disputes associated with the order.
    disputes: [OrderDisputeSummary!]!

    # Whether the order has had any edits applied.
    edited: Boolean!

    # The email address associated with the customer.
    email: String

    # Whether taxes on the order are estimated.
    # This field returns false when taxes on the order are finalized and aren't subject to any changes.
    estimatedTaxes: Boolean!

    # A list of events associated with the order.
    events(
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
        sortKey: EventSortKeys = ID
        query: String
    ): EventConnection!

    # Whether there are line items that can be fulfilled.
    # This field returns false when the order has no fulfillable line items.
    # For a more granular view of the fulfillment status, refer to the FulfillmentOrder object.
    fulfillable: Boolean!

    # A list of fulfillment orders for the order.
    fulfillmentOrders(
        displayable: Boolean = false
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
        query: String
    ): FulfillmentOrderConnection!

    # List of shipments for the order.
    fulfillments(first: Int): [Fulfillment!]!

    # Whether the order has been paid in full.
    fullyPaid: Boolean!

    # Whether the merchant added a timeline comment to the order.
    hasTimelineComment: Boolean!

    # A globally-unique identifier.
    id: ID!

    # The ID of the corresponding resource in the REST Admin API.
    legacyResourceId: UnsignedInt64!

    # A list of the order's line items.
    lineItems(
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
    ): LineItemConnection!

    # List of localization extensions for the resource.
    localizationExtensions(
        countryCodes: [CountryCode!]
        purposes: [LocalizationExtensionPurpose!]
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
    ): LocalizationExtensionConnection!

    # Whether the order can be edited by the merchant. For example, canceled orders can’t be edited.
    merchantEditable: Boolean!

    # A list of reasons why the order can't be edited. For example, "Canceled orders can’t be edited".
    merchantEditableErrors: [String!]!

    # The application acting as the Merchant of Record for the order.
    merchantOfRecordApp: OrderApp

    # Returns a metafield by namespace and key that belongs to the resource.
    metafield(namespace: String!key: String!): Metafield

    # List of metafield definitions.
    metafieldDefinitions(
        namespace: String
        pinnedStatus: MetafieldDefinitionPinnedStatus = ANY
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
        sortKey: MetafieldDefinitionSortKeys = ID
        query: String
    ): MetafieldDefinitionConnection!

    # List of metafields that belong to the resource.
    metafields(
        namespace: String
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
    ): MetafieldConnection!

    # The unique identifier for the order that appears on the order page in the Shopify admin and the order status page.
    # For example, "#1001", "EN1001", or "1001-A".
    # This value isn't unique across multiple stores.
    name: String!

    # The net payment for the order, based on the total amount received minus the total amount refunded, in shop and presentment currencies.
    netPaymentSet: MoneyBag!

    # A list of line items that can't be fulfilled.
    # For example, tips and fully refunded line items can't be fulfilled.
    # For a more granular view of the fulfillment status, refer to the FulfillmentOrder object.
    nonFulfillableLineItems(
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
    ): LineItemConnection!

    # The contents of the note associated with the order.
    note: String

    # The total amount of duties before returns, in shop and presentment currencies.
    # Returns null if duties aren't applicable.
    originalTotalDutiesSet: MoneyBag

    # The total price of the order at the time of order creation, in shop and presentment currencies.
    originalTotalPriceSet: MoneyBag!

    # The payment collection details for the order.
    paymentCollectionDetails: OrderPaymentCollectionDetails!

    # A list of the names of all payment gateways used for the order.
    # For example, "Shopify Payments" and "Cash on Delivery (COD)".
    paymentGatewayNames: [String!]!

    # The payment terms associated with the order.
    paymentTerms: PaymentTerms

    # The phone number associated with the customer.
    phone: String

    # The fulfillment location that was assigned when the order was created.
    # Use the FulfillmentOrder object for up to date fulfillment location information.
    physicalLocation: Location

    # The payment CurrencyCode of the customer for the order.
    presentmentCurrencyCode: CurrencyCode!

    # Returns a private metafield by namespace and key that belongs to the resource.
    privateMetafield(namespace: String!key: String!): PrivateMetafield

    # List of private metafields that belong to the resource.
    privateMetafields(
        namespace: String
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
    ): PrivateMetafieldConnection!

    # The date and time when the order was processed.
    # This date and time might not match the date and time when the order was created.
    processedAt: DateTime!

    # The publication that the order was created from.
    publication: Publication

    # The purchasing entity for the order.
    purchasingEntity: PurchasingEntity

    # The difference between the suggested and actual refund amount of all refunds that have been applied to the order. A positive value indicates a difference in the merchant's favor, and a negative value indicates a difference in the customer's favor.
    refundDiscrepancySet: MoneyBag!

    # Whether the order can be refunded.
    refundable: Boolean!

    # A list of refunds that have been applied to the order.
    refunds(first: Int): [Refund!]!

    # The URL of the source that the order originated from, if found in the domain registry.
    registeredSourceUrl: URL

    # Whether the order has shipping lines or at least one line item on the order that requires shipping.
    requiresShipping: Boolean!

    # Whether any line item on the order can be restocked.
    restockable: Boolean!

    # The fraud risk level of the order.
    riskLevel: OrderRiskLevel!

    # A list of risks associated with the order.
    risks(first: Int): [OrderRisk!]!

    # The mailing address of the customer.
    shippingAddress: MailingAddress

    # A summary of all shipping costs on the order.
    shippingLine: ShippingLine

    # A list of the order's shipping lines.
    shippingLines(
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
    ): ShippingLineConnection!

    # A unique POS or third party order identifier.
    # For example, "1234-12-1000" or "111-98567-54". The receipt_number field is derived from this value for POS orders.
    sourceIdentifier: String

    # The sum of the quantities for all line items that contribute to the order's subtotal price.
    subtotalLineItemsQuantity: Int!

    # The sum of the prices for all line items after discounts and before returns, in shop and presentment currencies.
    # If taxesIncluded is true, then the subtotal also includes tax.
    subtotalPriceSet: MoneyBag

    # A suggested refund for the order.
    suggestedRefund(
        shippingAmount: Money
        refundShipping: Boolean
        refundLineItems: [RefundLineItemInput!]
        refundDuties: [RefundDutyInput!]
        suggestFullRefund: Boolean = false
    ): SuggestedRefund

    # A comma separated list of tags associated with the order. Updating tags overwrites
    # any existing tags that were previously added to the order. To add new tags without overwriting
    # existing tags, use the tagsAdd mutation.
    tags: [String!]!

    # A list of all tax lines applied to line items on the order, before returns.
    # Tax line prices represent the total price for all tax lines with the same rate and title.
    taxLines: [TaxLine!]!

    # Whether taxes are included in the subtotal price of the order.
    taxesIncluded: Boolean!

    # Whether the order is a test.
    # Test orders are made using the Shopify Bogus Gateway or a payment provider with test mode enabled.
    # A test order cannot be converted into a real order and vice versa.
    test: Boolean!

    # The authorized amount that is uncaptured or undercaptured, in shop and presentment currencies.
    # This amount isn't adjusted for returns.
    totalCapturableSet: MoneyBag!

    # The total amount discounted on the order before returns, in shop and presentment currencies.
    # This includes both order and line level discounts.
    totalDiscountsSet: MoneyBag

    # The total amount not yet transacted for the order, in shop and presentment currencies.
    # A positive value indicates a difference in the merchant's favor (payment from customer to merchant) and a negative value indicates a difference in the customer's favor (refund from merchant to customer).
    totalOutstandingSet: MoneyBag!

    # The total price of the order, before returns, in shop and presentment currencies.
    # This includes taxes and discounts.
    totalPriceSet: MoneyBag!

    # The total amount received from the customer before returns, in shop and presentment currencies.
    totalReceivedSet: MoneyBag!

    # The total amount that was refunded, in shop and presentment currencies.
    totalRefundedSet: MoneyBag!

    # The total amount of shipping that was refunded, in shop and presentment currencies.
    totalRefundedShippingSet: MoneyBag!

    # The total shipping amount before discounts and returns, in shop and presentment currencies.
    totalShippingPriceSet: MoneyBag!

    # The total tax amount before returns, in shop and presentment currencies.
    totalTaxSet: MoneyBag

    # The sum of all tip amounts for the order, in shop and presentment currencies.
    totalTipReceivedSet: MoneyBag!

    # The total weight of the order before returns, in grams.
    totalWeight: UnsignedInt64

    # A list of transactions associated with the order.
    transactions(
        first: Int
        capturable: Boolean
        manuallyResolvable: Boolean
    ): [OrderTransaction!]!

    # Whether no payments have been made for the order.
    unpaid: Boolean!

    # The date and time when the order was modified last.
    updatedAt: DateTime!
}

# An order that a merchant creates on behalf of a customer. Draft orders are useful for merchants that need to do the following tasks:
#
# Create new orders for sales made by phone, in person, by chat, or elsewhere. When a merchant accepts payment for a draft order, an order is created.
# Send invoices to customers to pay with a secure checkout link.
# Use custom items to represent additional costs or products that aren't displayed in a shop's inventory.
# Re-create orders manually from active sales channels.
# Sell products at discount or wholesale rates.
# Take pre-orders.
# Save an order as a draft and resume working on it later.
# For Draft orders in multiple currencies presentment_money is the source of truth for what a customer is going to be charged and shop_money is an estimate of what the merchant might receive in their local currency.
#
# Caution: Only use this data if it's required for your app's functionality. Shopify will restrict access to scopes for apps that don't have a legitimate use for the associated data.
type DraftOrder
    implements CommentEventSubject&HasEvents&HasLocalizationExtensions&HasMetafields&LegacyInteroperability&Navigable&Node
    @key(fields: "id") {

    # The order-level discount applied to the draft order.
    appliedDiscount: DraftOrderAppliedDiscount

    # The billing address of the customer.
    billingAddress: MailingAddress

    # Whether the billing address matches the shipping address.
    billingAddressMatchesShippingAddress: Boolean!

    # The date and time when the draft order converted to a new order,
    # and the draft order's status changed to Completed.
    completedAt: DateTime

    # The date and time when the draft order was created in Shopify.
    createdAt: DateTime!

    # The three letter code for the currency of the store at the time of the most recent update to the draft order.
    currencyCode: CurrencyCode!

    # The custom information added to the draft order on behalf of the customer.
    customAttributes: [Attribute!]!

    # The customer who will be sent an invoice for the draft order, if there is one.
    customer: Customer

    # A default cursor that returns the single next record, sorted ascending by ID.
    defaultCursor: String!

    # The email address of the customer, which is used to send notifications.
    email: String

    # The list of events associated with the draft order.
    events(
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
        sortKey: EventSortKeys = ID
        query: String
    ): EventConnection!

    # Whether the merchant has added timeline comments to the draft order.
    hasTimelineComment: Boolean!

    # A globally-unique identifier.
    id: ID!

    # The subject defined for the draft invoice email template.
    invoiceEmailTemplateSubject: String!

    # The date and time when the invoice was last emailed to the customer.
    invoiceSentAt: DateTime

    # The link to the checkout, which is sent to the customer in the invoice email.
    invoiceUrl: URL

    # The ID of the corresponding resource in the REST Admin API.
    legacyResourceId: UnsignedInt64!

    # The list of the line items in the draft order.
    lineItems(
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
    ): DraftOrderLineItemConnection!

    # The subtotal of the line items and corresponding discounts. The subtotal doesn't include shipping charges, shipping discounts, taxes, or order discounts.
    lineItemsSubtotalPrice: MoneyBag!

    # List of localization extensions for the resource.
    localizationExtensions(
        countryCodes: [CountryCode!]
        purposes: [LocalizationExtensionPurpose!]
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
    ): LocalizationExtensionConnection!

    # The name of the selected market.
    marketName: String!

    # The selected market region country code for the draft order.
    marketRegionCountryCode: CountryCode!

    # Returns a metafield by namespace and key that belongs to the resource.
    metafield(namespace: String!key: String!): Metafield

    # List of metafields that belong to the resource.
    metafields(
        namespace: String
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
    ): MetafieldConnection!

    # The identifier for the draft order, which is unique within the store. For example, #D1223.
    name: String!

    # The text from an optional note attached to the draft order.
    note2: String

    # The order that was created from this draft order.
    order: Order

    # The associated payment terms for this draft order.
    paymentTerms: PaymentTerms

    # The phone number assigned to the draft order.
    phone: String

    # The payment currency of the customer for this draft order.
    presentmentCurrencyCode: CurrencyCode!

    # Returns a private metafield by namespace and key that belongs to the resource.
    privateMetafield(namespace: String!key: String!): PrivateMetafield

    # List of private metafields that belong to the resource.
    privateMetafields(
        namespace: String
        first: Int
        after: String
        last: Int
        before: String
        reverse: Boolean = false
    ): PrivateMetafieldConnection!

    # The purchasing entity for the draft order.
    purchasingEntity: PurchasingEntity

    # Whether the Draft Order is ready and can be completed. Draft Orders
    # might have asynchronous operations that can take time to finish.
    ready: Boolean!

    # The time after which inventory will automatically be restocked.
    reserveInventoryUntil: DateTime

    # The shipping address of the customer.
    shippingAddress: MailingAddress

    # The line item that contains the shipping costs.
    shippingLine: ShippingLine

    # Status of the draft order.
    status: DraftOrderStatus!

    # The subtotal of the line items and their discounts. The subtotal doesn't include shipping charges, shipping discounts, or taxes.
    subtotalPrice: Money!

    # A subtotal of the line items and corresponding discounts. The subtotal doesn't include shipping charges, shipping discounts, or taxes.
    subtotalPriceSet: MoneyBag!

    # A comma separated list of tags associated with the draft order. Updating tags overwrites
    # any existing tags that were previously added to the draft order. To add new tags without overwriting
    # existing tags, use the tagsAdd mutation.
    tags: [String!]!

    # Whether the draft order is tax exempt.
    taxExempt: Boolean!

    # Total amount of taxes charged for each line item and shipping line.
    taxLines: [TaxLine!]!

    # Whether the line item prices include taxes.
    taxesIncluded: Boolean!

    # The total discounts for this draft order.
    totalDiscountsSet: MoneyBag!

    # The total price of line items for this draft order.
    totalLineItemsPriceSet: MoneyBag!

    # The total amount of the draft order, including taxes, shipping charges, and discounts.
    totalPrice: Money!

    # The total amount of the draft order including taxes, shipping charges, and discounts.
    totalPriceSet: MoneyBag!

    # The total shipping charge for the draft order.
    totalShippingPrice: Money!

    # The total shipping charge for the draft order.
    totalShippingPriceSet: MoneyBag!

    # The total amount of taxes for the draft order.
    totalTax: Money!

    # The total amount of taxes for the draft order.
    totalTaxSet: MoneyBag!

    # The total weight in grams of the draft order.
    totalWeight: UnsignedInt64!

    # The date and time when the draft order was last changed.
    # The format is YYYY-MM-DD HH:mm:ss. For example, 2016-02-05 17:04:01.
    updatedAt: DateTime!

    # Whether the draft order will be visible to the customer on the self-serve portal.
    visibleToCustomer: Boolean!
}

extend type App @key(fields: "id") {
    id: ID! @external
}

extend type Market @key(fields: "id") {
    id: ID! @external
}

extend type Customer @key(fields: "id") {
    id: ID! @external
}

extend type FulfillmentService @key(fields: "id") {
    id: ID! @external
}

extend type MarketWebPresence @key(fields: "id") {
    id: ID! @external
}

extend type Product @key(fields: "id") {
   id: ID! @external
}

extend type ProductVariant @key(fields: "id") {
   id: ID! @external
}

extend type InventoryLevel @key(fields: "id") {
    id: ID! @external
}

extend type Collection @key(fields: "id") {
   id: ID! @external
}
