shop-definitions.ts 16 KB

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