Skip to content

Commit

Permalink
Merge pull request #10 from Kentico/class-to-plain
Browse files Browse the repository at this point in the history
Class to plain
  • Loading branch information
Jan Lenoch authored Oct 15, 2018
2 parents bad2ae6 + 516b445 commit 627fd9d
Show file tree
Hide file tree
Showing 11 changed files with 828 additions and 648 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"presets": [ "@babel/preset-env" ],
"plugins": [
"@babel/plugin-transform-regenerator"
]
],
"sourceMaps": "both"
}
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@
!package.json
!.npmignore
!README.md
!*.js
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ deploy:
email: $NPM_EMAIL
api_key: $NPM_API_KEY
skip_cleanup: true
tag: beta
on:
tags: true
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"--runInBand",
"--no-cache"
],
"sourceMaps": false,
"sourceMaps": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"windows": {
Expand Down
83 changes: 43 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ This repo contains a [Gatsby v2 source plugin](https://www.gatsbyjs.org/docs/rec
You can use the plugin in any of the following ways:

* Install the [gatsby-source-kentico-cloud](https://www.npmjs.com/package/gatsby-source-kentico-cloud) NPM package in your Gatsby site via `npm install --save gatsby-source-kentico-cloud`.
* (Coming soon) Use the [gatsby-starter-kentico-cloud](https://github.com/Kentico/gatsby-starter-kentico-cloud) starter site, which uses the NPM package.
* Use the [gatsby-starter-kentico-cloud](https://github.com/Kentico/gatsby-starter-kentico-cloud) starter site, which uses the NPM package.

### Features

**Breaking change: All Kentico Cloud content element values now reside inside of the `elements` property of `kenticoCloudItem` nodes.**

The plugin creates GraphQL nodes for all Kentico Cloud content types, content items, and language variants.

The node names are prefixed with `kenticoCloud`. More specifically, content type nodes are prefixed with `kenticoCloudType` and content items and their language variants are prefixed with `kenticoCloudItem`.
Expand All @@ -22,23 +24,33 @@ The plugin creates the following relationships among the Kentico Cloud nodes. Yo

#### Content item <-> content type relationships

This relationship is captured in the `contentItems` navigation property of all *content type* nodes. For all *content item* nodes, it can be found in the `contentType` navigation property.
This relationship is captured in the `contentItems` navigation property of all `kenticoCloudType` nodes. In the opposite direction, in all `kenticoCloudItem` nodes, it can be found in the `contentType` navigation property.

You can use the GraphiQL interface to experiment with the data structures produced by the source plugin. For instance, you can fetch a content item of the *Project reference* type (by querying `kenticoCloudItemProjectReference`) and use the `contentType` navigation property to get a full list of all of the elements in the underlying content type. Like so:
You can use the GraphiQL interface to experiment with the data structures produced by the source plugin. For instance, you can fetch a content item of the *Project reference* type (by querying `allKenticoCloudItemProjectReference`) and use the `contentType` navigation property to get a full list of all of the elements in the underlying content type. Like so:

{
kenticoCloudItemProjectReference {
name___teaser_image__name {
value
allKenticoCloudItemProjectReference {
edges {
node {
elements {
name___teaser_image__name {
value
}
}
contentType {
elements {
codename
contentType {
elements {
name___teaser_image__name {
name
}
}
}
}
}
}
}
}

This kind of relationship comes handy when no content item has a particular element populated with data. In that case Gatsby won't recognize that element and won't include it in its internal schema. Neither the (null) value nor the name of the element will be visible through the `kenticoCloudItem` GraphQL nodes. Tapping into the related `kenticoCloudType` GraphQL node might be a proper fallback mechanism.

#### Language variant relationships

This relationship is captured by the `otherLanguages` navigation property of all content item nodes. For instance, you can get the names of all content items of the *Speaking engagement* type (by querying `kenticoCloudItemSpeakingEngagement`) in their default language as well as other languages all at once:
Expand All @@ -47,14 +59,18 @@ This relationship is captured by the `otherLanguages` navigation property of all
allKenticoCloudItemSpeakingEngagement {
edges {
node {
name {
value
}
otherLanguages {
elements {
name {
value
}
}
otherLanguages {
elements {
name {
value
}
}
}
}
}
}
Expand All @@ -68,13 +84,8 @@ Each modular content property is accompanied by a sibling property suffixed with
allKenticoCloudItemProjectReference {
edges {
node {
related_project_references {
name___teaser_image__name {
value
}
}
related_project_references_nodes {
name___teaser_image__name {
elements {
related_project_references {
value
}
related_project_references_nodes {
Expand All @@ -94,15 +105,17 @@ As with the previous example, all rich text properties with modular content also
allKenticoCloudItemBlogpostReference {
edges {
node {
name___teaser_image__name {
value
}
summary {
value
}
summary_nodes {
system {
codename
elements {
name___teaser_image__name {
value
}
summary {
value
}
summary_nodes {
system {
codename
}
}
}
}
Expand All @@ -118,16 +131,6 @@ All nodes have a `usedByContentItems` property that reflects the other nodes in

* [Node.js](https://nodejs.org/) with NPM installed

### Troubleshooting

In case you encounter the following error:

`GraphQL Error Unknown field 'system' on type '...'`

just rebuild the site using `npm run develop` or (if you have the Gatsby CLI installed) `gatsby develop`.

This [error](https://github.com/gatsbyjs/gatsby/issues/8053) occurs mostly due to issues with building of the internal schema. If it cannot be solved by rebuilding with `npm run develop` or raising the `version` field in the [package.json](https://github.com/Kentico/gatsby-source-kentico-cloud/blob/master/package.json) of the source plugin, then you should look for other root causes (not related to [building of the schema](https://github.com/gatsbyjs/gatsby/issues/2674#issuecomment-340510736)).

## Further information

For more developer resources, visit the Kentico Cloud Developer Hub at https://developer.kenticocloud.com.
Expand Down
Loading

0 comments on commit 627fd9d

Please sign in to comment.