shop-definitions.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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. total
  9. couponCodes
  10. adjustments {
  11. adjustmentSource
  12. amount
  13. description
  14. type
  15. }
  16. lines {
  17. id
  18. quantity
  19. productVariant {
  20. id
  21. }
  22. adjustments {
  23. adjustmentSource
  24. amount
  25. description
  26. type
  27. }
  28. }
  29. shipping
  30. shippingMethod {
  31. id
  32. code
  33. description
  34. }
  35. customer {
  36. id
  37. user {
  38. id
  39. identifier
  40. }
  41. }
  42. history {
  43. items {
  44. id
  45. type
  46. data
  47. }
  48. }
  49. }
  50. `;
  51. export const UPDATED_ORDER_FRAGMENT = gql`
  52. fragment UpdatedOrder on Order {
  53. id
  54. code
  55. state
  56. active
  57. total
  58. lines {
  59. id
  60. quantity
  61. productVariant {
  62. id
  63. }
  64. adjustments {
  65. adjustmentSource
  66. amount
  67. description
  68. type
  69. }
  70. }
  71. adjustments {
  72. adjustmentSource
  73. amount
  74. description
  75. type
  76. }
  77. }
  78. `;
  79. export const ADD_ITEM_TO_ORDER = gql`
  80. mutation AddItemToOrder($productVariantId: ID!, $quantity: Int!) {
  81. addItemToOrder(productVariantId: $productVariantId, quantity: $quantity) {
  82. ...UpdatedOrder
  83. ... on ErrorResult {
  84. errorCode
  85. message
  86. }
  87. ... on InsufficientStockError {
  88. quantityAvailable
  89. order {
  90. ...UpdatedOrder
  91. }
  92. }
  93. }
  94. }
  95. ${UPDATED_ORDER_FRAGMENT}
  96. `;
  97. export const SEARCH_PRODUCTS_SHOP = gql`
  98. query SearchProductsShop($input: SearchInput!) {
  99. search(input: $input) {
  100. totalItems
  101. items {
  102. productId
  103. productName
  104. productPreview
  105. productVariantId
  106. productVariantName
  107. productVariantPreview
  108. sku
  109. collectionIds
  110. price {
  111. ... on SinglePrice {
  112. value
  113. }
  114. ... on PriceRange {
  115. min
  116. max
  117. }
  118. }
  119. }
  120. }
  121. }
  122. `;
  123. export const REGISTER_ACCOUNT = gql`
  124. mutation Register($input: RegisterCustomerInput!) {
  125. registerCustomerAccount(input: $input) {
  126. ... on Success {
  127. success
  128. }
  129. ... on ErrorResult {
  130. errorCode
  131. message
  132. }
  133. }
  134. }
  135. `;
  136. export const CURRENT_USER_FRAGMENT = gql`
  137. fragment CurrentUserShop on CurrentUser {
  138. id
  139. identifier
  140. channels {
  141. code
  142. token
  143. permissions
  144. }
  145. }
  146. `;
  147. export const VERIFY_EMAIL = gql`
  148. mutation Verify($password: String, $token: String!) {
  149. verifyCustomerAccount(password: $password, token: $token) {
  150. ...CurrentUserShop
  151. ... on ErrorResult {
  152. errorCode
  153. message
  154. }
  155. }
  156. }
  157. ${CURRENT_USER_FRAGMENT}
  158. `;
  159. export const REFRESH_TOKEN = gql`
  160. mutation RefreshToken($emailAddress: String!) {
  161. refreshCustomerVerification(emailAddress: $emailAddress) {
  162. ... on Success {
  163. success
  164. }
  165. ... on ErrorResult {
  166. errorCode
  167. message
  168. }
  169. }
  170. }
  171. `;
  172. export const REQUEST_PASSWORD_RESET = gql`
  173. mutation RequestPasswordReset($identifier: String!) {
  174. requestPasswordReset(emailAddress: $identifier) {
  175. ... on Success {
  176. success
  177. }
  178. ... on ErrorResult {
  179. errorCode
  180. message
  181. }
  182. }
  183. }
  184. `;
  185. export const RESET_PASSWORD = gql`
  186. mutation ResetPassword($token: String!, $password: String!) {
  187. resetPassword(token: $token, password: $password) {
  188. ...CurrentUserShop
  189. ... on ErrorResult {
  190. errorCode
  191. message
  192. }
  193. }
  194. }
  195. ${CURRENT_USER_FRAGMENT}
  196. `;
  197. export const REQUEST_UPDATE_EMAIL_ADDRESS = gql`
  198. mutation RequestUpdateEmailAddress($password: String!, $newEmailAddress: String!) {
  199. requestUpdateCustomerEmailAddress(password: $password, newEmailAddress: $newEmailAddress) {
  200. ... on Success {
  201. success
  202. }
  203. ... on ErrorResult {
  204. errorCode
  205. message
  206. }
  207. }
  208. }
  209. `;
  210. export const UPDATE_EMAIL_ADDRESS = gql`
  211. mutation UpdateEmailAddress($token: String!) {
  212. updateCustomerEmailAddress(token: $token) {
  213. ... on Success {
  214. success
  215. }
  216. ... on ErrorResult {
  217. errorCode
  218. message
  219. }
  220. }
  221. }
  222. `;
  223. export const GET_ACTIVE_CUSTOMER = gql`
  224. query GetActiveCustomer {
  225. activeCustomer {
  226. id
  227. emailAddress
  228. }
  229. }
  230. `;
  231. export const CREATE_ADDRESS = gql`
  232. mutation CreateAddressShop($input: CreateAddressInput!) {
  233. createCustomerAddress(input: $input) {
  234. id
  235. streetLine1
  236. country {
  237. code
  238. }
  239. }
  240. }
  241. `;
  242. export const UPDATE_ADDRESS = gql`
  243. mutation UpdateAddressShop($input: UpdateAddressInput!) {
  244. updateCustomerAddress(input: $input) {
  245. streetLine1
  246. country {
  247. code
  248. }
  249. }
  250. }
  251. `;
  252. export const DELETE_ADDRESS = gql`
  253. mutation DeleteAddressShop($id: ID!) {
  254. deleteCustomerAddress(id: $id) {
  255. success
  256. }
  257. }
  258. `;
  259. export const UPDATE_CUSTOMER = gql`
  260. mutation UpdateCustomer($input: UpdateCustomerInput!) {
  261. updateCustomer(input: $input) {
  262. id
  263. firstName
  264. lastName
  265. }
  266. }
  267. `;
  268. export const UPDATE_PASSWORD = gql`
  269. mutation UpdatePassword($old: String!, $new: String!) {
  270. updateCustomerPassword(currentPassword: $old, newPassword: $new) {
  271. ... on Success {
  272. success
  273. }
  274. ... on ErrorResult {
  275. errorCode
  276. message
  277. }
  278. }
  279. }
  280. `;
  281. export const GET_ACTIVE_ORDER = gql`
  282. query GetActiveOrder {
  283. activeOrder {
  284. ...TestOrderFragment
  285. }
  286. }
  287. ${TEST_ORDER_FRAGMENT}
  288. `;
  289. export const GET_ACTIVE_ORDER_WITH_PRICE_DATA = gql`
  290. query GetActiveOrderWithPriceData {
  291. activeOrder {
  292. id
  293. subTotalBeforeTax
  294. subTotal
  295. totalBeforeTax
  296. total
  297. lines {
  298. id
  299. unitPrice
  300. unitPriceWithTax
  301. taxRate
  302. linePrice
  303. lineTax
  304. linePriceWithTax
  305. items {
  306. id
  307. unitPrice
  308. unitPriceWithTax
  309. taxRate
  310. }
  311. adjustments {
  312. amount
  313. type
  314. }
  315. }
  316. taxSummary {
  317. taxRate
  318. taxBase
  319. taxTotal
  320. }
  321. }
  322. }
  323. `;
  324. export const ADJUST_ITEM_QUANTITY = gql`
  325. mutation AdjustItemQuantity($orderLineId: ID!, $quantity: Int!) {
  326. adjustOrderLine(orderLineId: $orderLineId, quantity: $quantity) {
  327. ...TestOrderFragment
  328. ... on ErrorResult {
  329. errorCode
  330. message
  331. }
  332. }
  333. }
  334. ${TEST_ORDER_FRAGMENT}
  335. `;
  336. export const REMOVE_ITEM_FROM_ORDER = gql`
  337. mutation RemoveItemFromOrder($orderLineId: ID!) {
  338. removeOrderLine(orderLineId: $orderLineId) {
  339. ...TestOrderFragment
  340. ... on ErrorResult {
  341. errorCode
  342. message
  343. }
  344. }
  345. }
  346. ${TEST_ORDER_FRAGMENT}
  347. `;
  348. export const GET_ELIGIBLE_SHIPPING_METHODS = gql`
  349. query GetShippingMethods {
  350. eligibleShippingMethods {
  351. id
  352. price
  353. description
  354. }
  355. }
  356. `;
  357. export const SET_SHIPPING_METHOD = gql`
  358. mutation SetShippingMethod($id: ID!) {
  359. setOrderShippingMethod(shippingMethodId: $id) {
  360. ...TestOrderFragment
  361. ... on ErrorResult {
  362. errorCode
  363. message
  364. }
  365. }
  366. }
  367. ${TEST_ORDER_FRAGMENT}
  368. `;
  369. export const ACTIVE_ORDER_CUSTOMER = gql`
  370. fragment ActiveOrderCustomer on Order {
  371. id
  372. customer {
  373. id
  374. emailAddress
  375. firstName
  376. lastName
  377. }
  378. lines {
  379. id
  380. }
  381. }
  382. `;
  383. export const SET_CUSTOMER = gql`
  384. mutation SetCustomerForOrder($input: CreateCustomerInput!) {
  385. setCustomerForOrder(input: $input) {
  386. ...ActiveOrderCustomer
  387. ... on ErrorResult {
  388. errorCode
  389. message
  390. }
  391. }
  392. }
  393. ${ACTIVE_ORDER_CUSTOMER}
  394. `;
  395. export const GET_ORDER_BY_CODE = gql`
  396. query GetOrderByCode($code: String!) {
  397. orderByCode(code: $code) {
  398. ...TestOrderFragment
  399. }
  400. }
  401. ${TEST_ORDER_FRAGMENT}
  402. `;
  403. export const GET_ORDER_PROMOTIONS_BY_CODE = gql`
  404. query GetOrderPromotionsByCode($code: String!) {
  405. orderByCode(code: $code) {
  406. ...TestOrderFragment
  407. promotions {
  408. id
  409. name
  410. }
  411. }
  412. }
  413. ${TEST_ORDER_FRAGMENT}
  414. `;
  415. export const GET_AVAILABLE_COUNTRIES = gql`
  416. query GetAvailableCountries {
  417. availableCountries {
  418. id
  419. code
  420. }
  421. }
  422. `;
  423. export const TRANSITION_TO_STATE = gql`
  424. mutation TransitionToState($state: String!) {
  425. transitionOrderToState(state: $state) {
  426. ...TestOrderFragment
  427. ... on OrderStateTransitionError {
  428. errorCode
  429. message
  430. transitionError
  431. fromState
  432. toState
  433. }
  434. }
  435. }
  436. ${TEST_ORDER_FRAGMENT}
  437. `;
  438. export const SET_SHIPPING_ADDRESS = gql`
  439. mutation SetShippingAddress($input: CreateAddressInput!) {
  440. setOrderShippingAddress(input: $input) {
  441. shippingAddress {
  442. fullName
  443. company
  444. streetLine1
  445. streetLine2
  446. city
  447. province
  448. postalCode
  449. country
  450. phoneNumber
  451. }
  452. }
  453. }
  454. `;
  455. export const SET_BILLING_ADDRESS = gql`
  456. mutation SetBillingAddress($input: CreateAddressInput!) {
  457. setOrderBillingAddress(input: $input) {
  458. billingAddress {
  459. fullName
  460. company
  461. streetLine1
  462. streetLine2
  463. city
  464. province
  465. postalCode
  466. country
  467. phoneNumber
  468. }
  469. }
  470. }
  471. `;
  472. export const TEST_ORDER_WITH_PAYMENTS_FRAGMENT = gql`
  473. fragment TestOrderWithPayments on Order {
  474. ...TestOrderFragment
  475. payments {
  476. id
  477. transactionId
  478. method
  479. amount
  480. state
  481. metadata
  482. }
  483. }
  484. ${TEST_ORDER_FRAGMENT}
  485. `;
  486. export const GET_ACTIVE_ORDER_WITH_PAYMENTS = gql`
  487. query GetActiveOrderWithPayments {
  488. activeOrder {
  489. ...TestOrderWithPayments
  490. }
  491. }
  492. ${TEST_ORDER_WITH_PAYMENTS_FRAGMENT}
  493. `;
  494. export const ADD_PAYMENT = gql`
  495. mutation AddPaymentToOrder($input: PaymentInput!) {
  496. addPaymentToOrder(input: $input) {
  497. ...TestOrderWithPayments
  498. ... on ErrorResult {
  499. errorCode
  500. message
  501. }
  502. ... on PaymentDeclinedError {
  503. paymentErrorMessage
  504. }
  505. ... on PaymentFailedError {
  506. paymentErrorMessage
  507. }
  508. ... on OrderStateTransitionError {
  509. transitionError
  510. }
  511. }
  512. }
  513. ${TEST_ORDER_WITH_PAYMENTS_FRAGMENT}
  514. `;
  515. export const GET_ACTIVE_ORDER_PAYMENTS = gql`
  516. query GetActiveOrderPayments {
  517. activeOrder {
  518. id
  519. payments {
  520. id
  521. transactionId
  522. method
  523. amount
  524. state
  525. errorMessage
  526. metadata
  527. }
  528. }
  529. }
  530. `;
  531. export const GET_ORDER_BY_CODE_WITH_PAYMENTS = gql`
  532. query GetOrderByCodeWithPayments($code: String!) {
  533. orderByCode(code: $code) {
  534. ...TestOrderWithPayments
  535. }
  536. }
  537. ${TEST_ORDER_WITH_PAYMENTS_FRAGMENT}
  538. `;
  539. export const GET_NEXT_STATES = gql`
  540. query GetNextOrderStates {
  541. nextOrderStates
  542. }
  543. `;
  544. export const GET_ACTIVE_ORDER_ADDRESSES = gql`
  545. query GetCustomerAddresses {
  546. activeOrder {
  547. customer {
  548. addresses {
  549. id
  550. streetLine1
  551. }
  552. }
  553. }
  554. }
  555. `;
  556. export const GET_ACTIVE_ORDER_ORDERS = gql`
  557. query GetCustomerOrders {
  558. activeOrder {
  559. customer {
  560. orders {
  561. items {
  562. id
  563. }
  564. }
  565. }
  566. }
  567. }
  568. `;
  569. export const APPLY_COUPON_CODE = gql`
  570. mutation ApplyCouponCode($couponCode: String!) {
  571. applyCouponCode(couponCode: $couponCode) {
  572. ...TestOrderFragment
  573. ... on ErrorResult {
  574. errorCode
  575. message
  576. }
  577. }
  578. }
  579. ${TEST_ORDER_FRAGMENT}
  580. `;
  581. export const REMOVE_COUPON_CODE = gql`
  582. mutation RemoveCouponCode($couponCode: String!) {
  583. removeCouponCode(couponCode: $couponCode) {
  584. ...TestOrderFragment
  585. }
  586. }
  587. ${TEST_ORDER_FRAGMENT}
  588. `;
  589. export const REMOVE_ALL_ORDER_LINES = gql`
  590. mutation RemoveAllOrderLines {
  591. removeAllOrderLines {
  592. ...TestOrderFragment
  593. ... on ErrorResult {
  594. errorCode
  595. message
  596. }
  597. }
  598. }
  599. ${TEST_ORDER_FRAGMENT}
  600. `;