How do I add a Root Node - graphql

Adding a nested item is easy: the config is just a RANGE_ADD
query {
viewer {
item {
edges {
node {
subitem {
edges {
node {
id,
title
}
}
}
}
}
}
}
}
Adding a subitem will just require a RANGE_ADD with the parentId equal to the id of item.
However, how do I add an item which doesn't have a parent? I tried using a RANGE_ADD config without a parentId but it didn't work.
I feel like this is such a simple thing, but I can't seem to find it in the docs.

item does have a parent, which is viewer. It's just that viewer can have one item instead of multiple items as item is not a connection type. So when you want to add another item, you want to either:
1) replace / update the existing item. FIELDS_CHANGE is usually used in this case.
OR
2) fetch an item which does not need to be put in the client store. In this case, you can use REQUIRED_CHILDREN mutator configuration. Check an excellent example of how to use it in an answer to another related question.

Related

How do I query a GitHub Project Item title from GraphQL?

I'm attempting to use the GitHub ProjectV2 API to query a GitHub Projects beta project to obtain the title or a given GitHub Project Item.
Unfortunately, I'm not well-versed in GraphQL and struggling to complete the query. What am I missing from the following GraphQL query to get this to work?
query {
node(id: \"PROJECT_NODE_ID\") {
... on ProjectV2 {
items(id:\"PROJECT_ITEM_ID\")
}
}
content{
... on DraftIssue {
title
}
}
}
As written, this returns the following error:
Field must have selections (field 'items' returns ProjectV2ItemConnection but has no selections. Did you mean 'items { ... }'?)"}
You're almost there, but there are two issues here:
items returns a Connection, which means you still need to include another set of curly braces to "select" which fields you'd like.
The GitHub ProjectsV2 API doesn't look like it supports selection of individual items yet, only paginating through a list of items. This means that what you actually want to use is something like:
query {
node(id: \"PROJECT_NODE_ID\") {
... on ProjectV2 {
items(first: 10) {
nodes {
content {
... on DraftIssue {
title
}
}
}
}
}
}
}

ComboBox.Item.add(USB1) switch language----- globalization - VS 2019 WPF

I added ComboBox from MainWindow_OnContentRendered, when I start the program, and how ComboBox.Item will find the resource file to change different language?> .How can I put WPF ComboBox content globalization.Thank you.
hello.
A.
1.
public void MyComboBox()
{
ComboBox.Item.add(USB1)
ComboBox.Item.add(USB2)
ComboBox.Item.add(USB3)
}
2.
MainWindow_OnContentRendered
{
MyComboBox();
}
B.
//ResourceHelper.cs
public static void LoadResource(string ) {
var = (from d in _Resourcelist where d.ToString().Equals() select d).FirstOrDefault();
App.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(langType, UriKind.RelativeOrAbsolute) });
Thread.CurrentThread.CurrentCulture = cultureInfo;
hread.CurrentThread.CurrentUICulture = cultureInfo;}
The question sounds quite simple but is quite difficult to answer. I've just started a new WPF application from scratch, so I thought about the issue of switching to a different language at runtime in general. Of course you have to set CurrentCulture and CurrentUICulture like you do in your example. But what about the controls and their textual content?
My solution is a recursive method that I call with MainWindow.Content as parameter, and then it iterates deeper and deeper through the hierarchy of controls:
private static void ReloadAllText(object root)
{
if (root is TextBlock textBlock1)
{
UpdateBinding(textBlock1, TextBlock.TextProperty);
}
else if (root is ContentControl contentControl)
{
if (contentControl.Content is string)
{
UpdateBinding(contentControl, ContentControl.ContentProperty);
}
else
{
ReloadAllText(contentControl.Content);
}
}
else if (root is Panel panel)
{
foreach (var child in panel.Children)
{
ReloadAllText(child);
}
}
else if (root is ItemsControl itemsControl)
{
for (int cnt = 0, cntMax = VisualTreeHelper.GetChildrenCount(itemsControl); cnt < cntMax; cnt++)
{
if (VisualTreeHelper.GetChild(itemsControl, cnt) is TextBlock textBlock2)
{
ReloadAllText(textBlock2);
}
}
foreach (var item in itemsControl.Items)
{
ReloadAllText(item);
}
}
else if (root is Decorator decorator)
{
ReloadAllText(decorator.Child);
}
else if (root is IRaiseLanguageChanged customItem)
{
customItem.RaiseLanguageChanged();
}
}
The method consists of several branches:
For TextBlock (which is also used by default as the text display element inside other, more complicated controls), the Text property is set to the new value. In my case, I just update the binding. In your case, the new text may have a different source, I don't know your architechture.
For ContentControl (which is any control that has a Content property), it depends: If the content is just a string, I can set it to the new value right away. If it's more complex, then I have to recurse deeper.
For Panel (which is the base class for StackPanel, DockPanel, Grid etc.), I just recurse for each child element.
For ItemsControl (so also for your ComboBox!), I recurse for each item. I added the VisualTree part only because I have a control template for an empty list box consisting of only a TextBox saying "no items". If you bind ItemsSource to an enum type, you must renew the ItemsSourceProperty binding.
For Decorator (e.g. Border), I recurse for its single child.
For custom/self-made controls, I have defined a custom interface IRaiseLanguageChanged, so they must implement a RaiseLanguageChanged() method and handle the language switch themselves. After all, a control itself knows best what to do when the language changes.
This reflects only the set of controls I'm currently using. If you have additional control types, then you have to add respective branches. Please post them here, if you have any good ideas!

