kentico-cloud-graphql-schema-generator
Advanced tools
Comparing version 0.0.1-beta2 to 0.0.1-beta3
@@ -84,3 +84,3 @@ "use strict"; | ||
'asset', | ||
"type Asset {\n name: String\n type: String\n size: Int\n description: String\n url: String,\n}", | ||
"type Asset {\n name: String\n type: String\n size: Int\n description: String\n url: String\n}", | ||
], | ||
@@ -87,0 +87,0 @@ [ |
#!/usr/bin/env node | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var fs = require("fs"); | ||
var kentico_cloud_delivery_1 = require("kentico-cloud-delivery"); | ||
var yargs = require("yargs"); | ||
var schema_generator_1 = require("./schema-generator"); | ||
// tslint:disable-next-line:no-var-requires | ||
var yargs = require('yargs'); | ||
var argv = yargs.argv; | ||
var projectId = argv.projectId; | ||
var secureAccessKey = argv.secureAccessKey; | ||
var outputFile = argv.outputFile; | ||
var createModule = argv.createModule; | ||
if (!projectId) { | ||
throw Error("Please provide project id using 'projectId' argument"); | ||
throw Error('Please provide project id using \'projectId\' argument'); | ||
} | ||
@@ -20,5 +22,17 @@ var deliveryClient = new kentico_cloud_delivery_1.DeliveryClient({ | ||
var generator = new schema_generator_1.SchemaGenerator(deliveryClient); | ||
generator.getSchema().then(function (result) { | ||
console.info(result); | ||
generator.createModule(createModule); | ||
generator.getSchema() | ||
.then(function (result) { | ||
if (outputFile) { | ||
fs.writeFile(outputFile, result, function (err) { | ||
if (err) { | ||
console.error("Error while writing schema to file: " + outputFile); | ||
throw err; | ||
} | ||
}); | ||
} | ||
else { | ||
console.log(result); | ||
} | ||
}); | ||
//# sourceMappingURL=index.js.map |
import { DeliveryClient } from 'kentico-cloud-delivery'; | ||
export declare class SchemaGenerator { | ||
private readonly deliveryClient; | ||
private encapsulateToModule; | ||
constructor(deliveryClient: DeliveryClient); | ||
getSchema(): Promise<string>; | ||
createModule(value: boolean): SchemaGenerator; | ||
private wrapByModule; | ||
private transformToSchemas; | ||
@@ -7,0 +10,0 @@ private loadContentTypes; |
@@ -38,6 +38,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var os = require("os"); | ||
var graphql_schema_model_1 = require("./graphql-schema-model"); | ||
var SchemaGenerator = /** @class */ (function () { | ||
function SchemaGenerator(deliveryClient) { | ||
this.encapsulateToModule = false; | ||
if (!deliveryClient) { | ||
@@ -50,3 +50,3 @@ throw Error('Provide DeliveryClient'); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var schemaModel, fieldSchemas, contentTypes, contentTypesSchemas; | ||
var schemaModel, fieldSchemas, contentTypes, contentTypesSchemas, result; | ||
return __generator(this, function (_a) { | ||
@@ -61,3 +61,7 @@ switch (_a.label) { | ||
contentTypesSchemas = this.transformToSchemas(contentTypes); | ||
return [2 /*return*/, fieldSchemas.concat(contentTypesSchemas).join('\n')]; | ||
result = fieldSchemas.concat(contentTypesSchemas).join('\n'); | ||
if (this.encapsulateToModule) { | ||
result = this.wrapByModule(result); | ||
} | ||
return [2 /*return*/, result]; | ||
} | ||
@@ -67,2 +71,9 @@ }); | ||
}; | ||
SchemaGenerator.prototype.createModule = function (value) { | ||
this.encapsulateToModule = value; | ||
return this; | ||
}; | ||
SchemaGenerator.prototype.wrapByModule = function (input) { | ||
return "export const TYPE_DEFINITION = `" + input + "`;"; | ||
}; | ||
SchemaGenerator.prototype.transformToSchemas = function (contentTypes) { | ||
@@ -79,3 +90,3 @@ var _this = this; | ||
var typename = _this.snakeToPascal(contentType.system.codename) + 'ContentType'; | ||
return "\ntype " + typename + " implements " + graphql_schema_model_1.GraphQLSchemaModel.contentItemInterfaceName + " {\n system: " + graphql_schema_model_1.GraphQLSchemaModel.systemTypeName + "!\n " + elements.join(os.EOL + ' ') + "\n}"; | ||
return "\ntype " + typename + " implements " + graphql_schema_model_1.GraphQLSchemaModel.contentItemInterfaceName + " {\n system: " + graphql_schema_model_1.GraphQLSchemaModel.systemTypeName + "!\n " + elements.join('\n' + ' ') + "\n}"; | ||
}); | ||
@@ -82,0 +93,0 @@ }; |
{ | ||
"name": "kentico-cloud-graphql-schema-generator", | ||
"version": "0.0.1-beta2", | ||
"version": "0.0.1-beta3", | ||
"description": "GraphQL schema generator used to generate schema based on specified project.", | ||
@@ -14,2 +14,3 @@ "main": "_commonjs/index.js", | ||
"test": "jest", | ||
"test:coverage": "jest --coverage", | ||
"watch": "tsc -w", | ||
@@ -16,0 +17,0 @@ "build": "tsc" |
271
README.md
# Kentico GraphQl schema generator | ||
[![Build Status](https://api.travis-ci.org/Kentico/kentico-cloud-graphql-schema-generator.svg?branch=master)](https://travis-ci.org/Kentico/kentico-cloud-graphql-schema-generator) | ||
[![npm version](https://badge.fury.io/js/kentico-cloud-graphql-schema-generator.svg)](https://www.npmjs.com/package/kentico-cloud-graphql-schema-generator) | ||
[![npm](https://img.shields.io/npm/dt/kentico-cloud-graphql-schema-generator.svg)](https://www.npmjs.com/package/kentico-cloud-graphql-schema-generator) | ||
[GraphQL schema](https://graphql.org/learn/schema/) generator used to generate schema based on specified project. | ||
@@ -8,3 +12,3 @@ | ||
# Prerequisites | ||
## Prerequisites | ||
* [Node](https://nodejs.org/en/download/) installed | ||
@@ -19,4 +23,17 @@ | ||
`kc-generate-gql-schema --projectId xxx` | ||
Write type definition to the snadard output | ||
* `kc-generate-gql-schema --projectId xxx` | ||
Generate file with definition exported as a constant fo file `config.js` | ||
* `kc-generate-gql-schema --projectId xxx --createModule --outputFile "config.js"` | ||
## Configuration | ||
* `projectId` - represents the Kentico Cloud Project Id from which schema will be generated | ||
* `secureAccessKey` - Secure access key required to authenticate requests with enabled secure access in Kentico Cloud project | ||
* `outputFile` - specifies output file name (possible with the path), if not specified - output is written to standard output | ||
* `createModule` - output is defined as a constant and exported as a module (see [Example Output](#example-output)) | ||
# Development | ||
@@ -42,2 +59,3 @@ | ||
<details> | ||
<summary>Without module encapsulation (w/o `createModule`)</summary> | ||
@@ -143,145 +161,93 @@ ``` | ||
type AccessoryContentType implements ContentItem { | ||
system: SystemInfo! | ||
metadata__og_description: TextElement | ||
metadata__meta_title: TextElement | ||
metadata__og_title: TextElement | ||
long_description: RichTextElement | ||
metadata__meta_description: TextElement | ||
metadata__twitter_site: TextElement | ||
price: NumberElement | ||
metadata__twitter_image: AssetElement | ||
metadata__twitter_creator: TextElement | ||
url_pattern: UrlSlugElement | ||
short_description: RichTextElement | ||
manufacturer: TextElement | ||
metadata__twitter_title: TextElement | ||
metadata__twitter_description: TextElement | ||
metadata__og_image: AssetElement | ||
product_status: TaxonomyElement | ||
image: AssetElement | ||
product_name: TextElement | ||
} | ||
``` | ||
type ArticleContentType implements ContentItem { | ||
system: SystemInfo! | ||
metadata__og_description: TextElement | ||
metadata__meta_title: TextElement | ||
personas: TaxonomyElement | ||
body_copy: RichTextElement | ||
metadata__og_title: TextElement | ||
metadata__meta_description: TextElement | ||
metadata__twitter_site: TextElement | ||
post_date: DateTimeElement | ||
meta_keywords: TextElement | ||
teaser_image: AssetElement | ||
metadata__twitter_image: AssetElement | ||
metadata__twitter_creator: TextElement | ||
title: TextElement | ||
summary: TextElement | ||
metadata__twitter_title: TextElement | ||
metadata__twitter_description: TextElement | ||
meta_description: TextElement | ||
metadata__og_image: AssetElement | ||
related_articles: [ContentItem] | ||
url_pattern: UrlSlugElement | ||
} | ||
</details> | ||
type BrewerContentType implements ContentItem { | ||
system: SystemInfo! | ||
product_name: TextElement | ||
metadata__og_description: TextElement | ||
metadata__meta_title: TextElement | ||
long_description: RichTextElement | ||
metadata__og_title: TextElement | ||
metadata__meta_description: TextElement | ||
metadata__twitter_site: TextElement | ||
price: NumberElement | ||
manufacturer: TaxonomyElement | ||
metadata__twitter_image: AssetElement | ||
metadata__twitter_creator: TextElement | ||
url_pattern: UrlSlugElement | ||
short_description: RichTextElement | ||
product_status: TaxonomyElement | ||
metadata__twitter_title: TextElement | ||
metadata__twitter_description: TextElement | ||
metadata__og_image: AssetElement | ||
image: AssetElement | ||
} | ||
<details> | ||
<summary>With module encapsulation</summary> | ||
type CafeContentType implements ContentItem { | ||
system: SystemInfo! | ||
phone: TextElement | ||
city: TextElement | ||
photo: AssetElement | ||
email: TextElement | ||
country: TextElement | ||
street: TextElement | ||
state: TextElement | ||
zip_code: TextElement | ||
``` | ||
export const TYPE_DEFINITION = `type SystemInfo { | ||
id: String! | ||
name: String! | ||
codename: String! | ||
language: String! | ||
type: String! | ||
lastModified: String! | ||
} | ||
type CoffeeContentType implements ContentItem { | ||
interface ContentItem { | ||
system: SystemInfo! | ||
metadata__og_description: TextElement | ||
metadata__meta_title: TextElement | ||
metadata__og_title: TextElement | ||
product_status: TaxonomyElement | ||
altitude: TextElement | ||
metadata__meta_description: TextElement | ||
variety: TextElement | ||
image: AssetElement | ||
metadata__twitter_site: TextElement | ||
url_pattern: UrlSlugElement | ||
price: NumberElement | ||
metadata__twitter_image: AssetElement | ||
metadata__twitter_creator: TextElement | ||
country: TextElement | ||
metadata__twitter_title: TextElement | ||
short_description: RichTextElement | ||
processing: TaxonomyElement | ||
metadata__twitter_description: TextElement | ||
metadata__og_image: AssetElement | ||
long_description: RichTextElement | ||
farm: TextElement | ||
product_name: TextElement | ||
} | ||
type FactAboutUsContentType implements ContentItem { | ||
system: SystemInfo! | ||
description: RichTextElement | ||
title: TextElement | ||
image: AssetElement | ||
type MultipleChoiceElementOption { | ||
name: String! | ||
codename: String | ||
} | ||
type GrinderContentType implements ContentItem { | ||
system: SystemInfo! | ||
metadata__og_description: TextElement | ||
metadata__meta_title: TextElement | ||
metadata__og_title: TextElement | ||
price: NumberElement | ||
long_description: RichTextElement | ||
short_description: RichTextElement | ||
manufacturer: TextElement | ||
metadata__meta_description: TextElement | ||
metadata__twitter_site: TextElement | ||
product_status: TaxonomyElement | ||
metadata__twitter_image: AssetElement | ||
metadata__twitter_creator: TextElement | ||
image: AssetElement | ||
metadata__twitter_title: TextElement | ||
product_name: TextElement | ||
metadata__twitter_description: TextElement | ||
url_pattern: UrlSlugElement | ||
metadata__og_image: AssetElement | ||
type TaxonomyTerm { | ||
name: String! | ||
codename: String | ||
} | ||
type HeroUnitContentType implements ContentItem { | ||
system: SystemInfo! | ||
title: TextElement | ||
image: AssetElement | ||
marketing_message: RichTextElement | ||
type Asset { | ||
name: String | ||
type: String | ||
size: Int | ||
description: String | ||
url: String, | ||
} | ||
type Link { | ||
codename: String | ||
itemID: String | ||
urlSlug: String | ||
type: String | ||
} | ||
type TextElement { | ||
type: String! | ||
name: String! | ||
value: String | ||
} | ||
type NumberElement { | ||
type: String! | ||
name: String! | ||
value: String | ||
number: Int | ||
} | ||
type DateTimeElement { | ||
type: String! | ||
name: String! | ||
value: String | ||
datetime: String | ||
} | ||
type MultipleChoiceElement { | ||
type: String! | ||
name: String! | ||
value: String | ||
options: [MultipleChoiceElementOption] | ||
} | ||
type UrlSlugElement { | ||
type: String! | ||
name: String! | ||
value: String | ||
data: String | ||
} | ||
type TaxonomyElement { | ||
type: String! | ||
name: String! | ||
value: String | ||
taxonomyGroup: String | ||
taxonomyTerms: [TaxonomyTerm] | ||
} | ||
type AssetElement { | ||
type: String! | ||
name: String! | ||
value: String | ||
assets: [Asset] | ||
} | ||
type RichTextElement { | ||
type: String! | ||
name: String! | ||
value: String | ||
linkedItemCodenames: [String] | ||
links: [Link] | ||
} | ||
type HomeContentType implements ContentItem { | ||
type AboutUsContentType implements ContentItem { | ||
system: SystemInfo! | ||
@@ -291,8 +257,5 @@ metadata__og_description: TextElement | ||
metadata__og_title: TextElement | ||
articles: [ContentItem] | ||
hero_unit: [ContentItem] | ||
metadata__meta_description: TextElement | ||
metadata__twitter_site: TextElement | ||
our_story: [ContentItem] | ||
cafes: [ContentItem] | ||
url_pattern: UrlSlugElement | ||
metadata__twitter_image: AssetElement | ||
@@ -303,33 +266,7 @@ metadata__twitter_creator: TextElement | ||
metadata__og_image: AssetElement | ||
url_pattern: UrlSlugElement | ||
contact: RichTextElement | ||
} | ||
facts: [ContentItem] | ||
}`; | ||
type HostedVideoContentType implements ContentItem { | ||
system: SystemInfo! | ||
video_id: TextElement | ||
video_host: MultipleChoiceElement | ||
} | ||
type OfficeContentType implements ContentItem { | ||
system: SystemInfo! | ||
state: TextElement | ||
email: TextElement | ||
phone: TextElement | ||
country: TextElement | ||
city: TextElement | ||
name: TextElement | ||
zip_code: TextElement | ||
street: TextElement | ||
} | ||
type TweetContentType implements ContentItem { | ||
system: SystemInfo! | ||
tweet_link: TextElement | ||
theme: MultipleChoiceElement | ||
display_options: MultipleChoiceElement | ||
} | ||
``` | ||
</details> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
322
0
29547
267
1