shop-queries.ts 4.7 KB

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