shop-queries.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import gql from 'graphql-tag';
  2. export const TEST_ORDER_FRAGMENT = gql`
  3. fragment TestOrderFragment on Order {
  4. id
  5. code
  6. state
  7. active
  8. subTotal
  9. subTotalWithTax
  10. shipping
  11. shippingWithTax
  12. total
  13. totalWithTax
  14. currencyCode
  15. couponCodes
  16. discounts {
  17. adjustmentSource
  18. amount
  19. amountWithTax
  20. description
  21. type
  22. }
  23. payments {
  24. id
  25. transactionId
  26. method
  27. amount
  28. state
  29. metadata
  30. }
  31. lines {
  32. id
  33. quantity
  34. linePrice
  35. linePriceWithTax
  36. unitPrice
  37. unitPriceWithTax
  38. unitPriceChangeSinceAdded
  39. unitPriceWithTaxChangeSinceAdded
  40. proratedUnitPriceWithTax
  41. productVariant {
  42. id
  43. }
  44. discounts {
  45. adjustmentSource
  46. amount
  47. amountWithTax
  48. description
  49. type
  50. }
  51. }
  52. shippingLines {
  53. shippingMethod {
  54. id
  55. code
  56. description
  57. }
  58. }
  59. customer {
  60. id
  61. user {
  62. id
  63. identifier
  64. }
  65. }
  66. history {
  67. items {
  68. id
  69. type
  70. data
  71. }
  72. }
  73. }
  74. `;
  75. export const ADD_PAYMENT = gql`
  76. mutation AddPaymentToOrder($input: PaymentInput!) {
  77. addPaymentToOrder(input: $input) {
  78. ...TestOrderFragment
  79. ... on ErrorResult {
  80. errorCode
  81. message
  82. }
  83. ... on PaymentDeclinedError {
  84. paymentErrorMessage
  85. }
  86. ... on PaymentFailedError {
  87. paymentErrorMessage
  88. }
  89. ... on OrderStateTransitionError {
  90. transitionError
  91. }
  92. ... on IneligiblePaymentMethodError {
  93. eligibilityCheckerMessage
  94. }
  95. }
  96. }
  97. ${TEST_ORDER_FRAGMENT}
  98. `;
  99. export const SET_SHIPPING_ADDRESS = gql`
  100. mutation SetShippingAddress($input: CreateAddressInput!) {
  101. setOrderShippingAddress(input: $input) {
  102. ... on Order {
  103. shippingAddress {
  104. fullName
  105. company
  106. streetLine1
  107. streetLine2
  108. city
  109. province
  110. postalCode
  111. country
  112. phoneNumber
  113. }
  114. }
  115. ... on ErrorResult {
  116. errorCode
  117. message
  118. }
  119. }
  120. }
  121. `;
  122. export const GET_ELIGIBLE_SHIPPING_METHODS = gql`
  123. query GetShippingMethods {
  124. eligibleShippingMethods {
  125. id
  126. code
  127. price
  128. name
  129. description
  130. }
  131. }
  132. `;
  133. export const TRANSITION_TO_STATE = gql`
  134. mutation TransitionToState($state: String!) {
  135. transitionOrderToState(state: $state) {
  136. ... on Order {
  137. id
  138. }
  139. ... on OrderStateTransitionError {
  140. errorCode
  141. message
  142. transitionError
  143. fromState
  144. toState
  145. }
  146. }
  147. }
  148. `;
  149. export const SET_SHIPPING_METHOD = gql`
  150. mutation SetShippingMethod($id: [ID!]!) {
  151. setOrderShippingMethod(shippingMethodId: $id) {
  152. ...TestOrderFragment
  153. ... on ErrorResult {
  154. errorCode
  155. message
  156. }
  157. }
  158. }
  159. ${TEST_ORDER_FRAGMENT}
  160. `;
  161. export const ADD_ITEM_TO_ORDER = gql`
  162. mutation AddItemToOrder($productVariantId: ID!, $quantity: Int!) {
  163. addItemToOrder(productVariantId: $productVariantId, quantity: $quantity) {
  164. ...TestOrderFragment
  165. ... on ErrorResult {
  166. errorCode
  167. message
  168. }
  169. ... on InsufficientStockError {
  170. quantityAvailable
  171. order {
  172. ...TestOrderFragment
  173. }
  174. }
  175. }
  176. }
  177. ${TEST_ORDER_FRAGMENT}
  178. `;
  179. export const GET_ORDER_BY_CODE = gql`
  180. query GetOrderByCode($code: String!) {
  181. orderByCode(code: $code) {
  182. ...TestOrderFragment
  183. }
  184. }
  185. ${TEST_ORDER_FRAGMENT}
  186. `;
  187. export const GET_ACTIVE_ORDER = gql`
  188. query GetActiveOrder {
  189. activeOrder {
  190. ...TestOrderFragment
  191. }
  192. }
  193. ${TEST_ORDER_FRAGMENT}
  194. `;