shop-definitions.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  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. lines {
  23. id
  24. quantity
  25. linePrice
  26. linePriceWithTax
  27. unitPrice
  28. unitPriceWithTax
  29. unitPriceChangeSinceAdded
  30. unitPriceWithTaxChangeSinceAdded
  31. proratedUnitPriceWithTax
  32. productVariant {
  33. id
  34. }
  35. discounts {
  36. adjustmentSource
  37. amount
  38. amountWithTax
  39. description
  40. type
  41. }
  42. items {
  43. id
  44. unitPrice
  45. unitPriceWithTax
  46. }
  47. }
  48. shippingLines {
  49. shippingMethod {
  50. id
  51. code
  52. description
  53. }
  54. }
  55. customer {
  56. id
  57. user {
  58. id
  59. identifier
  60. }
  61. }
  62. history {
  63. items {
  64. id
  65. type
  66. data
  67. }
  68. }
  69. }
  70. `;
  71. export const UPDATED_ORDER_FRAGMENT = gql`
  72. fragment UpdatedOrder on Order {
  73. id
  74. code
  75. state
  76. active
  77. total
  78. totalWithTax
  79. lines {
  80. id
  81. quantity
  82. productVariant {
  83. id
  84. }
  85. discounts {
  86. adjustmentSource
  87. amount
  88. amountWithTax
  89. description
  90. type
  91. }
  92. }
  93. discounts {
  94. adjustmentSource
  95. amount
  96. amountWithTax
  97. description
  98. type
  99. }
  100. }
  101. `;
  102. export const ADD_ITEM_TO_ORDER = gql`
  103. mutation AddItemToOrder($productVariantId: ID!, $quantity: Int!) {
  104. addItemToOrder(productVariantId: $productVariantId, quantity: $quantity) {
  105. ...UpdatedOrder
  106. ... on ErrorResult {
  107. errorCode
  108. message
  109. }
  110. ... on InsufficientStockError {
  111. quantityAvailable
  112. order {
  113. ...UpdatedOrder
  114. }
  115. }
  116. }
  117. }
  118. ${UPDATED_ORDER_FRAGMENT}
  119. `;
  120. export const SEARCH_PRODUCTS_SHOP = gql`
  121. query SearchProductsShop($input: SearchInput!) {
  122. search(input: $input) {
  123. totalItems
  124. items {
  125. productId
  126. productName
  127. productVariantId
  128. productVariantName
  129. sku
  130. collectionIds
  131. price {
  132. ... on SinglePrice {
  133. value
  134. }
  135. ... on PriceRange {
  136. min
  137. max
  138. }
  139. }
  140. }
  141. }
  142. }
  143. `;
  144. export const REGISTER_ACCOUNT = gql`
  145. mutation Register($input: RegisterCustomerInput!) {
  146. registerCustomerAccount(input: $input) {
  147. ... on Success {
  148. success
  149. }
  150. ... on ErrorResult {
  151. errorCode
  152. message
  153. }
  154. ... on PasswordValidationError {
  155. validationErrorMessage
  156. }
  157. }
  158. }
  159. `;
  160. export const CURRENT_USER_FRAGMENT = gql`
  161. fragment CurrentUserShop on CurrentUser {
  162. id
  163. identifier
  164. channels {
  165. code
  166. token
  167. permissions
  168. }
  169. }
  170. `;
  171. export const VERIFY_EMAIL = gql`
  172. mutation Verify($password: String, $token: String!) {
  173. verifyCustomerAccount(password: $password, token: $token) {
  174. ...CurrentUserShop
  175. ... on ErrorResult {
  176. errorCode
  177. message
  178. }
  179. ... on PasswordValidationError {
  180. validationErrorMessage
  181. }
  182. }
  183. }
  184. ${CURRENT_USER_FRAGMENT}
  185. `;
  186. export const REFRESH_TOKEN = gql`
  187. mutation RefreshToken($emailAddress: String!) {
  188. refreshCustomerVerification(emailAddress: $emailAddress) {
  189. ... on Success {
  190. success
  191. }
  192. ... on ErrorResult {
  193. errorCode
  194. message
  195. }
  196. }
  197. }
  198. `;
  199. export const REQUEST_PASSWORD_RESET = gql`
  200. mutation RequestPasswordReset($identifier: String!) {
  201. requestPasswordReset(emailAddress: $identifier) {
  202. ... on Success {
  203. success
  204. }
  205. ... on ErrorResult {
  206. errorCode
  207. message
  208. }
  209. }
  210. }
  211. `;
  212. export const RESET_PASSWORD = gql`
  213. mutation ResetPassword($token: String!, $password: String!) {
  214. resetPassword(token: $token, password: $password) {
  215. ...CurrentUserShop
  216. ... on ErrorResult {
  217. errorCode
  218. message
  219. }
  220. ... on PasswordValidationError {
  221. validationErrorMessage
  222. }
  223. }
  224. }
  225. ${CURRENT_USER_FRAGMENT}
  226. `;
  227. export const REQUEST_UPDATE_EMAIL_ADDRESS = gql`
  228. mutation RequestUpdateEmailAddress($password: String!, $newEmailAddress: String!) {
  229. requestUpdateCustomerEmailAddress(password: $password, newEmailAddress: $newEmailAddress) {
  230. ... on Success {
  231. success
  232. }
  233. ... on ErrorResult {
  234. errorCode
  235. message
  236. }
  237. }
  238. }
  239. `;
  240. export const UPDATE_EMAIL_ADDRESS = gql`
  241. mutation UpdateEmailAddress($token: String!) {
  242. updateCustomerEmailAddress(token: $token) {
  243. ... on Success {
  244. success
  245. }
  246. ... on ErrorResult {
  247. errorCode
  248. message
  249. }
  250. }
  251. }
  252. `;
  253. export const GET_ACTIVE_CUSTOMER = gql`
  254. query GetActiveCustomer {
  255. activeCustomer {
  256. id
  257. emailAddress
  258. }
  259. }
  260. `;
  261. export const CREATE_ADDRESS = gql`
  262. mutation CreateAddressShop($input: CreateAddressInput!) {
  263. createCustomerAddress(input: $input) {
  264. id
  265. streetLine1
  266. country {
  267. code
  268. }
  269. }
  270. }
  271. `;
  272. export const UPDATE_ADDRESS = gql`
  273. mutation UpdateAddressShop($input: UpdateAddressInput!) {
  274. updateCustomerAddress(input: $input) {
  275. streetLine1
  276. country {
  277. code
  278. }
  279. }
  280. }
  281. `;
  282. export const DELETE_ADDRESS = gql`
  283. mutation DeleteAddressShop($id: ID!) {
  284. deleteCustomerAddress(id: $id) {
  285. success
  286. }
  287. }
  288. `;
  289. export const UPDATE_CUSTOMER = gql`
  290. mutation UpdateCustomer($input: UpdateCustomerInput!) {
  291. updateCustomer(input: $input) {
  292. id
  293. firstName
  294. lastName
  295. }
  296. }
  297. `;
  298. export const UPDATE_PASSWORD = gql`
  299. mutation UpdatePassword($old: String!, $new: String!) {
  300. updateCustomerPassword(currentPassword: $old, newPassword: $new) {
  301. ... on Success {
  302. success
  303. }
  304. ... on ErrorResult {
  305. errorCode
  306. message
  307. }
  308. }
  309. }
  310. `;
  311. export const GET_ACTIVE_ORDER = gql`
  312. query GetActiveOrder {
  313. activeOrder {
  314. ...TestOrderFragment
  315. }
  316. }
  317. ${TEST_ORDER_FRAGMENT}
  318. `;
  319. export const GET_ACTIVE_ORDER_WITH_PRICE_DATA = gql`
  320. query GetActiveOrderWithPriceData {
  321. activeOrder {
  322. id
  323. subTotal
  324. subTotalWithTax
  325. total
  326. totalWithTax
  327. total
  328. lines {
  329. id
  330. unitPrice
  331. unitPriceWithTax
  332. taxRate
  333. linePrice
  334. lineTax
  335. linePriceWithTax
  336. items {
  337. id
  338. unitPrice
  339. unitPriceWithTax
  340. taxRate
  341. }
  342. taxLines {
  343. taxRate
  344. description
  345. }
  346. }
  347. taxSummary {
  348. description
  349. taxRate
  350. taxBase
  351. taxTotal
  352. }
  353. }
  354. }
  355. `;
  356. export const ADJUST_ITEM_QUANTITY = gql`
  357. mutation AdjustItemQuantity($orderLineId: ID!, $quantity: Int!) {
  358. adjustOrderLine(orderLineId: $orderLineId, quantity: $quantity) {
  359. ...TestOrderFragment
  360. ... on ErrorResult {
  361. errorCode
  362. message
  363. }
  364. }
  365. }
  366. ${TEST_ORDER_FRAGMENT}
  367. `;
  368. export const REMOVE_ITEM_FROM_ORDER = gql`
  369. mutation RemoveItemFromOrder($orderLineId: ID!) {
  370. removeOrderLine(orderLineId: $orderLineId) {
  371. ...TestOrderFragment
  372. ... on ErrorResult {
  373. errorCode
  374. message
  375. }
  376. }
  377. }
  378. ${TEST_ORDER_FRAGMENT}
  379. `;
  380. export const GET_ELIGIBLE_SHIPPING_METHODS = gql`
  381. query GetShippingMethods {
  382. eligibleShippingMethods {
  383. id
  384. code
  385. price
  386. name
  387. description
  388. }
  389. }
  390. `;
  391. export const SET_SHIPPING_METHOD = gql`
  392. mutation SetShippingMethod($id: ID!) {
  393. setOrderShippingMethod(shippingMethodId: $id) {
  394. ...TestOrderFragment
  395. ... on ErrorResult {
  396. errorCode
  397. message
  398. }
  399. }
  400. }
  401. ${TEST_ORDER_FRAGMENT}
  402. `;
  403. export const ACTIVE_ORDER_CUSTOMER = gql`
  404. fragment ActiveOrderCustomer on Order {
  405. id
  406. customer {
  407. id
  408. emailAddress
  409. firstName
  410. lastName
  411. }
  412. lines {
  413. id
  414. }
  415. }
  416. `;
  417. export const SET_CUSTOMER = gql`
  418. mutation SetCustomerForOrder($input: CreateCustomerInput!) {
  419. setCustomerForOrder(input: $input) {
  420. ...ActiveOrderCustomer
  421. ... on ErrorResult {
  422. errorCode
  423. message
  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. items {
  610. id
  611. fulfillment {
  612. id
  613. state
  614. method
  615. trackingCode
  616. }
  617. }
  618. }
  619. }
  620. }
  621. }
  622. }
  623. `;
  624. export const GET_NEXT_STATES = gql`
  625. query GetNextOrderStates {
  626. nextOrderStates
  627. }
  628. `;
  629. export const GET_ACTIVE_ORDER_ADDRESSES = gql`
  630. query GetCustomerAddresses {
  631. activeOrder {
  632. customer {
  633. addresses {
  634. id
  635. streetLine1
  636. }
  637. }
  638. }
  639. }
  640. `;
  641. export const GET_ACTIVE_ORDER_ORDERS = gql`
  642. query GetCustomerOrders {
  643. activeOrder {
  644. customer {
  645. orders {
  646. items {
  647. id
  648. }
  649. }
  650. }
  651. }
  652. }
  653. `;
  654. export const GET_ACTIVE_CUSTOMER_ORDERS = gql`
  655. query GetActiveCustomerOrders {
  656. activeCustomer {
  657. id
  658. orders {
  659. totalItems
  660. items {
  661. id
  662. state
  663. }
  664. }
  665. }
  666. }
  667. `;
  668. export const APPLY_COUPON_CODE = gql`
  669. mutation ApplyCouponCode($couponCode: String!) {
  670. applyCouponCode(couponCode: $couponCode) {
  671. ...TestOrderFragment
  672. ... on ErrorResult {
  673. errorCode
  674. message
  675. }
  676. }
  677. }
  678. ${TEST_ORDER_FRAGMENT}
  679. `;
  680. export const REMOVE_COUPON_CODE = gql`
  681. mutation RemoveCouponCode($couponCode: String!) {
  682. removeCouponCode(couponCode: $couponCode) {
  683. ...TestOrderFragment
  684. }
  685. }
  686. ${TEST_ORDER_FRAGMENT}
  687. `;
  688. export const REMOVE_ALL_ORDER_LINES = gql`
  689. mutation RemoveAllOrderLines {
  690. removeAllOrderLines {
  691. ...TestOrderFragment
  692. ... on ErrorResult {
  693. errorCode
  694. message
  695. }
  696. }
  697. }
  698. ${TEST_ORDER_FRAGMENT}
  699. `;
  700. export const GET_ELIGIBLE_PAYMENT_METHODS = gql`
  701. query GetEligiblePaymentMethods {
  702. eligiblePaymentMethods {
  703. id
  704. code
  705. eligibilityMessage
  706. isEligible
  707. }
  708. }
  709. `;
  710. export const GET_PRODUCT_WITH_STOCK_LEVEL = gql`
  711. query GetProductStockLevel($id: ID!) {
  712. product(id: $id) {
  713. id
  714. variants {
  715. id
  716. stockLevel
  717. }
  718. }
  719. }
  720. `;
  721. export const GET_ACTIVE_CUSTOMER_WITH_ORDERS_PRODUCT_SLUG = gql`
  722. query GetActiveCustomerWithOrdersProductSlug($options: OrderListOptions) {
  723. activeCustomer {
  724. orders(options: $options) {
  725. items {
  726. lines {
  727. productVariant {
  728. product {
  729. slug
  730. }
  731. }
  732. }
  733. }
  734. }
  735. }
  736. }
  737. `;
  738. export const GET_ACTIVE_CUSTOMER_WITH_ORDERS_PRODUCT_PRICE = gql`
  739. query GetActiveCustomerWithOrdersProductPrice($options: OrderListOptions) {
  740. activeCustomer {
  741. orders(options: $options) {
  742. items {
  743. lines {
  744. linePrice
  745. productVariant {
  746. id
  747. name
  748. price
  749. }
  750. }
  751. }
  752. }
  753. }
  754. }
  755. `;