Comments (7)
Hi @chris-evansnz,
In this case, you want to extend the BasicBlockListItem and use this instead of the BasicBlockListItem that is used in the documentation.
The BasicBlockListModel takes a type of BasicBlockListItem as the generic parameter so you just need to have another class inherit from the BasicBlockListItem eg.
public class CustomBlockListItem : BasicBlockListItem<BasicProperty> {
public string MyCustomProperty { get; set; }
public CustomBlockListItem (CreateBlockListItem createBlockListItem, IPropertyFactory<BasicProperty> propertyFactory) {
MyCustomProperty = "Hello I'm Custom!";
}
}
public class CustomBlockListModel : BasicBlockListModel<CustomBlockListItem> {
public string MyCustomProperty { get; set; }
public CustomBlockListModel(CreatePropertyValue createPropertyValue, IDependencyReflectorFactory dependencyReflectorFactory) : base(createPropertyValue, dependencyReflectorFactory) {
MyCustomProperty = "Hello I'm Custom!";
}
}
from nikcio.uheadless.
@chris-evansnz Did this answer your question?
from nikcio.uheadless.
@nikcio thanks so much for the quick response! I live in New Zealand so my time zone is a bit odd - hence the slower reply.
I figured something like this was required. I just tried implementing that, and the code compiles ok but I'm not sure how to query my new property.
I've got this:
public class CustomBlockListModel : BasicBlockListModel<BasicBlockListItem<BasicProperty>>
{
public string MyCustomProperty { get; set; }
public CustomBlockListModel(CreatePropertyValue createPropertyValue, IDependencyReflectorFactory dependencyReflectorFactory) : base(createPropertyValue, dependencyReflectorFactory)
{
MyCustomProperty = "Hello I'm Custom at parent!";
}
}
public class CustomBlockListItem : BasicBlockListItem<BasicProperty>
{
public string MyCustomProperty2 { get; set; }
public CustomBlockListItem(CreateBlockListItem createBlockListItem, IPropertyFactory<BasicProperty> propertyFactory) : base(createBlockListItem, propertyFactory)
{
MyCustomProperty2 = "Hello I'm Custom in block item!2";
}
}
And I'm running this graphql query on a page I have called Contact Us:
{
contentByAbsoluteRoute (route: "/contact-us") {
name,
id,
properties {
alias,
value,
editorAlias,
__typename
}
}
}
I get this response, which shows the first custom property on the parent Block List, but not the second custom property on the block children:
{
"data": {
"contentByAbsoluteRoute": {
"name": "Contact us",
"id": 1070,
"properties": [
{
"alias": "contentBlocks",
"value": {
"myCustomProperty": "Hello I'm Custom at parent!",
"blocks": [
{
"contentProperties": [
{
"alias": "title",
"value": {
"value": "My test feature"
},
"editorAlias": "Umbraco.TextBox"
},
{
"alias": "text",
"value": {
"value": "<p>This is some text for the feature</p>"
},
"editorAlias": "Umbraco.TinyMCE"
},
{
"alias": "image",
"value": {
"mediaItems": [
{
"url": "https://localhost:44387/media/ivmfpss5/90mmplusnailerpluswebplusp1.png",
"id": 1069
}
]
},
"editorAlias": "Umbraco.MediaPicker3"
},
{
"alias": "showImageOnRight",
"value": {
"value": false
},
"editorAlias": "Umbraco.TrueFalse"
}
],
"settingsProperties": [],
"contentAlias": "featureBlock",
"settingsAlias": null
},
{
"contentProperties": [
{
"alias": "title",
"value": {
"value": "Second feature"
},
"editorAlias": "Umbraco.TextBox"
},
{
"alias": "text",
"value": {
"value": "<p>Some text for the second feature</p>"
},
"editorAlias": "Umbraco.TinyMCE"
},
{
"alias": "image",
"value": {
"mediaItems": [
{
"url": "https://localhost:44387/media/b1sgsw1d/_0002_layer-30.png",
"id": 1072
}
]
},
"editorAlias": "Umbraco.MediaPicker3"
},
{
"alias": "showImageOnRight",
"value": {
"value": true
},
"editorAlias": "Umbraco.TrueFalse"
}
],
"settingsProperties": [],
"contentAlias": "featureBlock",
"settingsAlias": null
}
]
},
"editorAlias": "Umbraco.BlockList",
"__typename": "BasicProperty"
}
]
}
}
}
Is there something else I need to do in code to expose this new custom property on the children, or is there something I need to add in the graphql query? I couldn't see the MyCustomProperty2 in the playground schema docs.
If I try to query it explicity I get this response in the graphql playground:
"The field `myCustomProperty2` does not exist on the type `BasicProperty`.",
Thanks again for your help!
from nikcio.uheadless.
@chris-evansnz you need to change this line:
public class CustomBlockListModel : BasicBlockListModel<BasicBlockListItem<BasicProperty>>
To this
public class CustomBlockListModel : BasicBlockListModel<CustomBlockListItem<BasicProperty>>
Otherwise you don't use your custom implementation of the block list item.
About the properties not being available in the GraphQL playground. This will be fixed in version 3. Right now it's just a normal JSON text that's put into the property hence why you can't specifically query the properties value.
from nikcio.uheadless.
Hmm - when I try that I get this compilation error:
is there something else I need to include or declare?
from nikcio.uheadless.
Oh sorry @chris-evansnz. It needs to say:
public class CustomBlockListModel : BasicBlockListModel<CustomBlockListItem>
Your CustomBlockListItem
isn't generic and therefore doesn't take an type argument eg. <BasicProperty>
from nikcio.uheadless.
Ah yes, that makes sense. I can see the property in the results now, thanks so much for your responses!
Will keep experimenting with this package and see how we can make use of it in our projects, it's very promising indeed.
from nikcio.uheadless.
Related Issues (20)
- How to "hide" the GraphQL UI in production? HOT 1
- How to protect schema endpoints by "roles" or "member groups"? HOT 3
- How to query only own data? HOT 10
- Using GraphQL to query MarkdownEditor value HOT 2
- Preview HOT 2
- Adding custom basic types HOT 3
- Exception thrown when content picker value is node with unpublished parent HOT 4
- Querying all descendants of a node including nested descendants HOT 2
- Empty value when property is shared between cultures HOT 3
- Extend the existing content model not extending to children and parent nodes HOT 3
- Support Preview flag in ContentByContentTypeQuery HOT 4
- Doubt about PropertyValueFilterInput HOT 2
- Extend an existing property value does not override a default Basic value HOT 10
- Filter By Custom Property Value HOT 7
- Unable to obtain children of content within BasicContentPicker HOT 5
- contentByAbsoluteRoute routingmode CACHE_OR_ROUTING requires baseUrl otherwise crash on 404 HOT 8
- Extended Content Model only when requested in the graphQL fields HOT 2
- Is't possibile to push data to the Umbraco or only read from it? HOT 1
- Error in Docs: Where is the file howToUseAExtendingPackage.md? HOT 1
- Possible localization bug in BasicBlockListModel? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nikcio.uheadless.