shop-definitions.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  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. lines {
  24. id
  25. quantity
  26. linePrice
  27. linePriceWithTax
  28. unitPrice
  29. unitPriceWithTax
  30. unitPriceChangeSinceAdded
  31. unitPriceWithTaxChangeSinceAdded
  32. discountedUnitPriceWithTax
  33. proratedUnitPriceWithTax
  34. productVariant {
  35. id
  36. }
  37. discounts {
  38. adjustmentSource
  39. amount
  40. amountWithTax
  41. description
  42. type
  43. }
  44. }
  45. shippingLines {
  46. priceWithTax
  47. shippingMethod {
  48. id
  49. code
  50. description
  51. }
  52. }
  53. customer {
  54. id
  55. user {
  56. id
  57. identifier
  58. }
  59. }
  60. history {
  61. items {
  62. id
  63. type
  64. data
  65. }
  66. }
  67. }
  68. `;
  69. export const UPDATED_ORDER_FRAGMENT = gql`
  70. fragment UpdatedOrder on Order {
  71. id
  72. code
  73. state
  74. active
  75. total
  76. totalWithTax
  77. currencyCode
  78. lines {
  79. id
  80. quantity
  81. productVariant {
  82. id
  83. }
  84. unitPrice
  85. unitPriceWithTax
  86. linePrice
  87. linePriceWithTax
  88. featuredAsset {
  89. id
  90. }
  91. discounts {
  92. adjustmentSource
  93. amount
  94. amountWithTax
  95. description
  96. type
  97. }
  98. }
  99. discounts {
  100. adjustmentSource
  101. amount
  102. amountWithTax
  103. description
  104. type
  105. }
  106. }
  107. `;
  108. export const ADD_ITEM_TO_ORDER = gql`
  109. mutation AddItemToOrder($productVariantId: ID!, $quantity: Int!) {
  110. addItemToOrder(productVariantId: $productVariantId, quantity: $quantity) {
  111. ...UpdatedOrder
  112. ... on ErrorResult {
  113. errorCode
  114. message
  115. }
  116. ... on InsufficientStockError {
  117. quantityAvailable
  118. order {
  119. ...UpdatedOrder
  120. }
  121. }
  122. ... on OrderInterceptorError {
  123. interceptorError
  124. }
  125. }
  126. }
  127. ${UPDATED_ORDER_FRAGMENT}
  128. `;
  129. export const SEARCH_PRODUCTS_SHOP = gql`
  130. query SearchProductsShop($input: SearchInput!) {
  131. search(input: $input) {
  132. totalItems
  133. items {
  134. productId
  135. productName
  136. productVariantId
  137. productVariantName
  138. sku
  139. collectionIds
  140. price {
  141. ... on SinglePrice {
  142. value
  143. }
  144. ... on PriceRange {
  145. min
  146. max
  147. }
  148. }
  149. }
  150. }
  151. }
  152. `;
  153. export const REGISTER_ACCOUNT = gql`
  154. mutation Register($input: RegisterCustomerInput!) {
  155. registerCustomerAccount(input: $input) {
  156. ... on Success {
  157. success
  158. }
  159. ... on ErrorResult {
  160. errorCode
  161. message
  162. }
  163. ... on PasswordValidationError {
  164. validationErrorMessage
  165. }
  166. }
  167. }
  168. `;
  169. export const CURRENT_USER_FRAGMENT = gql`
  170. fragment CurrentUserShop on CurrentUser {
  171. id
  172. identifier
  173. channels {
  174. code
  175. token
  176. permissions
  177. }
  178. }
  179. `;
  180. export const VERIFY_EMAIL = gql`
  181. mutation Verify($password: String, $token: String!) {
  182. verifyCustomerAccount(password: $password, token: $token) {
  183. ...CurrentUserShop
  184. ... on ErrorResult {
  185. errorCode
  186. message
  187. }
  188. ... on PasswordValidationError {
  189. validationErrorMessage
  190. }
  191. }
  192. }
  193. ${CURRENT_USER_FRAGMENT}
  194. `;
  195. export const REFRESH_TOKEN = gql`
  196. mutation RefreshToken($emailAddress: String!) {
  197. refreshCustomerVerification(emailAddress: $emailAddress) {
  198. ... on Success {
  199. success
  200. }
  201. ... on ErrorResult {
  202. errorCode
  203. message
  204. }
  205. }
  206. }
  207. `;
  208. export const REQUEST_PASSWORD_RESET = gql`
  209. mutation RequestPasswordReset($identifier: String!) {
  210. requestPasswordReset(emailAddress: $identifier) {
  211. ... on Success {
  212. success
  213. }
  214. ... on ErrorResult {
  215. errorCode
  216. message
  217. }
  218. }
  219. }
  220. `;
  221. export const RESET_PASSWORD = gql`
  222. mutation ResetPassword($token: String!, $password: String!) {
  223. resetPassword(token: $token, password: $password) {
  224. ...CurrentUserShop
  225. ... on ErrorResult {
  226. errorCode
  227. message
  228. }
  229. ... on PasswordValidationError {
  230. validationErrorMessage
  231. }
  232. }
  233. }
  234. ${CURRENT_USER_FRAGMENT}
  235. `;
  236. export const REQUEST_UPDATE_EMAIL_ADDRESS = gql`
  237. mutation RequestUpdateEmailAddress($password: String!, $newEmailAddress: String!) {
  238. requestUpdateCustomerEmailAddress(password: $password, newEmailAddress: $newEmailAddress) {
  239. ... on Success {
  240. success
  241. }
  242. ... on ErrorResult {
  243. errorCode
  244. message
  245. }
  246. }
  247. }
  248. `;
  249. export const UPDATE_EMAIL_ADDRESS = gql`
  250. mutation UpdateEmailAddress($token: String!) {
  251. updateCustomerEmailAddress(token: $token) {
  252. ... on Success {
  253. success
  254. }
  255. ... on ErrorResult {
  256. errorCode
  257. message
  258. }
  259. }
  260. }
  261. `;
  262. export const GET_ACTIVE_CUSTOMER = gql`
  263. query GetActiveCustomer {
  264. activeCustomer {
  265. id
  266. emailAddress
  267. }
  268. }
  269. `;
  270. export const CREATE_ADDRESS = gql`
  271. mutation CreateAddressShop($input: CreateAddressInput!) {
  272. createCustomerAddress(input: $input) {
  273. id
  274. streetLine1
  275. country {
  276. code
  277. }
  278. }
  279. }
  280. `;
  281. export const UPDATE_ADDRESS = gql`
  282. mutation UpdateAddressShop($input: UpdateAddressInput!) {
  283. updateCustomerAddress(input: $input) {
  284. streetLine1
  285. country {
  286. code
  287. }
  288. }
  289. }
  290. `;
  291. export const DELETE_ADDRESS = gql`
  292. mutation DeleteAddressShop($id: ID!) {
  293. deleteCustomerAddress(id: $id) {
  294. success
  295. }
  296. }
  297. `;
  298. export const UPDATE_CUSTOMER = gql`
  299. mutation UpdateCustomer($input: UpdateCustomerInput!) {
  300. updateCustomer(input: $input) {
  301. id
  302. firstName
  303. lastName
  304. }
  305. }
  306. `;
  307. export const UPDATE_PASSWORD = gql`
  308. mutation UpdatePassword($old: String!, $new: String!) {
  309. updateCustomerPassword(currentPassword: $old, newPassword: $new) {
  310. ... on Success {
  311. success
  312. }
  313. ... on ErrorResult {
  314. errorCode
  315. message
  316. }
  317. }
  318. }
  319. `;
  320. export const GET_ACTIVE_ORDER = gql`
  321. query GetActiveOrder {
  322. activeOrder {
  323. ...TestOrderFragment
  324. }
  325. }
  326. ${TEST_ORDER_FRAGMENT}
  327. `;
  328. export const GET_ACTIVE_ORDER_WITH_PRICE_DATA = gql`
  329. query GetActiveOrderWithPriceData {
  330. activeOrder {
  331. id
  332. subTotal
  333. subTotalWithTax
  334. total
  335. totalWithTax
  336. total
  337. lines {
  338. id
  339. unitPrice
  340. unitPriceWithTax
  341. taxRate
  342. linePrice
  343. lineTax
  344. linePriceWithTax
  345. taxLines {
  346. taxRate
  347. description
  348. }
  349. }
  350. taxSummary {
  351. description
  352. taxRate
  353. taxBase
  354. taxTotal
  355. }
  356. }
  357. }
  358. `;
  359. export const ADJUST_ITEM_QUANTITY = gql`
  360. mutation AdjustItemQuantity($orderLineId: ID!, $quantity: Int!) {
  361. adjustOrderLine(orderLineId: $orderLineId, quantity: $quantity) {
  362. ...TestOrderFragment
  363. ... on ErrorResult {
  364. errorCode
  365. message
  366. }
  367. ... on OrderInterceptorError {
  368. interceptorError
  369. }
  370. }
  371. }
  372. ${TEST_ORDER_FRAGMENT}
  373. `;
  374. export const REMOVE_ITEM_FROM_ORDER = gql`
  375. mutation RemoveItemFromOrder($orderLineId: ID!) {
  376. removeOrderLine(orderLineId: $orderLineId) {
  377. ...TestOrderFragment
  378. ... on ErrorResult {
  379. errorCode
  380. message
  381. }
  382. ... on OrderInterceptorError {
  383. interceptorError
  384. }
  385. }
  386. }
  387. ${TEST_ORDER_FRAGMENT}
  388. `;
  389. export const GET_ELIGIBLE_SHIPPING_METHODS = gql`
  390. query GetShippingMethods {
  391. eligibleShippingMethods {
  392. id
  393. code
  394. price
  395. name
  396. description
  397. }
  398. }
  399. `;
  400. export const SET_SHIPPING_METHOD = gql`
  401. mutation SetShippingMethod($id: [ID!]!) {
  402. setOrderShippingMethod(shippingMethodId: $id) {
  403. ...TestOrderFragment
  404. ... on ErrorResult {
  405. errorCode
  406. message
  407. }
  408. }
  409. }
  410. ${TEST_ORDER_FRAGMENT}
  411. `;
  412. export const ACTIVE_ORDER_CUSTOMER = gql`
  413. fragment ActiveOrderCustomer on Order {
  414. id
  415. customer {
  416. id
  417. emailAddress
  418. firstName
  419. lastName
  420. }
  421. lines {
  422. id
  423. }
  424. }
  425. `;
  426. export const SET_CUSTOMER = gql`
  427. mutation SetCustomerForOrder($input: CreateCustomerInput!) {
  428. setCustomerForOrder(input: $input) {
  429. ...ActiveOrderCustomer
  430. ... on ErrorResult {
  431. errorCode
  432. message
  433. }
  434. ... on GuestCheckoutError {
  435. errorDetail
  436. }
  437. }
  438. }
  439. ${ACTIVE_ORDER_CUSTOMER}
  440. `;
  441. export const GET_ORDER_BY_CODE = gql`
  442. query GetOrderByCode($code: String!) {
  443. orderByCode(code: $code) {
  444. ...TestOrderFragment
  445. }
  446. }
  447. ${TEST_ORDER_FRAGMENT}
  448. `;
  449. export const GET_ORDER_SHOP = gql`
  450. query GetOrderShop($id: ID!) {
  451. order(id: $id) {
  452. ...TestOrderFragment
  453. }
  454. }
  455. ${TEST_ORDER_FRAGMENT}
  456. `;
  457. export const GET_ORDER_PROMOTIONS_BY_CODE = gql`
  458. query GetOrderPromotionsByCode($code: String!) {
  459. orderByCode(code: $code) {
  460. ...TestOrderFragment
  461. promotions {
  462. id
  463. name
  464. }
  465. }
  466. }
  467. ${TEST_ORDER_FRAGMENT}
  468. `;
  469. export const GET_AVAILABLE_COUNTRIES = gql`
  470. query GetAvailableCountries {
  471. availableCountries {
  472. id
  473. code
  474. }
  475. }
  476. `;
  477. export const TRANSITION_TO_STATE = gql`
  478. mutation TransitionToState($state: String!) {
  479. transitionOrderToState(state: $state) {
  480. ...TestOrderFragment
  481. ... on OrderStateTransitionError {
  482. errorCode
  483. message
  484. transitionError
  485. fromState
  486. toState
  487. }
  488. }
  489. }
  490. ${TEST_ORDER_FRAGMENT}
  491. `;
  492. export const ORDER_WITH_ADDRESSES_FRAGMENT = gql`
  493. fragment OrderWithAddresses on Order {
  494. lines {
  495. id
  496. }
  497. shippingAddress {
  498. fullName
  499. company
  500. streetLine1
  501. streetLine2
  502. city
  503. province
  504. postalCode
  505. country
  506. phoneNumber
  507. }
  508. billingAddress {
  509. fullName
  510. company
  511. streetLine1
  512. streetLine2
  513. city
  514. province
  515. postalCode
  516. country
  517. phoneNumber
  518. }
  519. }
  520. `;
  521. export const SET_SHIPPING_ADDRESS = gql`
  522. mutation SetShippingAddress($input: CreateAddressInput!) {
  523. setOrderShippingAddress(input: $input) {
  524. ...OrderWithAddresses
  525. ... on ErrorResult {
  526. errorCode
  527. message
  528. }
  529. }
  530. }
  531. ${ORDER_WITH_ADDRESSES_FRAGMENT}
  532. `;
  533. export const SET_BILLING_ADDRESS = gql`
  534. mutation SetBillingAddress($input: CreateAddressInput!) {
  535. setOrderBillingAddress(input: $input) {
  536. ...OrderWithAddresses
  537. ... on ErrorResult {
  538. errorCode
  539. message
  540. }
  541. }
  542. }
  543. ${ORDER_WITH_ADDRESSES_FRAGMENT}
  544. `;
  545. export const UNSET_SHIPPING_ADDRESS = gql`
  546. mutation UnsetShippingAddress {
  547. unsetOrderShippingAddress {
  548. ...OrderWithAddresses
  549. ... on ErrorResult {
  550. errorCode
  551. message
  552. }
  553. }
  554. }
  555. ${ORDER_WITH_ADDRESSES_FRAGMENT}
  556. `;
  557. export const UNSET_BILLING_ADDRESS = gql`
  558. mutation UnsetBillingAddress {
  559. unsetOrderBillingAddress {
  560. ...OrderWithAddresses
  561. ... on ErrorResult {
  562. errorCode
  563. message
  564. }
  565. }
  566. }
  567. ${ORDER_WITH_ADDRESSES_FRAGMENT}
  568. `;
  569. export const TEST_ORDER_WITH_PAYMENTS_FRAGMENT = gql`
  570. fragment TestOrderWithPayments on Order {
  571. ...TestOrderFragment
  572. payments {
  573. id
  574. transactionId
  575. method
  576. amount
  577. state
  578. metadata
  579. }
  580. }
  581. ${TEST_ORDER_FRAGMENT}
  582. `;
  583. export const GET_ACTIVE_ORDER_WITH_PAYMENTS = gql`
  584. query GetActiveOrderWithPayments {
  585. activeOrder {
  586. ...TestOrderWithPayments
  587. }
  588. }
  589. ${TEST_ORDER_WITH_PAYMENTS_FRAGMENT}
  590. `;
  591. export const ADD_PAYMENT = gql`
  592. mutation AddPaymentToOrder($input: PaymentInput!) {
  593. addPaymentToOrder(input: $input) {
  594. ...TestOrderWithPayments
  595. ... on ErrorResult {
  596. errorCode
  597. message
  598. }
  599. ... on PaymentDeclinedError {
  600. paymentErrorMessage
  601. }
  602. ... on PaymentFailedError {
  603. paymentErrorMessage
  604. }
  605. ... on OrderStateTransitionError {
  606. transitionError
  607. }
  608. ... on IneligiblePaymentMethodError {
  609. eligibilityCheckerMessage
  610. }
  611. }
  612. }
  613. ${TEST_ORDER_WITH_PAYMENTS_FRAGMENT}
  614. `;
  615. export const GET_ACTIVE_ORDER_PAYMENTS = gql`
  616. query GetActiveOrderPayments {
  617. activeOrder {
  618. id
  619. payments {
  620. id
  621. transactionId
  622. method
  623. amount
  624. state
  625. errorMessage
  626. metadata
  627. }
  628. }
  629. }
  630. `;
  631. export const GET_ORDER_BY_CODE_WITH_PAYMENTS = gql`
  632. query GetOrderByCodeWithPayments($code: String!) {
  633. orderByCode(code: $code) {
  634. ...TestOrderWithPayments
  635. }
  636. }
  637. ${TEST_ORDER_WITH_PAYMENTS_FRAGMENT}
  638. `;
  639. export const GET_ACTIVE_ORDER_CUSTOMER_WITH_ITEM_FULFILLMENTS = gql`
  640. query GetActiveCustomerOrderWithItemFulfillments {
  641. activeCustomer {
  642. orders(
  643. options: { skip: 0, take: 5, sort: { createdAt: DESC }, filter: { active: { eq: false } } }
  644. ) {
  645. totalItems
  646. items {
  647. id
  648. code
  649. state
  650. lines {
  651. id
  652. }
  653. fulfillments {
  654. id
  655. state
  656. method
  657. trackingCode
  658. }
  659. }
  660. }
  661. }
  662. }
  663. `;
  664. export const GET_NEXT_STATES = gql`
  665. query GetNextOrderStates {
  666. nextOrderStates
  667. }
  668. `;
  669. export const GET_ACTIVE_ORDER_ADDRESSES = gql`
  670. query GetCustomerAddresses {
  671. activeOrder {
  672. customer {
  673. addresses {
  674. id
  675. streetLine1
  676. }
  677. }
  678. }
  679. }
  680. `;
  681. export const GET_ACTIVE_ORDER_ORDERS = gql`
  682. query GetCustomerOrders {
  683. activeOrder {
  684. customer {
  685. orders {
  686. items {
  687. id
  688. }
  689. }
  690. }
  691. }
  692. }
  693. `;
  694. export const GET_ACTIVE_CUSTOMER_ORDERS = gql`
  695. query GetActiveCustomerOrders {
  696. activeCustomer {
  697. id
  698. orders {
  699. totalItems
  700. items {
  701. id
  702. state
  703. }
  704. }
  705. }
  706. }
  707. `;
  708. export const APPLY_COUPON_CODE = gql`
  709. mutation ApplyCouponCode($couponCode: String!) {
  710. applyCouponCode(couponCode: $couponCode) {
  711. ...TestOrderFragment
  712. ... on ErrorResult {
  713. errorCode
  714. message
  715. }
  716. }
  717. }
  718. ${TEST_ORDER_FRAGMENT}
  719. `;
  720. export const REMOVE_COUPON_CODE = gql`
  721. mutation RemoveCouponCode($couponCode: String!) {
  722. removeCouponCode(couponCode: $couponCode) {
  723. ...TestOrderFragment
  724. }
  725. }
  726. ${TEST_ORDER_FRAGMENT}
  727. `;
  728. export const REMOVE_ALL_ORDER_LINES = gql`
  729. mutation RemoveAllOrderLines {
  730. removeAllOrderLines {
  731. ...TestOrderFragment
  732. ... on ErrorResult {
  733. errorCode
  734. message
  735. }
  736. }
  737. }
  738. ${TEST_ORDER_FRAGMENT}
  739. `;
  740. export const GET_ELIGIBLE_PAYMENT_METHODS = gql`
  741. query GetEligiblePaymentMethods {
  742. eligiblePaymentMethods {
  743. id
  744. code
  745. eligibilityMessage
  746. isEligible
  747. }
  748. }
  749. `;
  750. export const GET_PRODUCT_WITH_STOCK_LEVEL = gql`
  751. query GetProductStockLevel($id: ID!) {
  752. product(id: $id) {
  753. id
  754. variants {
  755. id
  756. stockLevel
  757. }
  758. }
  759. }
  760. `;
  761. export const GET_ACTIVE_CUSTOMER_WITH_ORDERS_PRODUCT_SLUG = gql`
  762. query GetActiveCustomerWithOrdersProductSlug($options: OrderListOptions) {
  763. activeCustomer {
  764. orders(options: $options) {
  765. items {
  766. lines {
  767. productVariant {
  768. product {
  769. slug
  770. }
  771. }
  772. }
  773. }
  774. }
  775. }
  776. }
  777. `;
  778. export const GET_ACTIVE_CUSTOMER_WITH_ORDERS_PRODUCT_PRICE = gql`
  779. query GetActiveCustomerWithOrdersProductPrice($options: OrderListOptions) {
  780. activeCustomer {
  781. orders(options: $options) {
  782. items {
  783. lines {
  784. linePrice
  785. productVariant {
  786. id
  787. name
  788. price
  789. }
  790. }
  791. }
  792. }
  793. }
  794. }
  795. `;