Browse Source

refactor(core): Split common graphql definitions

Michael Bromley 5 năm trước cách đây
mục cha
commit
4d09d95d34

+ 3 - 0
packages/admin-ui/src/lib/core/src/common/introspection-result.ts

@@ -139,6 +139,9 @@ const result: PossibleTypesResultData = {
             'InvalidCredentialsError',
             'OrderStateTransitionError',
             'EmailAddressConflictError',
+            'OrderLimitError',
+            'NegativeQuantityError',
+            'InsufficientStockError',
         ],
         CustomField: [
             'StringCustomFieldConfig',

+ 37 - 0
packages/core/src/api/schema/admin-api/order.api.graphql

@@ -15,6 +15,7 @@ type Mutation {
     transitionOrderToState(id: ID!, state: String!): TransitionOrderToStateResult
     transitionFulfillmentToState(id: ID!, state: String!): TransitionFulfillmentToStateResult!
     setOrderCustomFields(input: UpdateOrderInput!): Order
+    # modifyOrder(input: ModifyOrderInput!): ModifyOrderResult!
 }
 
 type Order {
@@ -72,6 +73,30 @@ input UpdateOrderNoteInput {
     isPublic: Boolean
 }
 
+#input ModifyOrderInput {
+#    id: ID!
+#    addItems: [AddItemInput!]
+#    adjustOrderLines: [OrderLineInput!]
+#    surcharges: [SurchargeInput!]
+#    recalculatePromotions: Boolean!
+#    note: String
+#}
+#
+#input AddItemInput {
+#    productVariantId: ID!
+#    quantity: Int!
+#}
+#
+#input OrderLineInput {
+#    orderLineId: ID!
+#    quantity: Int!
+#}
+#
+#input SurchargeInput {
+#    description: String!
+#    amount: Int!
+#}
+
 "Returned if the Payment settlement fails"
 type SettlePaymentError implements ErrorResult {
     errorCode: ErrorCode!
@@ -188,6 +213,12 @@ type FulfillmentStateTransitionError implements ErrorResult {
     toState: String!
 }
 
+#"Returned when attempting to modify the contents of an Order that is not in the `Modifying` state."
+#type OrderModificationStateError implements ErrorResult {
+#    errorCode: ErrorCode!
+#    message: String!
+#}
+
 union TransitionOrderToStateResult = Order | OrderStateTransitionError
 union SettlePaymentResult =
       Payment
@@ -221,3 +252,9 @@ union RefundOrderResult =
     | RefundStateTransitionError
 union SettleRefundResult = Refund | RefundStateTransitionError
 union TransitionFulfillmentToStateResult = Fulfillment | FulfillmentStateTransitionError
+#union ModifyOrderResult =
+#      Order
+#    | OrderModificationStateError
+#    | OrderLimitError
+#    | NegativeQuantityError
+#    | InsufficientStockError

+ 35 - 0
packages/core/src/api/schema/common/common-enums.graphql

@@ -0,0 +1,35 @@
+enum GlobalFlag {
+    TRUE
+    FALSE
+    INHERIT
+}
+
+enum AdjustmentType {
+    PROMOTION
+}
+
+enum DeletionResult {
+    "The entity was successfully deleted"
+    DELETED
+    "Deletion did not take place, reason given in message"
+    NOT_DELETED
+}
+
+# Populated at run-time
+enum Permission {
+    Placeholder
+}
+
+enum SortOrder {
+    ASC
+    DESC
+}
+
+enum ErrorCode {
+    UNKNOWN_ERROR
+}
+
+enum LogicalOperator {
+    AND
+    OR
+}

+ 48 - 0
packages/core/src/api/schema/common/common-error-results.graphql

@@ -0,0 +1,48 @@
+"Retured when attempting an operation that relies on the NativeAuthStrategy, if that strategy is not configured."
+type NativeAuthStrategyError implements ErrorResult {
+    errorCode: ErrorCode!
+    message: String!
+}
+
+"Returned if the user authentication credentials are not valid"
+type InvalidCredentialsError implements ErrorResult {
+    errorCode: ErrorCode!
+    message: String!
+    authenticationError: String!
+}
+
+"Returned if there is an error in transitioning the Order state"
+type OrderStateTransitionError implements ErrorResult {
+    errorCode: ErrorCode!
+    message: String!
+    transitionError: String!
+    fromState: String!
+    toState: String!
+}
+
+"Retured when attemting to create a Customer with an email address already registered to an existing User."
+type EmailAddressConflictError implements ErrorResult {
+    errorCode: ErrorCode!
+    message: String!
+}
+
+"Retured when the maximum order size limit has been reached."
+type OrderLimitError implements ErrorResult {
+    errorCode: ErrorCode!
+    message: String!
+    maxItems: Int!
+}
+
+"Retured when attemting to set a negative OrderLine quantity."
+type NegativeQuantityError implements ErrorResult {
+    errorCode: ErrorCode!
+    message: String!
+}
+
+"Returned when attempting to add more items to the Order than are available"
+type InsufficientStockError implements ErrorResult {
+    errorCode: ErrorCode!
+    message: String!
+    quantityAvailable: Int!
+    order: Order!
+}

+ 10 - 73
packages/core/src/api/schema/common/common-types.graphql

@@ -3,14 +3,18 @@ scalar JSON
 scalar DateTime
 scalar Upload
 
-enum GlobalFlag {
-    TRUE
-    FALSE
-    INHERIT
+interface PaginatedList {
+    items: [Node!]!
+    totalItems: Int!
 }
 
-enum AdjustmentType {
-    PROMOTION
+interface Node {
+    id: ID!
+}
+
+interface ErrorResult {
+    errorCode: ErrorCode!
+    message: String!
 }
 
 type Adjustment {
@@ -51,17 +55,6 @@ type ConfigurableOperationDefinition {
     description: String!
 }
 
-enum DeletionResult {
-    "The entity was successfully deleted"
-    DELETED
-    "Deletion did not take place, reason given in message"
-    NOT_DELETED
-}
-
-# Populated at run-time
-enum Permission {
-    Placeholder
-}
 
 type DeletionResponse {
     result: DeletionResult!
@@ -78,29 +71,6 @@ input ConfigurableOperationInput {
     arguments: [ConfigArgInput!]!
 }
 
-interface PaginatedList {
-    items: [Node!]!
-    totalItems: Int!
-}
-
-interface Node {
-    id: ID!
-}
-
-enum SortOrder {
-    ASC
-    DESC
-}
-
-enum ErrorCode {
-    UNKNOWN_ERROR
-}
-
-interface ErrorResult {
-    errorCode: ErrorCode!
-    message: String!
-}
-
 input StringOperators {
     eq: String
     contains: String
@@ -138,11 +108,6 @@ input DateOperators {
     between: DateRange
 }
 
-enum LogicalOperator {
-    AND
-    OR
-}
-
 input SearchInput {
     term: String
     facetValueIds: [ID!]
@@ -203,31 +168,3 @@ Indicates that an operation succeeded, where we do not want to return any more s
 type Success {
     success: Boolean!
 }
-
-"Retured when attempting an operation that relies on the NativeAuthStrategy, if that strategy is not configured."
-type NativeAuthStrategyError implements ErrorResult {
-    errorCode: ErrorCode!
-    message: String!
-}
-
-"Returned if the user authentication credentials are not valid"
-type InvalidCredentialsError implements ErrorResult {
-    errorCode: ErrorCode!
-    message: String!
-    authenticationError: String!
-}
-
-"Returned if there is an error in transitioning the Order state"
-type OrderStateTransitionError implements ErrorResult {
-    errorCode: ErrorCode!
-    message: String!
-    transitionError: String!
-    fromState: String!
-    toState: String!
-}
-
-"Retured when attemting to create a Customer with an email address already registered to an existing User."
-type EmailAddressConflictError implements ErrorResult {
-    errorCode: ErrorCode!
-    message: String!
-}

+ 0 - 21
packages/core/src/api/schema/shop-api/shop.api.graphql

@@ -184,27 +184,6 @@ type OrderModificationError implements ErrorResult {
     message: String!
 }
 
-"Retured when the maximum order size limit has been reached."
-type OrderLimitError implements ErrorResult {
-    errorCode: ErrorCode!
-    message: String!
-    maxItems: Int!
-}
-
-"Retured when attemting to set a negative OrderLine quantity."
-type NegativeQuantityError implements ErrorResult {
-    errorCode: ErrorCode!
-    message: String!
-}
-
-"Returned when attempting to add more items to the Order than are available"
-type InsufficientStockError implements ErrorResult {
-    errorCode: ErrorCode!
-    message: String!
-    quantityAvailable: Int!
-    order: Order!
-}
-
 "Returned when attempting to set a ShippingMethod for which the order is not eligible"
 type IneligibleShippingMethodError implements ErrorResult {
     errorCode: ErrorCode!

+ 34 - 1
packages/core/src/common/error/generated-graphql-admin-errors.ts

@@ -296,8 +296,41 @@ export class EmailAddressConflictError extends ErrorResult {
   }
 }
 
+export class OrderLimitError extends ErrorResult {
+  readonly __typename = 'OrderLimitError';
+  readonly errorCode = 'ORDER_LIMIT_ERROR' as any;
+  readonly message = 'ORDER_LIMIT_ERROR';
+  constructor(
+    public maxItems: Scalars['Int'],
+  ) {
+    super();
+  }
+}
+
+export class NegativeQuantityError extends ErrorResult {
+  readonly __typename = 'NegativeQuantityError';
+  readonly errorCode = 'NEGATIVE_QUANTITY_ERROR' as any;
+  readonly message = 'NEGATIVE_QUANTITY_ERROR';
+  constructor(
+  ) {
+    super();
+  }
+}
+
+export class InsufficientStockError extends ErrorResult {
+  readonly __typename = 'InsufficientStockError';
+  readonly errorCode = 'INSUFFICIENT_STOCK_ERROR' as any;
+  readonly message = 'INSUFFICIENT_STOCK_ERROR';
+  constructor(
+    public quantityAvailable: Scalars['Int'],
+    public order: any,
+  ) {
+    super();
+  }
+}
+
 
-const errorTypeNames = new Set(['MimeTypeError', 'LanguageNotAvailableError', 'ChannelDefaultLanguageError', 'SettlePaymentError', 'EmptyOrderLineSelectionError', 'ItemsAlreadyFulfilledError', 'InvalidFulfillmentHandlerError', 'CreateFulfillmentError', 'InsufficientStockOnHandError', 'MultipleOrderError', 'CancelActiveOrderError', 'PaymentOrderMismatchError', 'RefundOrderStateError', 'NothingToRefundError', 'AlreadyRefundedError', 'QuantityTooGreatError', 'RefundStateTransitionError', 'PaymentStateTransitionError', 'FulfillmentStateTransitionError', 'ProductOptionInUseError', 'MissingConditionsError', 'NativeAuthStrategyError', 'InvalidCredentialsError', 'OrderStateTransitionError', 'EmailAddressConflictError']);
+const errorTypeNames = new Set(['MimeTypeError', 'LanguageNotAvailableError', 'ChannelDefaultLanguageError', 'SettlePaymentError', 'EmptyOrderLineSelectionError', 'ItemsAlreadyFulfilledError', 'InvalidFulfillmentHandlerError', 'CreateFulfillmentError', 'InsufficientStockOnHandError', 'MultipleOrderError', 'CancelActiveOrderError', 'PaymentOrderMismatchError', 'RefundOrderStateError', 'NothingToRefundError', 'AlreadyRefundedError', 'QuantityTooGreatError', 'RefundStateTransitionError', 'PaymentStateTransitionError', 'FulfillmentStateTransitionError', 'ProductOptionInUseError', 'MissingConditionsError', 'NativeAuthStrategyError', 'InvalidCredentialsError', 'OrderStateTransitionError', 'EmailAddressConflictError', 'OrderLimitError', 'NegativeQuantityError', 'InsufficientStockError']);
 function isGraphQLError(input: any): input is import('@vendure/common/lib/generated-types').ErrorResult {
   return input instanceof ErrorResult || errorTypeNames.has(input.__typename);
 }

+ 11 - 11
packages/core/src/common/error/generated-graphql-shop-errors.ts

@@ -62,16 +62,6 @@ export class EmailAddressConflictError extends ErrorResult {
   }
 }
 
-export class OrderModificationError extends ErrorResult {
-  readonly __typename = 'OrderModificationError';
-  readonly errorCode = 'ORDER_MODIFICATION_ERROR' as any;
-  readonly message = 'ORDER_MODIFICATION_ERROR';
-  constructor(
-  ) {
-    super();
-  }
-}
-
 export class OrderLimitError extends ErrorResult {
   readonly __typename = 'OrderLimitError';
   readonly errorCode = 'ORDER_LIMIT_ERROR' as any;
@@ -105,6 +95,16 @@ export class InsufficientStockError extends ErrorResult {
   }
 }
 
+export class OrderModificationError extends ErrorResult {
+  readonly __typename = 'OrderModificationError';
+  readonly errorCode = 'ORDER_MODIFICATION_ERROR' as any;
+  readonly message = 'ORDER_MODIFICATION_ERROR';
+  constructor(
+  ) {
+    super();
+  }
+}
+
 export class IneligibleShippingMethodError extends ErrorResult {
   readonly __typename = 'IneligibleShippingMethodError';
   readonly errorCode = 'INELIGIBLE_SHIPPING_METHOD_ERROR' as any;
@@ -282,7 +282,7 @@ export class NotVerifiedError extends ErrorResult {
 }
 
 
-const errorTypeNames = new Set(['NativeAuthStrategyError', 'InvalidCredentialsError', 'OrderStateTransitionError', 'EmailAddressConflictError', 'OrderModificationError', 'OrderLimitError', 'NegativeQuantityError', 'InsufficientStockError', 'IneligibleShippingMethodError', 'OrderPaymentStateError', 'PaymentFailedError', 'PaymentDeclinedError', 'CouponCodeInvalidError', 'CouponCodeExpiredError', 'CouponCodeLimitError', 'AlreadyLoggedInError', 'MissingPasswordError', 'PasswordAlreadySetError', 'VerificationTokenInvalidError', 'VerificationTokenExpiredError', 'IdentifierChangeTokenInvalidError', 'IdentifierChangeTokenExpiredError', 'PasswordResetTokenInvalidError', 'PasswordResetTokenExpiredError', 'NotVerifiedError']);
+const errorTypeNames = new Set(['NativeAuthStrategyError', 'InvalidCredentialsError', 'OrderStateTransitionError', 'EmailAddressConflictError', 'OrderLimitError', 'NegativeQuantityError', 'InsufficientStockError', 'OrderModificationError', 'IneligibleShippingMethodError', 'OrderPaymentStateError', 'PaymentFailedError', 'PaymentDeclinedError', 'CouponCodeInvalidError', 'CouponCodeExpiredError', 'CouponCodeLimitError', 'AlreadyLoggedInError', 'MissingPasswordError', 'PasswordAlreadySetError', 'VerificationTokenInvalidError', 'VerificationTokenExpiredError', 'IdentifierChangeTokenInvalidError', 'IdentifierChangeTokenExpiredError', 'PasswordResetTokenInvalidError', 'PasswordResetTokenExpiredError', 'NotVerifiedError']);
 function isGraphQLError(input: any): input is import('@vendure/common/lib/generated-types').ErrorResult {
   return input instanceof ErrorResult || errorTypeNames.has(input.__typename);
 }