shop-queries.ts 4.5 KB

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