New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

graphdoc-plugin-schema

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphdoc-plugin-schema - npm Package Compare versions

Comparing version

to
2.0.0-alpha

CHANGELOG.md

30

lib/index.js
// Copyright (c) 2021 Gonzalo Müller Bravo.
// Licensed under the MIT License (MIT), see LICENSE.txt
const marked = require('marked')
const SchemaPlugin = require('@2fd/graphdoc/plugins/document.schema').default

@@ -16,4 +15,3 @@ const graphdocUtils = require('@2fd/graphdoc/lib/utility')

const config = projectPackage['graphdoc-plugin-schema'] || {}
this.documentTitle = config.documentTitle || 'Description'
this.extractDescription = activeOption(config.extractDescription)
this.documentTitle = config.documentTitle || 'Definition'
this.types = new Map()

@@ -36,7 +34,4 @@ schema.types && schema.types.forEach(type => SUPPORTED_KINDS_REGEX.test(type.kind) && this.types.set(type.name, type))

getDocument(description, extractedDescription) {
return [ {
title: this.documentTitle,
description: (extractedDescription ? `<div class="x-desc">${marked(extractedDescription)}</div>` : '') + graphdocUtils.html.code(description)
} ]
getDocument(description) {
return [ new graphdocUtils.DocumentSection(this.documentTitle, graphdocUtils.html.code(description)) ]
}

@@ -47,22 +42,15 @@

if (type) {
const finalType = this.extractDescription
? {
...type,
extractedDescription: type.description,
description: ''
}
: type
switch (type.kind) {
case 'SCALAR':
return this.getDocument(this.builder.scalar(finalType), finalType.extractedDescription)
return this.getDocument(this.builder.scalar(type))
case 'OBJECT':
return this.getDocument(this.builder.object(finalType), finalType.extractedDescription)
return this.getDocument(this.builder.object(type))
case 'INTERFACE':
return this.getDocument(this.builder.interfaces(finalType), finalType.extractedDescription)
return this.getDocument(this.builder.interfaces(type))
case 'UNION':
return this.getDocument(this.builder.union(finalType), finalType.extractedDescription)
return this.getDocument(this.builder.union(type))
case 'ENUM':
return this.getDocument(this.builder.enum(finalType), finalType.extractedDescription)
return this.getDocument(this.builder.enum(type))
case 'INPUT_OBJECT':
return this.getDocument(this.builder.inputObject(finalType), finalType.extractedDescription)
return this.getDocument(this.builder.inputObject(type))
}

@@ -69,0 +57,0 @@ }

{
"name": "graphdoc-plugin-schema",
"description": "GraphQL documentation using configurable graphdoc document plugin",
"version": "1.0.0",
"description": "GraphQL documentation using configurable graphdoc document-schema plugin",
"version": "2.0.0-alpha",
"license": "MIT",

@@ -53,4 +53,3 @@ "author": "Gonzalo Müller Bravo",

"peerDependencies": {
"@2fd/graphdoc": "2.4.0",
"marked": "*"
"@2fd/graphdoc": "2.4.0"
},

@@ -57,0 +56,0 @@ "devDependencies": {

@@ -6,3 +6,3 @@ <p align="center">

<h1 align="center">GraphQL documentation using configurable graphdoc document plugin</h1>
<h1 align="center">GraphQL documentation using configurable graphdoc document-schema plugin</h1>

@@ -17,2 +17,3 @@ [![graphdoc-plugin-schema](https://badgen.net/badge/homepage/graphdoc-plugin-schema/blue)](https://graphdoc-plugins.github.io)

[![Gitlab repo](https://badgen.net/badge/icon/gitlab?icon=gitlab&label)](https://gitlab.com/gmullerb/graphdoc-plugin-schema)
__________________

@@ -27,7 +28,5 @@

```json
..
"devDependencies": {
"@2fd/graphdoc": "2.4.0",
"graphdoc-plugin-schema": "1.0.0",
..
"graphdoc-plugin-schema": "2.0.0",
```

@@ -43,3 +42,2 @@

"documentTitle": "The Description",
"extractDescription": false,
"enableAssets": false

@@ -54,7 +52,18 @@ }

```sh
graphdoc -p graphdoc/../../graphdoc-plugin-schema -s ./schema.GraphQL -o ./build/documentation
```json
"scripts": {
"doc": "graphdoc -p graphdoc/../../graphdoc-plugin-schema -p graphdoc/../../graphdoc-plugin-flexible -s ./schema.graphql -o ./build/documentation"
},
"graphdoc-plugin-flexible": {
"document.schema": { "disable": true }
},
"devDependencies": {
"@2fd/graphdoc": "2.4.0",
"graphdoc-plugin-flexible": "1.0.2",
"graphdoc-plugin-schema": "2.0.0",
```
> `graphdoc-plugin-flexible` is required to avoid duplication when graphdoc default plugins are used.
> `graphdoc/../../` this is required to get external plugins working in `graphdoc`.
__________________

@@ -64,3 +73,3 @@

`graphdoc-plugin-schema` provides a way to use [`graphdoc`](https://www.npmjs.com/package/@2fd/graphdoc) default `document-schema` plugin with other custom kinds without breaking (being also faster that `document-schema`).
`graphdoc-plugin-schema` provides a way to use [`graphdoc`](https://www.npmjs.com/package/@2fd/graphdoc) default `document-schema` plugin with other custom kinds without breaking (being also faster than `document-schema`).

@@ -77,3 +86,2 @@ ## Options

"documentTitle": "Description",
"extractDescription": true,
"enableAssets": true

@@ -85,14 +93,27 @@ }

* `documentTitle`: title of the document section.
* `extractDescription`: if set to `false`, then description of the type will be inside the "code block".
* Extracted description is render in a `div` with `class="x-desc"`.
* `enableAssets`: if set to `false`, then it will disable all the assets provided by the plugin, i.e. script and css files will not be included.
The following shows where `documentTitle` and "code block" are located, using the example created by [`graphdoc`](https://www.npmjs.com/package/@2fd/graphdoc), [Pokemon GraphQL](https://2fd.github.io/graphdoc/pokemon/pokemonattack.doc.html):
The following shows where the `documentTitle` and the "code block" are located, using the example documentation created by [`graphdoc`](https://www.npmjs.com/package/@2fd/graphdoc), [Pokemon GraphQL HTML Documentation](https://2fd.github.io/graphdoc/pokemon/pokemonattack.doc.html), using [Pokemon GraphQL schema](https://github.com/lucasbento/graphql-pokemon):
![Graphdoc sections](docs/graphdoc-sections.svg)
## Tips
## Using/Configuration
* When using `extractDescription: true`, you may want to remove `{{{description}}}` in `main.mustache` template in "title" section.
* To use `graphdoc-plugin-schema` is necessary that `document-schema` plugin is disabled (to avoid duplication), use [`graphdoc-plugin-flexible`](https://graphdoc-plugins.github.io) plugin:
`package.json`
```json
"scripts": {
"doc": "graphdoc -p graphdoc/../../graphdoc-plugin-schema -p graphdoc/../../graphdoc-plugin-flexible -s ./schema.graphql -o ./build/documentation"
},
"graphdoc-plugin-flexible": {
"document.schema": { "disable": true }
},
"devDependencies": {
"@2fd/graphdoc": "2.4.0",
"graphdoc-plugin-flexible": "1.0.2",
"graphdoc-plugin-schema": "2.0.0",
```
__________________

@@ -103,9 +124,13 @@

* [`"@2fd/graphdoc": "2.4.0"`](https://www.npmjs.com/package/@2fd/graphdoc/v/2.4.0).
* [`"marked": "*"`](https://www.npmjs.com/package/marked).
> graphdoc can work with older versions of GraphQL (description syntax: #), and new versions (description syntax: """), [How to configure graphdoc](https://graphdoc-plugins.github.io/docs/how-to-configure-graphdoc.html).
> `marked` is installed when `@2fd/graphdoc` is installed although a newer version can be used.
__________________
## Documentation
* [Main documentation](https://graphdoc-plugins.github.io/docs/graphdoc-plugin-schema.html).
* [`CHANGELOG`](CHANGELOG.html): contains the information about changes in each version, chronologically ordered ([Keep a Changelog](http://keepachangelog.com)).
## Contributing

@@ -115,5 +140,5 @@

* **Share it**.
* [Give it a Star](https://github.com/gmullerb/eslint-plugin-regex).
* [Propose changes or improvements](https://github.com/gmullerb/eslint-plugin-regex/issues).
* [Report bugs](https://github.com/gmullerb/eslint-plugin-regex/issues).
* [Give it a Star](https://github.com/gmullerb/graphdoc-plugin-schema).
* [Propose changes or improvements](https://github.com/gmullerb/graphdoc-plugin-schema/issues).
* [Report bugs](https://github.com/gmullerb/graphdoc-plugin-schema/issues).

@@ -123,2 +148,3 @@ ## License

[MIT License](LICENSE.txt)
__________________

@@ -125,0 +151,0 @@