I am working on implementing tagging on the website, where we require English values for certain fields while the site is in Arabic
. We retrieve items through GraphQL
. For some components, we have employed custom content resolvers, which have effectively handled the task. However, there are certain components that are based on GraphQL
, presenting a challenge.
-
Have you looked into language fallback?– Richard Seal ♦Commented Jan 25 at 14:39
-
Yeah it is useful if the content is not available in Arabic– Muddassir PastaCommented Jan 26 at 7:42
-
Isn't that what you're asking in the post?– Richard Seal ♦Commented Jan 26 at 13:54
Add a comment
|
2 Answers
Could you please maybe try below?
query SignupForm($datasource: String!, $language: String!) {
item(path: $datasource, language: $language) {
name
... on SignUpForm {
tagTemplate {
targetItems {
... on GTMAttributeFolder {
children {
GTMAttributes: results {
... on GTMAttribute {
key {
value(language: "en") # Specify English language for key
}
value {
value
}
}
}
}
}
}
}
}
}
}
That might work and help.
-
-
@MuddassirPasta could you please maybe raise the Sitecore ticket to get the correct query by my understanding you are already in some specific language context when you are working on the children and now there you want to change the language which might be complex to get. Or you can use static props to GrapghQL to get the item details component as that would be faster to work on in this case. Commented Jan 30 at 9:44
-
Hi @nikhil Sure I check with Sitecore support Any How I fetched another Item with hardcoded language that did my job for now. By this I am getting multiple Items now for different level tagging. Commented Jan 30 at 11:31
Please try with search graphql query, it will provide results of the item in all the languages item version available.
Sample Query:
query {
search(
where: {
AND: [
{
name: "_path"
value: "{A25332F7-EB20-4CD3-A27B-C29C1FB9635B}"
operator: CONTAINS
}
]
}
# defaults to 10
first: 10
) {
total
pageInfo {
endCursor
hasNext
}
results {
... data
name: field(name: "title",) {
value
}
}
}
}
fragment data on Item {
language
{
displayName
}
... on OnboardingPage {
title {
value
}
}
url {
path
}
}
Response
{ "data": { "search": { "total": 2, "pageInfo": { "endCursor": "Mg==", "hasNext": false }, "results": [ { "language": { "displayName": "English (Australia) : English (Australia)" }, "title": { "value": "AppUpdate-AU" }, "url": { "path": "/mobilehome/appupdate" }, "name": { "value": "AppUpdate-AU" } }, { "language": { "displayName": "English : English" }, "title": { "value": "AppUpdate-EN" }, "url": { "path": "/mobilehome/appupdate" }, "name": { "value": "AppUpdate-EN" } } ] } } }
-
Thanks for your response. Is there anyway to extend the Item Query with required parameter?? Commented Jan 31 at 12:37
-
@MuddassirPasta are you looking for updating the GraphQL schema itself to support this?, if the above search query not works for you then, cant you try the below item query see if this helps Request: ` query { English:item(language:"en", path:"{A0BFA9A4-AC59-49A5-B169-1964EE39FA64}") { field(name:"Title") { value } } Australia:item(language:"en-AU", path:"{A0BFA9A4-AC59-49A5-B169-1964EE39FA64}") { field(name:"Title") { value } }} Response: { "data": { "English": { "field": { "value": "Home Crawler" } }, "Australia": {"field": { "value": "Aus content" } } }}`– NelsonCommented Feb 1 at 12:15
-
I tested the same It was reverteing the previous item as well on the last language Commented Feb 5 at 10:15