Last active
February 15, 2023 14:36
Revisions
-
paliarush revised this gist
Dec 12, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # [POLL] Custom attributes in Magento GraphQL Schema Magento GraphQL endpoints must support EAV entities such as Products. GraphQL specification requires all complex types eventually to be represented as structures of scalar types. Mixed/any types are not supported. -
paliarush revised this gist
Dec 12, 2017 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Magento GraphQL endpoints must support EAV entities such as Products. GraphQL sp We have couple options to choose from and would be glad to hear your opinion on that. ## Option 1: Custom attributes container *Schema* @@ -105,6 +105,7 @@ items{ *Pros* - Bag of attributes is a good OOP abstraction on the entities dynamically defined in the run-time - Simple way to represent attribute sets *Cons* - Nested structure for custom attributes filters (filter name, condition, value). No auto-complete for attribute names in filter and sorting. @@ -113,7 +114,7 @@ No auto-complete for attribute names in filter and sorting. - It is impossible to see all attributes available on the storefront in GraphQL schema, No auto-completion available in IDEs like Graphiql ## Option 2: Custom attributes in flat structure under the entity object In case when requested custom attributes are not defined for the resulting product, the values of such attributes will be set to null. -
paliarush revised this gist
Dec 12, 2017 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,11 @@ [POLL] Custom attributes in Magento GraphQL Schema Magento GraphQL endpoints must support EAV entities such as Products. GraphQL specification requires all complex types eventually to be represented as structures of scalar types. Mixed/any types are not supported. We have couple options to choose from and would be glad to hear your opinion on that. H1. Option 1: Custom attributes container *Schema* @@ -113,7 +113,8 @@ No auto-complete for attribute names in filter and sorting. - It is impossible to see all attributes available on the storefront in GraphQL schema, No auto-completion available in IDEs like Graphiql H2. Option 2: Custom attributes in flat structure under the entity object In case when requested custom attributes are not defined for the resulting product, the values of such attributes will be set to null. *Schema* -
paliarush revised this gist
Dec 12, 2017 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,9 @@ We have couple options to choose from and would be glad to hear your opinion on *Option 1: Custom attributes container* *Schema* NOTE: Parts of the schema which are identical in both options are omitted. ```graphql interface CustomAttribute { attribute_code: String! @@ -52,6 +54,7 @@ type Product { ``` *Query* ```graphql product(filter: { or: { @@ -114,6 +117,7 @@ No auto-complete for attribute names in filter and sorting. In case when requested custom attributes are not defined for the resulting product, the values of such attributes will be set to null. *Schema* ```graphql type SimpleProduct implements Product { some_custom_attribute: Boolean -
paliarush revised this gist
Dec 12, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ We have couple options to choose from and would be glad to hear your opinion on *Schema* NOTE: Parts of the schema which are identical in both options are omitted. ```graphql interface CustomAttribute { attribute_code: String! } @@ -52,7 +52,7 @@ type Product { ``` *Query* ```graphql product(filter: { or: { sku: {like:"%_2%"} @@ -131,7 +131,7 @@ type MediaAttributeValue { ``` *Query* ```graphql product(filter: { or: { sku: {like:"%_2%"} -
paliarush revised this gist
Dec 12, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ Magento GraphQL endpoints must support EAV entities such as Products. GraphQL sp We have couple options to choose from and would be glad to hear your opinion on that. *Option 1: Custom attributes container* *Schema* @@ -109,12 +109,12 @@ No auto-complete for attribute names in filter and sorting. - Requires special syntax for requesting specific attributes - It is impossible to see all attributes available on the storefront in GraphQL schema, No auto-completion available in IDEs like Graphiql *Option 2: Custom attributes in flat structure under the entity object* In case when requested custom attributes are not defined for the resulting product, the values of such attributes will be set to null. *Schema* ```graphql type SimpleProduct implements Product { some_custom_attribute: Boolean another_custom_attribute: MediaAttributeValue -
paliarush renamed this gist
Dec 12, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
paliarush created this gist
Dec 12, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,170 @@ [POLL] LEVERAGING SERVICE INTERFACES IN DECLARATIVE GRAPHQL SCHEMA Magento GraphQL endpoints must support EAV entities such as Products. GraphQL specification requires all complex types eventually to be represented as structures of scalar types. Mixed/any types are not supported. We have couple options to choose from and would be glad to hear your opinion on that. ============== *Option 1: Custom attributes container* *Schema* NOTE: Parts of the schema which are identical in both options are omitted. ``` interface CustomAttribute { attribute_code: String! } type StringAttribute implements Attribute { attribute_code: String! attribute_value: String! } type IntAttribute implements Attribute { attribute_code: String! attribute_value: Int! } type BooleanAttribute implements Attribute { attribute_code: String! attribute_value: Boolean! } type FloatAttribute implements Attribute { attribute_code: String! attribute_value: Float! } type MediaAttribute implements Attribute { attribute_code: String! attribute_value: MediaAttributeValue! } type MediaAttributeValue { size: String! path: String! } type Product { id: Int sku: String custom_attributes(attribute_code: String!): [CustomAttribute]! } ``` *Query* ``` product(filter: { or: { sku: {like:"%_2%"} or: { custom_attributes: [ { code: “some_custom_attribute”, value: “0”, condition: “eq” } ] } } } pageSize: 1 currentPage:1 ) { items{ id sku custom_attributes(attribute_code: "some_custom_attribute,another_custom_attribute") { attribute_code ... on StringAttribute { atribute_value } ... on FloatAttribute { atribute_value } ... on BooleanAttribute { atribute_value } ... on IntAttribute { atribute_value } ... on MediaAttribute { atribute_value { size path } } } } } ``` *Pros* - Bag of attributes is a good OOP abstraction on the entities dynamically defined in the run-time - Simple way to represent attribute sets *Cons* - Nested structure for custom attributes filters (filter name, condition, value). No auto-complete for attribute names in filter and sorting. - More complicated client code, requires GraphQL fragment declaration for every possible custom attribute value type. - Requires special syntax for requesting specific attributes - It is impossible to see all attributes available on the storefront in GraphQL schema, No auto-completion available in IDEs like Graphiql ===================== *Option 2: Custom attributes in flat structure under the entity object* In case when requested custom attributes are not defined for the resulting product, the values of such attributes will be set to null. *Schema* ``` type SimpleProduct implements Product { some_custom_attribute: Boolean another_custom_attribute: MediaAttributeValue id: Int sku: String … } type MediaAttributeValue { size: String! path: String! } ``` *Query* ``` product(filter: { or: { sku: {like:"%_2%"} or: { some_custom_attribute: {eq: “0”} } } } pageSize: 1 currentPage:1 ) { items{ some_custom_attribute another_custom_attribute { size, path } id sku } } ``` *Pros* - Good semantics for filters - You can see all available attributes in GraphQL schema - Auto-complete works in query, filter and sorting *Cons* - Request must be generated (using Magento client library) - Custom options are still represented as an array. Do we need to request specific custom options or use them in filters? - It is possible to request attributes un-related to the requested product's attribute set. The values will be set to NULL in the response - Schema cache must be invalidated on every change to custom attributes (CRUD on EAV attributes). Minor issue since cache invalidation must be implemented anyway