Comparing version 2.1.1 to 2.2.0-beta.0
@@ -187,2 +187,3 @@ "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.addExamples = addExamples;exports.augmentData = augmentData;exports.calculateShouldDocument = void 0;exports.createIntrospectionManipulator = createIntrospectionManipulator;exports.hideThingsBasedOnMetadata = hideThingsBasedOnMetadata;exports.removeTrailingPeriodsFromDescriptions = removeTrailingPeriodsFromDescriptions;var _lodash = _interopRequireDefault(require("lodash")); | ||
fieldDocumentedDefault; | ||
if (queryType && (0, _microfiber.typesAreSame)(type, queryType)) { | ||
@@ -197,3 +198,6 @@ defaultShowHide = !!queryDocumentedDefault; | ||
for (const field of type.fields || type.inputFields || []) { | ||
for (const field of type.fields || | ||
type.inputFields || | ||
type.enumValues || | ||
[]) { | ||
const metadata = _lodash.default.get(field, metadatasPath, {}); | ||
@@ -200,0 +204,0 @@ const shouldDocument = calculateShouldDocument({ |
@@ -132,2 +132,22 @@ "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.addMetadataFromDirectables = exports.DEFAULT_DIRECTIVE_OPTION_NAME = exports.DEFAULT_DIRECTIVE_NAME = void 0;exports.generateDirectiveSdl = generateDirectiveSdl;exports.generateOptionsSdl = generateOptionsSdl;exports.generateSpectaqlDirectiveSupport = generateSpectaqlDirectiveSupport;exports.generateSpectaqlSdl = generateSpectaqlSdl;var _isEmpty = _interopRequireDefault(require("lodash/isEmpty")); | ||
function enumValueHandler( | ||
config, | ||
typeName, | ||
schema, | ||
externalValue, | ||
mapperKind) | ||
{var _getDirective3; | ||
const directive = (_getDirective3 = (0, _utils.getDirective)(schema, config, 'spectaql')) === null || _getDirective3 === void 0 ? void 0 : _getDirective3[0]; | ||
if (!(0, _isEmpty.default)(directive)) { | ||
directables.push({ | ||
directive: processDirective(directive), | ||
config, | ||
typeName, | ||
externalValue, | ||
mapperKind | ||
}); | ||
} | ||
} | ||
const HANDLER_MAP = { | ||
@@ -159,3 +179,3 @@ [_utils.MapperKind.TYPE]: (...args) => typeHandler(...args, _utils.MapperKind.TYPE), | ||
[_utils.MapperKind.ENUM_VALUE]: (...args) => | ||
typeHandler(...args, _utils.MapperKind.ENUM_VALUE), | ||
enumValueHandler(...args, _utils.MapperKind.ENUM_VALUE), | ||
[_utils.MapperKind.FIELD]: (...args) => configHandler(...args, _utils.MapperKind.FIELD), | ||
@@ -200,3 +220,4 @@ [_utils.MapperKind.OBJECT_FIELD]: (...args) => | ||
[_utils.MapperKind.SUBSCRIPTION_ROOT_FIELD]: _microfiber.KINDS.OBJECT, | ||
[_utils.MapperKind.INTERFACE_FIELD]: _microfiber.KINDS.INTERFACE | ||
[_utils.MapperKind.INTERFACE_FIELD]: _microfiber.KINDS.INTERFACE, | ||
[_utils.MapperKind.ENUM_VALUE]: _microfiber.KINDS.ENUM | ||
}); | ||
@@ -283,2 +304,26 @@ | ||
}); | ||
}, | ||
EnumValueDefinition: ({ | ||
type, | ||
config, | ||
typeName, | ||
externalValue, | ||
mapperKind | ||
}) => { | ||
const typeKind = MAPPER_KIND_TO_KIND_MAP[mapperKind]; | ||
if (!typeKind) { | ||
console.error(new Error('Unsupported mapperKind'), { | ||
type, | ||
config, | ||
mapperKind, | ||
typeName, | ||
externalValue | ||
}); | ||
return; | ||
} | ||
return microfiber.getField({ | ||
typeKind, | ||
typeName, | ||
fieldName: externalValue | ||
}); | ||
} | ||
@@ -293,2 +338,3 @@ }; | ||
typeName, | ||
externalValue, | ||
mapperKind | ||
@@ -302,2 +348,3 @@ } of directables) { | ||
const astNode = (type || config).astNode; | ||
const fn = map[astNode.kind]; | ||
@@ -310,2 +357,3 @@ if (fn) { | ||
fieldName, | ||
externalValue, | ||
mapperKind, | ||
@@ -322,2 +370,4 @@ astNode | ||
fieldName, | ||
externalValue, | ||
mapperKind, | ||
astNode | ||
@@ -332,2 +382,3 @@ }); | ||
fieldName, | ||
externalValue, | ||
astNode | ||
@@ -334,0 +385,0 @@ }); |
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.TMP_PREFIX = void 0;exports.absoluteURL = absoluteURL;exports.camelCase = camelCase;exports.capitalize = capitalize;exports.capitalizeFirstLetter = capitalizeFirstLetter;exports.dynamicImport = dynamicImport;exports.fileExists = fileExists;exports.fileExtensionIs = fileExtensionIs;exports.fileToObject = fileToObject;exports.firstNonUndef = firstNonUndef;exports.isUndef = isUndef;exports.join = join;exports.lowerCase = lowerCase;exports.normalizePathFromCwd = normalizePathFromCwd;exports.normalizePathFromRoot = normalizePathFromRoot;exports.pathToRoot = void 0;exports.readJSFile = readJSFile;exports.readJSONFile = readJSONFile;exports.readTextFile = readTextFile;exports.relative = relative;exports.snakeCase = snakeCase;exports.takeDefaultExport = takeDefaultExport;exports.tmpFolder = tmpFolder;exports.upperCase = upperCase;exports.urlBasename = urlBasename;exports.writeTextFile = writeTextFile;var _path = _interopRequireDefault(require("path")); | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _lodash = _interopRequireDefault(require("lodash")); | ||
var _tmp = _interopRequireDefault(require("tmp"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} | ||
var _tmp = _interopRequireDefault(require("tmp")); | ||
var _json = _interopRequireDefault(require("json5"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} | ||
@@ -101,3 +102,3 @@ | ||
} | ||
return JSON.parse(readTextFile(pth, optionsForReadJSONParse)); | ||
return _json.default.parse(readTextFile(pth, optionsForReadJSONParse)); | ||
} | ||
@@ -104,0 +105,0 @@ |
{ | ||
"name": "spectaql", | ||
"version": "2.1.1", | ||
"version": "2.2.0-beta.0", | ||
"description": "A powerful library for autogenerating static GraphQL API documentation", | ||
@@ -5,0 +5,0 @@ "author": "Anvil Foundry Inc. <hello@useanvil.com>", |
@@ -187,2 +187,3 @@ import _ from 'lodash' | ||
: fieldDocumentedDefault | ||
if (queryType && typesAreSame(type, queryType)) { | ||
@@ -197,3 +198,6 @@ defaultShowHide = !!queryDocumentedDefault | ||
// Handle OBJECT.fields AND INPUT_OBJECT.inputFields | ||
for (const field of type.fields || type.inputFields || []) { | ||
for (const field of type.fields || | ||
type.inputFields || | ||
type.enumValues || | ||
[]) { | ||
const metadata = _.get(field, metadatasPath, {}) | ||
@@ -200,0 +204,0 @@ const shouldDocument = calculateShouldDocument({ |
@@ -132,2 +132,22 @@ import isEmpty from 'lodash/isEmpty' | ||
function enumValueHandler( | ||
config, | ||
typeName, | ||
schema, | ||
externalValue, | ||
mapperKind | ||
) { | ||
const directive = getDirective(schema, config, 'spectaql')?.[0] | ||
if (!isEmpty(directive)) { | ||
directables.push({ | ||
directive: processDirective(directive), | ||
config, | ||
typeName, | ||
externalValue, | ||
mapperKind, | ||
}) | ||
} | ||
} | ||
const HANDLER_MAP = { | ||
@@ -159,3 +179,3 @@ [MapperKind.TYPE]: (...args) => typeHandler(...args, MapperKind.TYPE), | ||
[MapperKind.ENUM_VALUE]: (...args) => | ||
typeHandler(...args, MapperKind.ENUM_VALUE), | ||
enumValueHandler(...args, MapperKind.ENUM_VALUE), | ||
[MapperKind.FIELD]: (...args) => configHandler(...args, MapperKind.FIELD), | ||
@@ -201,2 +221,3 @@ [MapperKind.OBJECT_FIELD]: (...args) => | ||
[MapperKind.INTERFACE_FIELD]: KINDS.INTERFACE, | ||
[MapperKind.ENUM_VALUE]: KINDS.ENUM, | ||
}) | ||
@@ -284,2 +305,26 @@ | ||
}, | ||
EnumValueDefinition: ({ | ||
type, | ||
config, | ||
typeName, | ||
externalValue, | ||
mapperKind, | ||
}) => { | ||
const typeKind = MAPPER_KIND_TO_KIND_MAP[mapperKind] | ||
if (!typeKind) { | ||
console.error(new Error('Unsupported mapperKind'), { | ||
type, | ||
config, | ||
mapperKind, | ||
typeName, | ||
externalValue, | ||
}) | ||
return | ||
} | ||
return microfiber.getField({ | ||
typeKind, | ||
typeName, | ||
fieldName: externalValue, | ||
}) | ||
}, | ||
} | ||
@@ -293,2 +338,3 @@ | ||
typeName, | ||
externalValue, | ||
mapperKind, | ||
@@ -302,2 +348,3 @@ } of directables) { | ||
const astNode = (type || config).astNode | ||
const fn = map[astNode.kind] | ||
@@ -310,2 +357,3 @@ if (fn) { | ||
fieldName, | ||
externalValue, | ||
mapperKind, | ||
@@ -322,2 +370,4 @@ astNode, | ||
fieldName, | ||
externalValue, | ||
mapperKind, | ||
astNode, | ||
@@ -332,2 +382,3 @@ }) | ||
fieldName, | ||
externalValue, | ||
astNode, | ||
@@ -334,0 +385,0 @@ }) |
@@ -5,2 +5,3 @@ import path from 'path' | ||
import tmp from 'tmp' | ||
import JSON5 from 'json5' | ||
@@ -102,3 +103,3 @@ // Ensures temporary files are cleaned up on program close, even if errors are encountered. | ||
} | ||
return JSON.parse(readTextFile(pth, optionsForReadJSONParse)) | ||
return JSON5.parse(readTextFile(pth, optionsForReadJSONParse)) | ||
} | ||
@@ -105,0 +106,0 @@ |
@@ -42,2 +42,8 @@ import _ from 'lodash' | ||
enum MyEnum { | ||
ENUM1 | ||
ENUM2 | ||
ENUM3 | ||
} | ||
type UnusedType { | ||
@@ -280,2 +286,3 @@ id: String | ||
// These are the plural versions in case it's hard to tell/read | ||
context( | ||
@@ -285,2 +292,3 @@ 'objectsDocumentedDefault and unionsDocumentedDefault and inputsDocumentedDefault is false', | ||
def('objectsDocumentedDefault', false) | ||
def('enumsDocumentedDefault', false) | ||
def('unionsDocumentedDefault', false) | ||
@@ -301,3 +309,3 @@ def('inputsDocumentedDefault', false) | ||
def('metadata', () => { | ||
return _.set($.metadataBase, 'OBJECT.MyType.documentation', { | ||
return _.set($.metadataBase, `OBJECT.MyType.${$.metadatasPath}`, { | ||
documented: true, | ||
@@ -320,6 +328,8 @@ }) | ||
// These are the singular versions in case it's hard to tell/read | ||
context( | ||
'objectDocumentedDefault and unionDocumentedDefault and inputDocumentedDefault is false', | ||
'objectDocumentedDefault and enumDocumentedDefault and unionDocumentedDefault and inputDocumentedDefault is false', | ||
function () { | ||
def('objectDocumentedDefault', false) | ||
def('enumDocumentedDefault', false) | ||
def('unionDocumentedDefault', false) | ||
@@ -457,3 +467,3 @@ def('inputDocumentedDefault', false) | ||
describe('Fields', function () { | ||
describe('Fields/EnumValues', function () { | ||
afterEach(() => { | ||
@@ -524,2 +534,21 @@ // Make sure it does not mess up Query or Mutation | ||
).to.be.ok | ||
expect( | ||
$.introspectionManipulator.getEnumValue({ | ||
typeName: 'MyEnum', | ||
fieldName: 'ENUM1', | ||
}) | ||
).to.be.ok | ||
expect( | ||
$.introspectionManipulator.getEnumValue({ | ||
typeName: 'MyEnum', | ||
fieldName: 'ENUM2', | ||
}) | ||
).to.be.ok | ||
expect( | ||
$.introspectionManipulator.getEnumValue({ | ||
typeName: 'MyEnum', | ||
fieldName: 'ENUM3', | ||
}) | ||
).to.be.ok | ||
}) | ||
@@ -578,2 +607,51 @@ | ||
}) | ||
describe('enumValues', function () { | ||
context( | ||
'metadata directive says MyEnum.ENUM2 should NOT be documented', | ||
function () { | ||
def('metadata', () => { | ||
return _.set( | ||
$.metadataBase, | ||
`ENUM.MyEnum.enumValues.ENUM2.${$.metadatasPath}`, | ||
{ undocumented: true } | ||
) | ||
}) | ||
it('only documents the other enumValues', function () { | ||
const responseBefore = _.cloneDeep($.introspectionResponse) | ||
const response = $.response | ||
expect(response).to.not.eql(responseBefore) | ||
const enumValues = $.introspectionManipulator.getType({ | ||
kind: KINDS.ENUM, | ||
name: 'MyEnum', | ||
}).enumValues | ||
// Only ENUM1 and ENUM3 are there | ||
expect(enumValues).to.be.an('array').of.length(2) | ||
expect(enumValues.map((enumValue) => enumValue.name)).to.eql([ | ||
'ENUM1', | ||
'ENUM3', | ||
]) | ||
for (const enumValue of ['ENUM1', 'ENUM3']) { | ||
const enumValueDef = $.introspectionManipulator.getEnumValue({ | ||
typeName: 'MyEnum', | ||
fieldName: enumValue, | ||
}) | ||
expect(enumValueDef).to.be.ok | ||
expect(enumValueDef.name).to.eql(enumValue) | ||
} | ||
expect( | ||
$.introspectionManipulator.getEnumValue({ | ||
typeName: 'MyEnum', | ||
fieldName: 'ENUM2', | ||
}) | ||
).to.not.be.ok | ||
}) | ||
} | ||
) | ||
}) | ||
}) | ||
@@ -580,0 +658,0 @@ |
@@ -68,3 +68,3 @@ import { | ||
) | ||
expect(directables).to.be.an('array').of.length(23) | ||
expect(directables).to.be.an('array').of.length(24) | ||
}) | ||
@@ -71,0 +71,0 @@ }) |
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8120252
547
30756
1
1