Get Product Metafields Data with GraphQL / BigCommerce

I'm trying to retrieve product metafields on BigCommmerce via GraphQL. The below code throws an error
query {
site {
product(entityId:639) {
sku
path
metafields(namespace: "App_Namespace", keys: "color_key") {
edges {
node {
id
value
}
}
}
}
}
}
Meta field information
Namespace App_Namespace
Key color_key
Description Colour
Value Blue | Grey | Yellow
Would appreciate any help on above. Thanks
The "keys" argument expects an array of keys. So even if you just want one key, submit it as an array of one:
query {
site {
product(entityId: 639) {
sku
path
metafields(namespace: "App_Namespace", keys: ["color_key"]) {
edges {
node {
id
value
}
}
}
}
}
}
Check out this link for more examples:
https://developer.bigcommerce.com/changelog#posts/graph-ql-storefront-api-updates-metafields-on-product-category-brand-variant
You also need to make sure that these requirements are met,
otherwise, even if the query is correct, you won't be able to get the metafields in the query:
The metafield must be marked with a permission_set of read_and_sf_access or write_and_sf_access in order to be exposed to the API. Metafields with any other permission value will be hidden.

Filter empty nodes on GitHub GraphQL API

I'm trying to use the V4 API of GITHUB to get a list of my assigned issues along with its labels and references.
After some time I got the query you can see below, which works exactly how I want.
There is however, a problem: it includes a lot of empty nodes I am not interested at. For example, if I want to get all the CrossReferencedEvent that are issues I will get a lot of empty nodes on the timeline edges array because the other events: LabeledEvent, ReferencedEvent, AssignedEvent etc.
How can I filter out those so I only get the events I am interested at?
Is this a limitation of graphql? Am I forced to remove the useless nodes locally?
This is the query that I have currently
{
search(query: "assignee:danielo515", type: ISSUE, last: 100) {
edges {
node {
... on Issue {
number
title
state
timeline(first: 10) {
edges {
node {
... on CrossReferencedEvent {
source{
... on Issue {
title
number
}
}
}
}
}
}
labels(last: 10) {
nodes {
name
color
}
}
repository {
name
}
}
}
}
}
}
One improvement I can make is, on the query part add is:issue. This will . save me all the empty nodes at the root edges array, but I don't see how to do the same for the nested timeline.
Thanks in advance

Get child node by name in Umbraco 7.x

I have a page that has a child node named "Widgets". I want to render that child's template at a certain section in my page template. Currently, I do this:
#{
foreach (var child in CurrentPage.Children)
{
if (child.Name == "Widgets")
{
#Umbraco.RenderTemplate(child.Id)
}
}
}
Is there a way to avoid having to loop through the children like this?
I've also discovered I can do this:
#{
#Umbraco.RenderTemplate(
Model.Content.Children
.Where(x => x.Name == "Widgets")
.Select(x => x.Id)
.FirstOrDefault())
}
But I was really hoping there was a more terse way to do this, since I may want to do it in several places on a given page.
Yes, you could use Examine.
However, I would strongly object to this practice, because the user is able to change the Name of a node, and thus possibly breaking your code.
I would create a special document type and search the node using the document type. There are several (fast) ways to do that:
#Umbraco.ContentByXPath("//MyDocType") // this returns a dynamic variable
#Umbraco.TypedContentSingleByXPath("//MyDocType") // this returns a typed objects
#Model.Content.Descendants("MyDocType")
// and many other ways
Yes on the same Idea of accepted answer
Following code worked for me.
var currentPageNode = Library.NodeById(#Model.Id);
#if(#currentPageNode.NodeTypeAlias == "ContactMst")
{
<div>Display respective data...</div>
}
As mention not good practice. Rather find nodes by their type and use the alias of the document type in your code. If for whatever reason you need a particular node, rather give it a property and look for the property. Sample code below
if (Model.Content.Children.Any())
{
if (Model.Content.Children.Where(x => x.DocumentTypeAlias.Equals("aliasOfCorrespondingDocumentType")).Any())
{
// gives you the child nodes underneath the current page of particular document type with alias "aliasOfCorrespondingDocumentType"
IEnumerable<IPublishedContent> childNodes = Model.Content.Children.Where(x => x.DocumentTypeAlias.Equals("aliasOfCorrespondingDocumentType"));
foreach (IPublishedContent childNode in childNodes)
{
// check if this child node has your property
if (childNode.HasValue("aliasOfYourProperty"))
{
// get the property value
string myProp = childNode.aliasOfYourProperty.ToString();
// continue what you need to do
}
}
}
}

Resources