microfiber
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -47,2 +47,3 @@ "use strict"; | ||
removePossibleTypesOfMissingTypes: true, | ||
removeDirectiveArgumentsOfMissingTypes: true, | ||
// TODO: implement | ||
@@ -62,3 +63,4 @@ // removeQueriesWithMissingTypes: true, | ||
removeInputFieldsWithMissingTypes: 'removeInputFieldsOfType', | ||
removePossibleTypesOfMissingTypes: 'removePossibleTypesOfType' | ||
removePossibleTypesOfMissingTypes: 'removePossibleTypesOfType', | ||
removeDirectiveArgumentsOfMissingTypes: 'removeDirectiveArgumentsOfType' | ||
}); | ||
@@ -190,2 +192,18 @@ const kindToFieldPropertyMap = Object.freeze({ | ||
getDirectives() { | ||
return this.schema.directives; | ||
} | ||
getDirective({ | ||
name | ||
}) { | ||
if (!name) { | ||
return; | ||
} | ||
return this.getDirectives()[this._getDirectiveIndex({ | ||
name | ||
})]; | ||
} | ||
getQueryType() { | ||
@@ -336,2 +354,32 @@ if (!this.queryTypeName) { | ||
getDirectiveArg({ | ||
directiveName, | ||
argName | ||
}) { | ||
const directive = this.getDirective({ | ||
name: directiveName | ||
}); | ||
if (!(directive && directive.args.length)) { | ||
return; | ||
} | ||
return directive.args.find(arg => arg.name === argName); | ||
} | ||
removeDirective({ | ||
name, | ||
cleanup = true | ||
}) { | ||
if (!name) { | ||
return; | ||
} | ||
this.schema.directives = this.schema.directives.filter(directive => directive.name !== name); | ||
if (cleanup) { | ||
this.cleanSchema(); | ||
} | ||
} | ||
removeType({ | ||
@@ -346,3 +394,4 @@ kind = _etc.KINDS.OBJECT, | ||
removePossibleTypesOfType, | ||
removeArgsOfType | ||
removeArgsOfType, | ||
removeDirectiveArgumentsOfType | ||
}) { | ||
@@ -376,3 +425,4 @@ const typeKey = buildKey({ | ||
removePossibleTypesOfType, | ||
removeArgsOfType | ||
removeArgsOfType, | ||
removeDirectiveArgumentsOfType | ||
}, mappedOpts); // If we are going to clean up afterwards, then the others should not have to | ||
@@ -444,2 +494,10 @@ | ||
if (mergedOpts.removeDirectiveArgumentsOfType) { | ||
this._removeDirectiveArgumentsOfType({ | ||
kind, | ||
name, | ||
cleanup: shouldOthersClean | ||
}); | ||
} | ||
if (cleanup) { | ||
@@ -651,2 +709,24 @@ this.cleanSchema(); | ||
for (const directive of this.schema.directives) { | ||
if (!directive) { | ||
continue; | ||
} | ||
const args = []; | ||
for (const arg of directive.args) { | ||
const argType = digUnderlyingType(arg.type); // Don't add it if its return type does not exist | ||
if (!this._hasType(argType)) { | ||
continue; | ||
} // Keep track of this so we know what we can remove | ||
typesEncountered.add(buildKey(argType)); | ||
args.push(arg); | ||
} | ||
directive.args = args; | ||
} | ||
for (const type of this.schema.types) { | ||
@@ -817,3 +897,5 @@ if (!type) { | ||
this.possibleTypesOfTypeMap = {}; | ||
this.argsOfTypeMap = {}; // Need to keep track of these so that we never remove them for not being referenced | ||
this.argsOfTypeMap = {}; | ||
this.directiveToIndexMap = {}; | ||
this.directiveArgsOfTypeMap = {}; // Need to keep track of these so that we never remove them for not being referenced | ||
@@ -824,2 +906,35 @@ this.queryTypeName = (0, _lodash.default)(this.schema, 'queryType.name'); | ||
for (let directivesIdx = 0; directivesIdx < this.schema.directives.length; directivesIdx++) { | ||
const directive = this.schema.directives[directivesIdx]; | ||
if (isUndef(directive)) { | ||
continue; | ||
} | ||
const directivesKey = buildKey({ | ||
kind: 'DIRECTIVE', | ||
name: directive.name | ||
}); | ||
this.directiveToIndexMap[directivesKey] = directivesIdx; | ||
const directivePath = `directives.${directivesIdx}`; | ||
for (let argsIdx = 0; argsIdx < directive.args.length; argsIdx++) { | ||
const arg = directive.args[argsIdx]; | ||
if (isUndef(arg)) { | ||
continue; | ||
} | ||
const argType = digUnderlyingType(arg.type); | ||
const argsKey = buildKey(argType); | ||
if (!this.directiveArgsOfTypeMap[argsKey]) { | ||
this.directiveArgsOfTypeMap[argsKey] = []; | ||
} | ||
const argPath = `${directivePath}.args.${argsIdx}`; | ||
this.directiveArgsOfTypeMap[argsKey].push(argPath); | ||
} | ||
} | ||
for (let typesIdx = 0; typesIdx < this.schema.types.length; typesIdx++) { | ||
@@ -953,2 +1068,17 @@ const type = this.schema.types[typesIdx]; | ||
_getDirectiveIndex({ | ||
name | ||
}) { | ||
const key = buildKey({ | ||
kind: 'DIRECTIVE', | ||
name | ||
}); | ||
if (Object.prototype.hasOwnProperty.call(this.directiveToIndexMap, key)) { | ||
return this.directiveToIndexMap[key]; | ||
} | ||
return false; | ||
} | ||
_removeThingsOfType({ | ||
@@ -1033,2 +1163,16 @@ kind, | ||
_removeDirectiveArgumentsOfType({ | ||
// kind, | ||
name, | ||
// Clean up the schema afterwards? | ||
cleanup = true | ||
}) { | ||
return this._removeThingsOfType({ | ||
kind: 'DIRECTIVE', | ||
name, | ||
map: this.directiveArgsOfTypeMap, | ||
cleanup | ||
}); | ||
} | ||
_cloneSchema() { | ||
@@ -1035,0 +1179,0 @@ return JSON.parse(JSON.stringify(this.schema)); |
{ | ||
"name": "microfiber", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "A library to query and manipulate GraphQL Introspection Query results in some useful ways.", | ||
@@ -5,0 +5,0 @@ "author": "Chris Newhouse", |
@@ -132,3 +132,3 @@ <a href="https://www.useanvil.com"><img src="/static/anvil.png" width="50"></a> | ||
#### getType | ||
Get a specific Type from yoyur schema. Supported params and their sane defaults are shown. | ||
Get a specific Type from your schema. Supported params and their sane defaults are shown. | ||
```node | ||
@@ -138,2 +138,14 @@ const type = microfiber.getType({ kind: 'OBJECT', name }) | ||
--- | ||
#### getDirectives | ||
Get all the Directives from your schema. | ||
```node | ||
const directives = microfiber.getDirectives() | ||
``` | ||
--- | ||
#### getDirective | ||
Get a specific Directive from your schema. Supported params and their sane defaults are shown. | ||
```node | ||
const directive = microfiber.getDirective({ name }) | ||
``` | ||
--- | ||
#### getQueryType | ||
@@ -199,2 +211,18 @@ Get the Query Type from your schema. | ||
--- | ||
#### getDirectiveArg | ||
Get a specific Arg from a specifig Directive in your schema. Supported params and their sane defaults are shown. | ||
```node | ||
const directiveArg = microfiber.getDirectiveArg({ directiveName, argName }) | ||
``` | ||
--- | ||
#### removeDirective | ||
Get a specific Directive from your schema. Supported params and their sane defaults are shown. | ||
```node | ||
const directiveArg = microfiber.removeDirective({ | ||
name, | ||
// Clean up the schema afterwards? | ||
cleanup = true, | ||
}) | ||
``` | ||
--- | ||
#### removeType | ||
@@ -201,0 +229,0 @@ Remove a Type from your schema, and optionally the references to that Type elsewhere in your schema. Supported params and their sane defaults are shown. |
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
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
47054
1032
405