Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
GraphQL schema for dynamic blocks
  • Loading branch information
melnikovi committed Oct 8, 2020
commit bb14b030971c998fd8ba94813d8b5f564b86f016
49 changes: 49 additions & 0 deletions design-documents/graph-ql/coverage/dynamic-blocks.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
type DynamicBlock {
uid: ID!
name: String!
content: String!
Copy link
Member Author

@melnikovi melnikovi Oct 8, 2020

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.

}

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!
Copy link

@supernova-at supernova-at Oct 22, 2020

Choose a reason for hiding this comment

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

Why is rotation_mode required?

I don't think the PWA will know this when it is querying.

Copy link
Member Author

@melnikovi melnikovi Oct 22, 2020

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

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

Should dynamic_block_uids be an array of ID types?

type DynamicBlock {
    uid: ID!

}

type DynamicBlocksOutput {
dynamic_blocks: DynamicBlocks!
}

enum DynamicBlockTypeEnum {
SPECIFIED
CART_PRICE_RULE_RELATED
CATALOG_PRICE_RULE_RELATED
}

enum DynamicBlockLocationEnum {
CONTENT
HEADER
FOOTER
LEFT
RIGHT
}

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.
since we have these zone is in Magento, relevant for Luma so far. Does it make sense to keep them for graphql.
Igor said yes, and I also got a request from @fnhipster to bring back the column layout on product interface. We took that one out completely

Copy link

@fnhipster fnhipster Nov 3, 2020

Choose a reason for hiding this comment

The 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
}
41 changes: 41 additions & 0 deletions design-documents/graph-ql/coverage/dynamic-blocks.md
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>

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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
}
}
```