shop-definitions.ts 18 KB

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