Skip to content
Open
Prev Previous commit
Next Next commit
- reactor types
  • Loading branch information
cpartica committed Mar 5, 2021
commit c2d29e24a73154229a93fbdf627fe219a2df8f8c
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
type Query {
customAttributeMetadataV2(attributes: [AttributeMetadataInput!]!): CustomAttributeMetadata
customAttributesLists(listType: CustomAttributesListsEnum): CustomAttributeMetadata
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customAttributesLists - do we need a better name for this

}

type AttributeMetadataInput {
attribute_uid: ID
}

type CustomAttributeMetadata {
type CustomAttributeMetadata { # this replaces existing Attribute type
items: [AttributeMetadataInterface]
}

# base metadata common to all attributes
interface AttributeMetadataInterface {
interface AttributeMetadataInterface { # base metadata common to all attributes
uid: ID # base64Encode(entityID/codeID)
label: String
data_type: ObjectDataTypeEnum # string, int, float, boolean etc
Expand All @@ -23,8 +27,8 @@ interface AttributeMetadataUiTypeInterface {
}

type CustomerAttributeMetadata implements AttributeMetadataInterface, AttributeMetadataEntityTypeInterface, AttributeMetadataUiTypeInterface {
# ui_input_type: UiInputTypeInterface!
# entity_type: EntityTypeEnum
# ui_input_type: UiInputTypeInterface! #imported
# entity_type: EntityTypeEnum #imported
forms_to_use_in: [CustomAttributesListsEnum]
}

Expand Down Expand Up @@ -106,13 +110,13 @@ type MultipleSelectInputType implements UiInputTypeInterface, AttributeOptionsIn
}

type VisualSwatchInputType implements UiInputTypeInterface, AttributeOptionsInterface {
default_option: [ID]
default_options: [ID]
update_product_preview_image: Boolean
use_product_image_for_swatch_if_possible: Boolean
use_product_image: Boolean # use product image for swatch if possible
}

type TextSwatchInputType implements UiInputTypeInterface, AttributeOptionsInterface {
default_option: [ID]
default_options: [ID]
update_product_preview_image: Boolean
}

Expand All @@ -123,11 +127,6 @@ type AttributeOption implements AttributeOptionInterface {
label: String
}

# extended type of an option as it would look like for visual swatches
#type AttributeOptionSwatch implements AttributeOptionInterface {
# swatch: SwatchOptionInterface
#}

type ColorSwatchAttributeOption implements AttributeOptionInterface {
color: String # html hex code format
label: String
Expand All @@ -143,8 +142,6 @@ type TextSwatchAttributeOption implements AttributeOptionInterface {
description: String
}

# end of swatches variation

#enums to support above queries
enum ObjectDataTypeEnum {
STRING
Expand Down Expand Up @@ -207,12 +204,6 @@ enum CustomerAttributeFormsEnum {
ADMINHTML_CHECKOUT
}

type Query {
customAttributesLists(
list_type: CustomAttributesListsEnum
): CustomAttributeMetadata
}

enum CustomAttributesListsEnum {
PRODUCTS_COMPARE
PRODUCTS_LISTING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Added schema:

```graphql
Query.customAttributesMetadataV2(
attributes: [AttributeInput!]!
attributes: [AttributeMetadataInput!]!
): CustomAttributeMetadata

#adding to existing type a choice of uid or code and
Expand Down Expand Up @@ -114,10 +114,15 @@ type MultipleSelectInputType implements UiInputTypeInterface, AttributeOptionsIn
default_options: [ID]
}

type SwatchInputType implements UiInputTypeInterface, AttributeOptionsInterface {
type VisualSwatchInputType implements UiInputTypeInterface, AttributeOptionsInterface {
default_options: [ID]
update_product_preview_image: Boolean
use_product_image: Boolean
}

type TextSwatchInputType implements UiInputTypeInterface, AttributeOptionsInterface {
default_options: [ID]
update_product_preview_image: Boolean
use_product_image_for_swatch_if_possible: Boolean
}

#other types for other entities here
Expand All @@ -134,23 +139,17 @@ type AttributeOption implements AttributeOptionInterface {
label: String
}

# extended type of an option as it would look like for visual swatches
type AttributeOptionSwatch implements AttributeOptionInterface {
swatch: SwatchOptionInterface
}

interface SwatchOptionInterface {
}

type SwatchOptionColor implements SwatchOptionInterface {
type ColorSwatchAttributeOption implements AttributeOptionInterface {
color: String # html hex code format
label: String
}

type SwatchOptionImage implements SwatchOptionInterface {
type ImageSwatchAttributeOption implements AttributeOptionInterface {
image_path: String # relative path
label: String
}

type SwatchOptionText implements SwatchOptionInterface {
type TextSwatchAttributeOption implements AttributeOptionInterface {
title: String
description: String
}
Expand All @@ -160,20 +159,26 @@ Additional fields should be added to the metadata response (`Attribute` type),

Introduction of the following query will allow fetching lists of attributes applicable to specific artifacts/listings:
```graphql
customAttributesListings(
listing_type: CustomAttributesListingsEnum
customAttributesLists(
listType: CustomAttributesListingsEnum
): CustomAttributeMetadata

enum CustomAttributesListingsEnum {
PRODUCTS_COMPARE
PRODUCTS_LISTING
ADVANCED_CATALOG_SEARCH
PRODUCT_SORT
PRODUCT_FILTER
PRODUCT_SEARCH_RESULTS
PRODUCT_AGGREGATIONS
RMA_FORM
CUSTOMER_REGISTRATION_FORM
CUSTOMER_ADDRESS_FORM
}
```

See full schema [attributes-metadata.graphqls](attributes-metadata.graphqls)

# Alternative solutions

GraphQL schema supports [directives](https://graphql.github.io/graphql-spec/June2018/#sec-Language.Directives) which can be used to describe additional information for types, fields, fragments and operations. Since all EAV attributes are automatically added to GraphQL schema in flat structure as fields of the respective types, it is possible to use directives to expose necessary attribute metadata for the client application.
Expand Down