GraphQL fragment on a collection? - contentful

I want to make a fragment on a collection, but am unable to do so. Currently I have a collection called, componentCollection, that I would like as a separate fragment.
`
pageCollection {
items {
name
contentCollection {
hero {
... heroFrag
}
cards {
... cardsFrag
}
}
${HERO_FRAG}
${CARD_FRAG}
}
}
`
What I want to do is something like:
`
fragment contentCollectionFragment on ContentCollection {
hero {
... heroFrag
}
cards {
... cardsFrag
}
${HERO_FRAG}
${CARD_FRAG}
}
`
So I can reuse this 'content collection'. But it is saying ContentCollection is not available. I can do this though See below ( I basically have to use page collection. why can't I use the fragment directly on content collection?. Content collection is currently a field on my page that I can reference to various content/blocks I've made):
`
fragment contentCollectionFragment on PageCollection {
items {
contentcollection {
items {
hero {
... heroFrag
}
cards {
... cardsFrag
}
${HERO_FRAG}
${CARD_FRAG}
}
}
}
}
`

Related

how to insert layout macro above thumbnail

I want to insert tiny type above the answer set providing a bit of metadata, but can't figure out how to do it. I just want the layout macro content-answer-set-info to say something like "results in reverse chronological order" in Legal or Detail_S. I want it to appear below altbrains workshop and above the first item in the list.
render {
if (size(this) > 1) {
list-of (this) {
has-details (true)
where-each (item) {
layout-macro (content-thumbnail-card) {
param (content) {
expression (item)
}
}
}
}
}
else-if (size(this) == 1) {
layout-match (this) {
mode (Details)
}
}
else {layout-macro (content-zero-results) {}
}
I would recommend wrapping this layout macro in a section and using the section-title (documentation) key to give it the text above the list.
There is an alternative solution that use section -> title but not with list-of
render {
layout {
section {
title {
template ("Voice command Add One")
}
content {
for-each (this) {
as (item) {
title-card {
title-area {
slot2 {
single-line {
text {
value {
template ("Integer: #{value(item.number)}")
}
style (Detail_L)
}
}
}
}
}
}
}
}
}
}

how to pass along structure property via similar method to Bixby onclick

In a Bixby result-view on the Detail mode I want to provide the user with the option to select from one or more Actions and pass along a hidden parameter "identifier" that corresponds to a database field name to include in the http request made by the Action.
layout {
match: AltBrainsData (this)
mode (Details)
content{
section {
content {
image {
//aspect-ratio (16:9)
url {
template ("#{value(this.icon_image)}")
}
}
}
}
section {
content {
title-area {
slot1 {
text("[#{value(this.name)}]")
{style(Title_M)}
}
}
}
}
section {
content {
paragraph { value ("#{value(this.description)}") style (Detail_L) }
}
}
section {
content {
cell-card {
slot2 {
content {
order (PrimarySecondary)
primary ("Show me the latest news headlines")
}
}
on-click {
intent {
goal: altbrains.persistencetest.GetNews
value: altbrains.persistencetest.AltBrainsData("#{value(this.identifier)}")
}
}
}
}
}
...
I get an error saying that the value must be a primitive.
How can I accomplish this? Basically, I want the result "Detail" card to be populated with one or more possible Actions and each action should pass along this identifier to the corresponding function in code/.
A bit difficult to include all the necessary bits and pieces in Stack Overflow. The money part of the GetNews function is:
function getNews(AltBrainsData) {
const url = properties.get("config", "baseUrl") + "content"
console.log("i got this far and the url is ", url);
const query = {
apikey: properties.get("secret", "apiKey"),
q: "{\"" + "identifier" + "\":\"" + AltBrainsData.identifier + "\"}"
}
Change to the following:
on-click {
intent {
goal: altbrains.persistencetest.GetNews
value: $expr(this)
}
}
You can read more about $expr() syntax in expression language

Can you refresh an input-view?

I am trying to create an input-view that will refresh every few seconds. The goal is to have a few buttons that increment and the user will click on the buttons when the buttons reach a 100. However, it seems like the action is waiting for an input so it is not updating. I found on the documentation that you can refresh an input-view, but I can't find any examples of it.
This is the code that I want to update:
input-view{
match: State(state){
to-input: UpdateGame
}
message{
template ("#{value(state.display)}"){
speech ("#{value(state.say)}")
}
}
refresh{
spec{
delay-seconds (2)
with-request{
intent{
goal: UpdateGame
}
}
}
}
render{
selection-of (state.options){
where-each (option){
cell-card{
slot2{
content{
primary{
template ("#{value(option)}")
}
}
}
}
}
}
}
}
There is one example of result-view in this doc
result-view {
match {
Activity (this)
}
refresh {
if (!exists(this.receipt)) {
spec {
delay-seconds (5)
with-request {
intent {
goal: CheckRideShareStatus
value {$expr(this)}
}
}
}
}
}
conversation-drivers {
if ("this.status == 'Requested' || this.status == 'Confirmed'") {
conversation-driver {
template ("Cancel my Uber ride")
}
}
}
render {
layout-match (this) {
mode (Details)
}
}
}
Sorry I've not caught this question earlier.
I've just verified that this issue is fixed in 20B SDK release.
Please refer the release notes for details about other changes.

Parameter not being passed to layout-macro-def

It seems like a parameter is not being passes to a layout-macro-def, and I can't figure out why.
I've read the documentation for layouts / layout macros.
In my layout, I have something like this:
result-view {
match: dailyDeals (this) {
from-property: inventory (inventory) // the param to pass
}
message {
template ("Wow!") {
speech ("#{value(this)}")
}
}
render {
layout {
section {
....
value ("#{value(inventory.item)}" // e.g., a vbox text value
....
layout-macro (myMacro) {param (inventory)}
}
}
}
}
And I have a layout macro like this:
layout-macro-def (myMacro) {
params {
param (inventory) {
type (inventory)
max (Many)
}
}
content {
....
value ("#{value(inventory.item)}" // e.g., a vbox text value
.....
}
}
I can access inventory values from within the layout just fine (e.g., inventory.item.) However, it seems that inventory isn't being passed (or is empty?) when it gets to the macro, because inventory.item won't show up in the layout from myMacro.
What am I missing?
I think you need to add the expression key to the param.
Try this:
render {
layout {
section {
....
value ("#{value(inventory.item)}" // e.g., a vbox text value
....
layout-macro (myMacro) {param (inventory) {expression (inventory)} }
}
}
}

Relay modern pagination without viewer

Hello i have done my server grapqhl api. Currently i'm stack on relay pagination in client. I searched many articles about that. And everywhere pagination done with viewer root query field. Which about it in docs said that field is unnecassary.
In other resourses:
query routesOrdersQuery {
viewer {
...Order_order
}
}
fragment Order_order on OrderType {
orders() #connection {
edges {
node {
}
}
}
In my case:
query routesOrdersQuery {
...Order_order
}
fragment Order_order on Query {
orders(first: $first) #connection(key: "Order_order") {
edges{
node{
id
}
}
}
}
I solved it. Assumption about spreading fragment in root query is not right.
Problem lays in Route render method.
<Route
render={({error, props}) => {
if(error) {
return <div>{error.message}</div>
} else if(props) {
return <Orders query={props} />
} else {
return <div>Loading...</div>
}
}}
...
/>
So use render instead of component. And it should render 3 different states. Otherwise it not work.

Resources