shop-queries.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. shippingAddress {
  53. fullName
  54. company
  55. streetLine1
  56. streetLine2
  57. city
  58. province
  59. postalCode
  60. country
  61. phoneNumber
  62. }
  63. shippingLines {
  64. shippingMethod {
  65. id
  66. code
  67. description
  68. }
  69. }
  70. customer {
  71. id
  72. emailAddress
  73. user {
  74. id
  75. identifier
  76. }
  77. }
  78. history {
  79. items {
  80. id
  81. type
  82. data
  83. }
  84. }
  85. }
  86. `;
  87. export const ADD_PAYMENT = gql`
  88. mutation AddPaymentToOrder($input: PaymentInput!) {
  89. addPaymentToOrder(input: $input) {
  90. ...TestOrderFragment
  91. ... on ErrorResult {
  92. errorCode
  93. message
  94. }
  95. ... on PaymentDeclinedError {
  96. paymentErrorMessage
  97. }
  98. ... on PaymentFailedError {
  99. paymentErrorMessage
  100. }
  101. ... on OrderStateTransitionError {
  102. transitionError
  103. }
  104. ... on IneligiblePaymentMethodError {
  105. eligibilityCheckerMessage
  106. }
  107. }
  108. }
  109. ${TEST_ORDER_FRAGMENT}
  110. `;
  111. export const SET_SHIPPING_ADDRESS = gql`
  112. mutation SetShippingAddress($input: CreateAddressInput!) {
  113. setOrderShippingAddress(input: $input) {
  114. ... on Order {
  115. ...TestOrderFragment
  116. }
  117. ... on ErrorResult {
  118. errorCode
  119. message
  120. }
  121. }
  122. }
  123. ${TEST_ORDER_FRAGMENT}
  124. `;
  125. export const GET_ELIGIBLE_SHIPPING_METHODS = gql`
  126. query GetShippingMethods {
  127. eligibleShippingMethods {
  128. id
  129. code
  130. price
  131. name
  132. description
  133. }
  134. }
  135. `;
  136. export const TRANSITION_TO_STATE = gql`
  137. mutation TransitionToState($state: String!) {
  138. transitionOrderToState(state: $state) {
  139. ... on Order {
  140. id
  141. }
  142. ... on OrderStateTransitionError {
  143. errorCode
  144. message
  145. transitionError
  146. fromState
  147. toState
  148. }
  149. }
  150. }
  151. `;
  152. export const SET_SHIPPING_METHOD = gql`
  153. mutation SetShippingMethod($id: [ID!]!) {
  154. setOrderShippingMethod(shippingMethodId: $id) {
  155. ...TestOrderFragment
  156. ... on ErrorResult {
  157. errorCode
  158. message
  159. }
  160. }
  161. }
  162. ${TEST_ORDER_FRAGMENT}
  163. `;
  164. export const ADD_ITEM_TO_ORDER = gql`
  165. mutation AddItemToOrder($productVariantId: ID!, $quantity: Int!) {
  166. addItemToOrder(productVariantId: $productVariantId, quantity: $quantity) {
  167. ...TestOrderFragment
  168. ... on ErrorResult {
  169. errorCode
  170. message
  171. }
  172. ... on InsufficientStockError {
  173. quantityAvailable
  174. order {
  175. ...TestOrderFragment
  176. }
  177. }
  178. }
  179. }
  180. ${TEST_ORDER_FRAGMENT}
  181. `;
  182. export const ADJUST_ORDER_LINE = gql`
  183. mutation AdjustOrderLine($orderLineId: ID!, $quantity: Int!) {
  184. adjustOrderLine(orderLineId: $orderLineId, quantity: $quantity) {
  185. ...TestOrderFragment
  186. ... on ErrorResult {
  187. errorCode
  188. message
  189. }
  190. ... on InsufficientStockError {
  191. quantityAvailable
  192. order {
  193. ...TestOrderFragment
  194. }
  195. }
  196. ... on OrderInterceptorError {
  197. interceptorError
  198. }
  199. }
  200. }
  201. ${TEST_ORDER_FRAGMENT}
  202. `;
  203. export const GET_ORDER_BY_CODE = gql`
  204. query GetOrderByCode($code: String!) {
  205. orderByCode(code: $code) {
  206. ...TestOrderFragment
  207. }
  208. }
  209. ${TEST_ORDER_FRAGMENT}
  210. `;
  211. export const GET_ACTIVE_ORDER = gql`
  212. query GetActiveOrder {
  213. activeOrder {
  214. ...TestOrderFragment
  215. }
  216. }
  217. ${TEST_ORDER_FRAGMENT}
  218. `;
  219. export const APPLY_COUPON_CODE = gql`
  220. mutation ApplyCouponCode($couponCode: String!) {
  221. applyCouponCode(couponCode: $couponCode) {
  222. ...TestOrderFragment
  223. ... on ErrorResult {
  224. errorCode
  225. message
  226. }
  227. }
  228. }
  229. ${TEST_ORDER_FRAGMENT}
  230. `;