-
Notifications
You must be signed in to change notification settings - Fork 150
GraphQL schema for dynamic blocks #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| type DynamicBlock { | ||
| uid: ID! | ||
| name: String! | ||
| content: String! | ||
| } | ||
|
|
||
| type DynamicBlocks { | ||
| items: [DynamicBlock]! | ||
| page_info: SearchResultPageInfo | ||
| total_count: Int! | ||
| } | ||
|
|
||
| # We don't need is_enabled, locations, ga_creative, catalog_price_rule_ids, cart_price_rules_ids, locations on storefront | ||
|
|
||
| type DynamicBlocksFilterInput { | ||
| type: DynamicBlockTypeEnum! | ||
| locations: [DynamicBlockLocationEnum!] # Blocks for all locations will be displayed if not supplied | ||
| rotation_mode: DynamicBlockRotationModeEnum! | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is I don't think the PWA will know this when it is querying.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This setting allows to request one random dynamic block, multiple dynamic block to display all at once, etc. rotation_mode comes from the data-rotate attribute on the dynamic block node. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, right - ok, thanks! |
||
| dynamic_block_uids: [Int!] # Only makes sense when DynamicBlockTypeEnum is set to SPECIFIED | ||
|
||
| } | ||
|
|
||
| type DynamicBlocksOutput { | ||
| dynamic_blocks: DynamicBlocks! | ||
| } | ||
|
|
||
| enum DynamicBlockTypeEnum { | ||
| SPECIFIED | ||
| CART_PRICE_RULE_RELATED | ||
| CATALOG_PRICE_RULE_RELATED | ||
| } | ||
|
|
||
| enum DynamicBlockLocationEnum { | ||
| CONTENT | ||
| HEADER | ||
| FOOTER | ||
| LEFT | ||
| RIGHT | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the kind of stuff I'd love to get ahead of in the future and design "Venia First". I'm unsure where we'd put a Dynamic Block that specified a LEFT or RIGHT location; it doesn't really fit. No worries for now though.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @supernova-at it really comes to the question: is layout part of graphql or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what "Venia First" means but we need to cover data that might not be part of Venia but needed for other storefronts. Layout is a good example. It's not utilized in Venia (yet) but we use it to enable authors/admins to have multiple layouts. The question I have is, are Location part of the Luma Theme or Core? |
||
|
|
||
| enum DynamicBlockRotationModeEnum { | ||
| NO_ROTATION @doc(description: "Display all.") | ||
| RANDOM | ||
| SERIES | ||
| SHUFFLE | ||
| } | ||
|
|
||
| type Query { | ||
| dynamic_blocks(input: DynamicBlocksFilterInput): DynamicBlocksOutput | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| ## Dynamic Blocks | ||
|
|
||
| Dynamic blocks can be inserted in CMS pages and blocks using widgets. Below is the sample markup of the widget inserted on the page. | ||
|
|
||
| ``` | ||
| {{widget type="Magento\Banner\Block\Widget\Banner" display_mode="fixed" types="content" rotate="random" banner_ids="1" template="widget/block.phtml" unique_id="34f6520f51ca9b79c91d1f56b5b453adc4d9ff235a7c9f5b04d1b0557584c5bc"}} | ||
| ``` | ||
|
|
||
| In Luma dynamic blocks rendered to a JavaScript component definition that does request to a backend to load content of the dynamic block. Here is an example of a JavaScript component definition. | ||
|
|
||
| ``` | ||
| <div class="widget block block-banners" data-bind="scope: 'banner'" data-banner-id="34f6520f51ca9b79c91d1f56b5b453adc4d9ff235a7c9f5b04d1b0557584c5bc" data-types="content" data-display-mode="fixed" data-ids="1" data-rotate="random" data-store-id="1"> | ||
| <ul class="banner-items" data-bind="afterRender: registerBanner"> | ||
| <!-- ko foreach: getItems34f6520f51ca9b79c91d1f56b5b453adc4d9ff235a7c9f5b04d1b0557584c5bc() --> | ||
| <li class="banner-item" data-bind="attr: {'data-banner-id': $data.bannerId}"> | ||
| <div class="banner-item-content" data-bind="bindHtml: $data.html"></div> | ||
| </li> | ||
| <!-- /ko --> | ||
| </ul> | ||
| </div> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does this HTML come from originally? Who / what query sends this to the front end?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This markup is in CMS blocks and pages content. |
||
| ``` | ||
|
|
||
| PWA will receive similar JavaScript component definition that can be parsed to extract parameters and make a [GraphQL query](./dynamic-blocks.graphqls) to load dynamic blocks. | ||
|
|
||
| ```graphql | ||
| { | ||
| dynamic_blocks(input: {type: SPECIFIED, locations: [CONTENT], rotation_mode: RANDOM, dynamic_block_uids: [1, 2]}) { | ||
| items { | ||
| uid | ||
| name | ||
| content | ||
| } | ||
| page_info { | ||
| current_page | ||
| page_size | ||
| total_pages | ||
| } | ||
| total_count | ||
| } | ||
| } | ||
| ``` | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can make it ComplexTextValue, that would allow to return content as a JSON in the future.