[SOLVED] GraphQL reference returning empty

I have…

I’m submitting a…

  • [ ] Regression (a behavior that stopped working in a new release)
  • [x] Bug report
  • [ ] Performance issue
  • [ ] Documentation issue or request

Current behavior

Trying to use referencesXXXXXXContents functionality on the GraphiQL environment, it always returns an empty array. We have related data to it but it is not working.

Query executed:

Expected behavior

It should return the referenced items

Minimal reproduction of the problem

Create two schemas. In one of them create a reference field. Add some content on both. In the schema with the referenced field add a reference to the other schema.
When calling the GraphQL query it should returned the referenced items

Environment

App Name:

  • [x] Self hosted with docker
  • [ ] Self hosted with IIS
  • [ ] Self hosted with other version
  • [ ] Cloud version

Version: dev-7133

Browser:

  • [x] Chrome (desktop)
  • [ ] Chrome (Android)
  • [ ] Chrome (iOS)
  • [ ] Firefox
  • [ ] Safari (desktop)
  • [ ] Safari (iOS)
  • [ ] IE
  • [ ] Edge

Others:

Please format the code properly and use the template for new support requests.

Hi @Sebastian, sorry. I just updated it. It is correct?

Yes, thanks. Is everything published?

Yes, all the items are published. Do you want me to send any other information?

I just tested it with the cloud and it works fine. What is the basic structure of these two schemas?

Categories schema:

{
"previewUrls": {},
"properties": {
    "label": "Categories",
    "validateOnPublish": false
},
"category": "Knowledge",
"scripts": {},
"isPublished": true,
"fieldRules": [],
"fieldsInLists": [],
"fieldsInReferences": [],
"fields": [
    {
        "name": "title",
        "properties": {
            "isRequired": true,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "String",
            "createEnum": false,
            "editor": "Input",
            "inlineEditable": false,
            "isEmbeddable": false,
            "isUnique": true,
            "minLength": 1,
            "contentType": "Unspecified",
            "label": "Title"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "description",
        "properties": {
            "isRequired": false,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "String",
            "createEnum": false,
            "editor": "Input",
            "inlineEditable": false,
            "isEmbeddable": false,
            "isUnique": false,
            "minLength": 1,
            "contentType": "Unspecified",
            "label": "Description"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "image",
        "properties": {
            "isRequired": true,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "Assets",
            "previewMode": "ImageAndFileName",
            "resolveFirst": false,
            "minItems": 1,
            "maxItems": 1,
            "maxSize": 51200,
            "expectedType": "Image",
            "mustBeImage": true,
            "resolveImage": false,
            "allowDuplicates": false,
            "label": "Image"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "articles",
        "properties": {
            "isRequired": true,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "References",
            "editor": "List",
            "allowDuplicates": false,
            "resolveReference": false,
            "mustBePublished": true,
            "schemaIds": [
                "011bc0ea-f754-4edd-83b6-1c76f82762b9"
            ],
            "label": "Articles"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    }
],
"type": "Default"

}

Knowledge schema:

{
"previewUrls": {},
"properties": {
    "label": "Articles",
    "validateOnPublish": false
},
"category": "Knowledge",
"scripts": {
    "query": "",
    "create": "/*var htmlContent = ctx.data.HTMLcontent.iv;\nvar result = htmlContent.match(/<h2>/);\n\nhtmlContent.replace('<h2>','<h2 id=\"article-anchor-h2-1>\"');\nfor(var i = 0; result.lenght >= i; i++){\n    \n}\n//result.forEach((element, index) => `<h2 id=article-anchor-h2-${index}>`)\n\n\nctx.data.stringToHTML.iv = result[0];\nctx.data.HTMLcontent.iv = htmlContent;*/\n\n// var regexp = /(<h1.*?>|<h2.*?>)/g;\nvar str = ctx.data.HTMLcontent.iv;\n\n// var text = str.match( regexp ).toString();\n\nfunction findText(toFind, whereToFind){\n\treturn whereToFind.includes(toFind);\n}\n\nfunction getTitle(textToReplace){\n\treturn textToReplace.split('</h')[0].split('>')[1];\n}\n\nfunction getId(text){\n  var regexpHeadersIds = /(id=('|\")[\\w\\d]+('|\"))/g;\n  var idValue = text.match(regexpHeadersIds);\n  if(idValue){\n  \treturn idValue[0].split('id=')[1];\n  }\n  return null;\n}\n\nvar regexp = /(<h(1|2).*?>.*?<\\/h(1|2)>)/g;\n\nvar text = str.match( regexp );\nvar navigation = [];\nvar oldItem = '';\n\nfor(var counter = 0; counter < text.length; counter++){\n\tvar textToReplace = text[counter];\n  var title = getTitle(textToReplace);\n  var idValueReturned = getId(textToReplace);\n  var hash = '';\n  if(!idValueReturned){\n    hash = '#' + title.replace(' ', '');\n  }else{\n  \thash = '#' + idValueReturned;\n  }\n  navigation.push({ title: title, hash: hash, children: []});\n}\n\nctx.data.pattern.iv = JSON.stringify(navigation);\nctx.data.navigation.iv = navigation;\n\nreplace();",
    "update": "/*var htmlContent = ctx.data.HTMLcontent.iv;\nvar result = htmlContent.match(/<h2>/);\n\nhtmlContent.replace('<h2>','<h2 id=\"article-anchor-h2-1>\"');\nfor(var i = 0; result.lenght >= i; i++){\n    \n}\n//result.forEach((element, index) => `<h2 id=article-anchor-h2-${index}>`)\n\n\nctx.data.stringToHTML.iv = result[0];\nctx.data.HTMLcontent.iv = htmlContent;*/\n\n// var regexp = /(<h1.*?>|<h2.*?>)/g;\nvar str = ctx.data.HTMLcontent.iv;\n\n// var text = str.match( regexp ).toString();\n\nfunction findText(toFind, whereToFind){\n\treturn whereToFind.includes(toFind);\n}\n\nfunction getTitle(textToReplace){\n\treturn textToReplace.split('</h')[0].split('>')[1];\n}\n\nfunction getId(text){\n  var regexpHeadersIds = /(id=('|\")[\\w\\d]+('|\"))/g;\n  var idValue = text.match(regexpHeadersIds);\n  if(idValue){\n  \treturn idValue[0].split('id=')[1];\n  }\n  return null;\n}\n\nvar regexp = /(<h(1|2).*?>.*?<\\/h(1|2)>)/g;\n\nvar text = str.match( regexp );\nvar navigation = [];\nvar oldItem = '';\n\nfor(var counter = 0; counter < text.length; counter++){\n\tvar textToReplace = text[counter];\n  var title = getTitle(textToReplace);\n  var idValueReturned = getId(textToReplace);\n  var hash = '';\n  if(!idValueReturned){\n    hash = '#' + title.replace(' ', '');\n  }else{\n  \thash = '#' + idValueReturned;\n  }\n  navigation.push({ title: title, hash: hash, children: []});\n}\n\nctx.data.pattern.iv = JSON.stringify(navigation);\nctx.data.navigation.iv = navigation;\n\nreplace();"
},
"isPublished": true,
"fieldRules": [
    {
        "action": "Hide",
        "field": "HTMLcontent",
        "condition": "data.type.iv != 'HTML'"
    },
    {
        "action": "Hide",
        "field": "direct-url",
        "condition": "data.type.iv != 'Direct URL'"
    },
    {
        "action": "Hide",
        "field": "document-content",
        "condition": "data.type.iv != 'Document'"
    }
],
"fieldsInLists": [],
"fieldsInReferences": [],
"fields": [
    {
        "name": "page-title-question",
        "properties": {
            "isRequired": true,
            "isRequiredOnPublish": true,
            "isHalfWidth": false,
            "fieldType": "String",
            "createEnum": false,
            "editor": "Input",
            "inlineEditable": false,
            "isEmbeddable": false,
            "isUnique": true,
            "contentType": "Unspecified",
            "label": "Page Title (Question)"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "type",
        "properties": {
            "isRequired": true,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "String",
            "createEnum": false,
            "editor": "Dropdown",
            "inlineEditable": false,
            "isEmbeddable": false,
            "isUnique": false,
            "allowedValues": [
                "HTML",
                "Document",
                "Direct URL"
            ],
            "contentType": "Unspecified",
            "label": "Type"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "HTMLcontent",
        "properties": {
            "isRequired": false,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "String",
            "createEnum": false,
            "editor": "RichText",
            "inlineEditable": false,
            "isEmbeddable": false,
            "isUnique": false,
            "contentType": "Html",
            "label": "HTML Content",
            "editorUrl": ""
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "document-content",
        "properties": {
            "isRequired": false,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "Assets",
            "previewMode": "ImageAndFileName",
            "resolveFirst": true,
            "minItems": 1,
            "maxItems": 1,
            "mustBeImage": false,
            "resolveImage": true,
            "allowedExtensions": [
                "png",
                "docx",
                "pdf"
            ],
            "allowDuplicates": false,
            "label": "Document content"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "direct-url",
        "properties": {
            "isRequired": false,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "String",
            "createEnum": false,
            "editor": "Input",
            "inlineEditable": false,
            "isEmbeddable": false,
            "isUnique": false,
            "pattern": "^(?:http(s)?:\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:\\/?#%[\\]@!\\$&'\\(\\)\\*\\+,;=.]+$",
            "contentType": "Unspecified",
            "label": "Direct URL"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "tags",
        "properties": {
            "isRequired": false,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "Tags",
            "createEnum": false,
            "editor": "Tags",
            "label": "Tags"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "category",
        "properties": {
            "isRequired": true,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "String",
            "createEnum": false,
            "editor": "Dropdown",
            "inlineEditable": false,
            "isEmbeddable": false,
            "isUnique": false,
            "allowedValues": [
                "Article",
                "Document",
                "FAQ",
                "Video"
            ],
            "contentType": "Unspecified",
            "label": "Category",
            "hints": "Category for filtering"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "public",
        "properties": {
            "isRequired": false,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "Boolean",
            "editor": "Checkbox",
            "inlineEditable": false,
            "defaultValue": false,
            "label": "Public ",
            "hints": "Non logged in users can access the content"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "retailer-access",
        "properties": {
            "isRequired": false,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "Boolean",
            "editor": "Checkbox",
            "inlineEditable": false,
            "defaultValue": false,
            "label": "Retailer Access",
            "hints": "A logged in user with the role 'Retailer' can access the content"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "supplier-access",
        "properties": {
            "isRequired": false,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "Boolean",
            "editor": "Checkbox",
            "inlineEditable": false,
            "defaultValue": false,
            "label": "Supplier Access",
            "hints": "A logged in user with the role 'Supplier' can access the content"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "asdada",
        "properties": {
            "isRequired": false,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "Json"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "pattern",
        "properties": {
            "isRequired": false,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "String",
            "createEnum": false,
            "editor": "TextArea",
            "inlineEditable": false,
            "isEmbeddable": false,
            "isUnique": false,
            "contentType": "Unspecified",
            "label": "Pattern"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    },
    {
        "name": "navigation",
        "properties": {
            "isRequired": false,
            "isRequiredOnPublish": false,
            "isHalfWidth": false,
            "fieldType": "Json",
            "label": "Navigation"
        },
        "isLocked": false,
        "isHidden": false,
        "isDisabled": false,
        "partitioning": "invariant"
    }
],
"type": "Default"

}

But the category property in knowledge is no reference.

Hi Sebastian, the category property on the knowledge schema is another kind of data, this is not related to the category schema.

The only field that is relating the category schema with the knowledge schema is the field on the category schema with the name “articles”.

Thanks

The referencesXXX property is used for the reverse direction.

If your categories have a direct reference to articles you have to use:

query {
   queryCategoriesContents {
      flatData {
        articles {
          ...
        }
      }
   }
}

But if you want to know which categories are referenced by an article you can use this:

query {
  queryArticlesContents {
    referencingCategoriesContents {
      id
    }
  }
}

(Names are probably not correct)

Hi! Thanks for the quick response. We were using the referencingXXXContent as you said and it is working great to get reverse direction. But the referencesXXXContent is only being shown when we are in the top-bottom direction.

I attached a snapshot when we are writing on GraphiQL that the property referenceXXXContents only is shown on the item that has a field of type reference.

Which is the purpose of referenceXXXContent here?

Thanks

referencesXXX gives you all references across all fields.2

Hi! So, on the first example that I sent you, we should see all the related elements and not an empty array. Isn’t it?

Oh, you choose references … mhm. let me check again.

1 Like

It is actually a bug. But you can just use

flatData { 
  articles 
}

Ok, thanks Sebastian. I don’t know if the flatData is going to be useful for us. What we saw with the referenceXXXContent is that it accepted a filter method, and that could help us to filter the child items. Thats why we wanted to use it.

Let me know if you fix the bug on that property.

Thank you very much for the support.

I actually consider to remove it. When nobody has complained so far, then nobody has probably asked for that yet and it is not needed.

1 Like

Fixed in dev-7334 (sorry, I had a problem with CI and some flaky tests)

Thanks Sebastian! You are a crack!

1 Like