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

graphql-markdown

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-markdown - npm Package Compare versions

Comparing version 2.2.0 to 3.0.0-0

src/diffSchema.js

5

package.json
{
"name": "graphql-markdown",
"version": "2.2.0",
"version": "3.0.0-0",
"description": "Generate documentation for your GraphQL schema in Markdown",

@@ -27,3 +27,3 @@ "main": "src/index.js",

"test:only": "ava",
"test:update": "ava --update-snapshot"
"test:update": "ava --update-snapshots"
},

@@ -35,2 +35,3 @@ "pre-commit": [

"dependencies": {
"deep-diff": "^0.3.8",
"graphql": "^0.11.7",

@@ -37,0 +38,0 @@ "minimist": "^1.2.0",

37

README.md

@@ -16,2 +16,4 @@ [![npm version](https://img.shields.io/npm/v/graphql-markdown.svg)](https://www.npmjs.com/package/graphql-markdown)

### Command Line API
Installing the package adds a `graphql-markdown` script. Point it at a schema

@@ -44,3 +46,3 @@ and the output will be written to stdout.

### Options
#### Options

@@ -70,2 +72,35 @@ ```console

### Node API
The following functions are exported from the `graphql-markdown` module for
programmatic use.
#### loadSchemaJSON(schemaPath: string)
Given a string pointing to a GraphQL schema (URL, module, or file path), get the
result of the introspection query, suitable for use as input to `renderSchema`.
#### renderSchema(schema: object, options: object)
Given a schema JSON object (the output of the introspection query, an object
with a `__schema` property), render the schema to a string.
| Option | Description |
| ---------- | ----------- |
| `title` | The title of the document, defaults to “Schema Types”. |
| `prologue` | Markdown content to include after the title. |
| `epilogue` | Markdown content to include at the end of the document. |
| `printer` | A function to handle each line of output, defaults to `console.log`. |
#### diffSchema(oldSchema: object, newSchema: object, options: object)
Given two schema JSON objects (the results of the introspection query on two
schemas), return a new schema JSON object containing only the added or updated
types and fields. You can use this to document a schema update, or to document
the effects of a schema extension (e.g. `extend type` definitions).
| Option | Description |
| ----------------- | ----------- |
| `processTypeDiff` | A function to add or modify fields on each type that will be output. |
## Output

@@ -72,0 +107,0 @@

@@ -7,2 +7,3 @@ #!/usr/bin/env node

const renderSchema = require('./renderSchema')
const diffSchema = require('./diffSchema')

@@ -67,2 +68,6 @@ function safeExit (code) {

module.exports = { loadSchemaJSON, renderSchema }
module.exports = {
loadSchemaJSON,
renderSchema,
diffSchema
}

@@ -103,3 +103,5 @@ 'use strict'

const query = types.filter(type => type.name === schema.queryType.name)[0]
const queryType = schema.queryType
const query =
queryType && types.find(type => type.name === schema.queryType.name)
const objects = types.filter(type => type.kind === 'OBJECT' && type !== query)

@@ -123,80 +125,102 @@ const enums = types.filter(type => type.kind === 'ENUM')

printer(' <summary><strong>Table of Contents</strong></summary>\n')
printer(' * [Query](#query)')
printer(' * [Objects](#objects)')
objects.forEach(type => {
printer(` * [${type.name}](#${type.name.toLowerCase()})`)
})
printer(' * [Enums](#enums)')
enums.forEach(type => {
printer(` * [${type.name}](#${type.name.toLowerCase()})`)
})
printer(' * [Scalars](#scalars)')
scalars.forEach(type => {
printer(` * [${type.name}](#${type.name.toLowerCase()})`)
})
printer(' * [Interfaces](#interfaces)')
interfaces.forEach(type => {
printer(` * [${type.name}](#${type.name.toLowerCase()})`)
})
if (query) {
printer(' * [Query](#query)')
}
if (objects.length) {
printer(' * [Objects](#objects)')
objects.forEach(type => {
printer(` * [${type.name}](#${type.name.toLowerCase()})`)
})
}
if (enums.length) {
printer(' * [Enums](#enums)')
enums.forEach(type => {
printer(` * [${type.name}](#${type.name.toLowerCase()})`)
})
}
if (scalars.length) {
printer(' * [Scalars](#scalars)')
scalars.forEach(type => {
printer(` * [${type.name}](#${type.name.toLowerCase()})`)
})
}
if (interfaces.length) {
printer(' * [Interfaces](#interfaces)')
interfaces.forEach(type => {
printer(` * [${type.name}](#${type.name.toLowerCase()})`)
})
}
printer('\n</details>')
printer(`\n## Query ${query.name === 'Query' ? '' : '(' + query.name + ')'}`)
renderObject(query, { skipTitle: true, printer })
if (query) {
printer(
`\n## Query ${query.name === 'Query' ? '' : '(' + query.name + ')'}`
)
renderObject(query, { skipTitle: true, printer })
}
printer('\n## Objects')
objects.forEach(type => renderObject(type, { printer }))
if (objects.length) {
printer('\n## Objects')
objects.forEach(type => renderObject(type, { printer }))
}
printer('\n## Enums')
enums.forEach(type => {
printer(`\n### ${type.name}\n`)
if (type.description) {
printer(`${type.description}\n`)
}
printer('<table>')
printer('<thead>')
printer('<th align="left">Value</th>')
printer('<th align="left">Description</th>')
printer('</thead>')
printer('<tbody>')
type.enumValues.forEach(value => {
printer('<tr>')
printer(
`<td valign="top"><strong>${value.name}</strong>${value.isDeprecated
? ' ⚠️'
: ''}</td>`
)
if (value.description || value.isDeprecated) {
printer('<td>')
if (value.description) {
printer(`\n${value.description}\n`)
}
if (value.isDeprecated) {
printer('<p>⚠️ <strong>DEPRECATED</strong></p>')
if (value.deprecationReason) {
printer('<blockquote>')
printer(`\n${value.deprecationReason}\n`)
printer('</blockquote>')
if (enums.length) {
printer('\n## Enums')
enums.forEach(type => {
printer(`\n### ${type.name}\n`)
if (type.description) {
printer(`${type.description}\n`)
}
printer('<table>')
printer('<thead>')
printer('<th align="left">Value</th>')
printer('<th align="left">Description</th>')
printer('</thead>')
printer('<tbody>')
type.enumValues.forEach(value => {
printer('<tr>')
printer(
`<td valign="top"><strong>${value.name}</strong>${value.isDeprecated
? ' ⚠️'
: ''}</td>`
)
if (value.description || value.isDeprecated) {
printer('<td>')
if (value.description) {
printer(`\n${value.description}\n`)
}
if (value.isDeprecated) {
printer('<p>⚠️ <strong>DEPRECATED</strong></p>')
if (value.deprecationReason) {
printer('<blockquote>')
printer(`\n${value.deprecationReason}\n`)
printer('</blockquote>')
}
}
printer('</td>')
} else {
printer('<td></td>')
}
printer('</td>')
} else {
printer('<td></td>')
printer('</tr>')
})
printer('</tbody>')
printer('</table>')
})
}
if (scalars.length) {
printer('\n## Scalars\n')
scalars.forEach(type => {
printer(`### ${type.name}\n`)
if (type.description) {
printer(`${type.description}\n`)
}
printer('</tr>')
})
printer('</tbody>')
printer('</table>')
})
}
printer('\n## Scalars\n')
scalars.forEach(type => {
printer(`### ${type.name}\n`)
if (type.description) {
printer(`${type.description}\n`)
}
})
if (interfaces.length) {
printer('\n## Interfaces\n')
interfaces.forEach(type => renderObject(type, { printer }))
}
printer('\n## Interfaces\n')
interfaces.forEach(type => renderObject(type, { printer }))
if (epilogue) {

@@ -203,0 +227,0 @@ printer(`\n${epilogue}`)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc