shop-definitions.ts 18 KB

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