microfiber
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -9,2 +9,3 @@ "use strict"; | ||
exports.isReservedType = isReservedType; | ||
exports.typesAreSame = typesAreSame; | ||
@@ -176,2 +177,3 @@ var _lodash = _interopRequireDefault(require("lodash.get")); | ||
this.mutationTypeName = (0, _lodash.default)(this.schema, 'mutationType.name'); | ||
this.subscriptionTypeName = (0, _lodash.default)(this.schema, 'subscriptionType.name'); | ||
@@ -302,6 +304,8 @@ for (let typesIdx = 0; typesIdx < this.schema.types.length; typesIdx++) { | ||
includeQuery = false, | ||
includeMutation = false | ||
includeMutation = false, | ||
includeSubscription = false | ||
} = {}) { | ||
const queryType = this.getQueryType(); | ||
const mutationType = this.getMutationType(); | ||
const subscriptionType = this.getSubscriptionType(); | ||
return this.schema.types.filter(type => { | ||
@@ -320,2 +324,6 @@ if (!includeReserved && isReservedType(type)) { | ||
if (subscriptionType && !includeSubscription && typesAreSame(type, subscriptionType)) { | ||
return false; | ||
} | ||
return true; | ||
@@ -395,2 +403,29 @@ }); | ||
getSubscriptionType() { | ||
if (!this.subscriptionTypeName) { | ||
return false; | ||
} | ||
return this.getType({ | ||
kind: KIND_OBJECT, | ||
name: this.subscriptionTypeName | ||
}); | ||
} | ||
getSubscription({ | ||
name | ||
}) { | ||
const subscriptionType = this.getSubscriptionType(); | ||
if (!subscriptionType) { | ||
return false; | ||
} | ||
return this.getField({ | ||
typeKind: subscriptionType.kind, | ||
typeName: subscriptionType.name, | ||
fieldName: name | ||
}); | ||
} | ||
getField({ | ||
@@ -428,5 +463,4 @@ typeKind = KIND_OBJECT, | ||
}); | ||
} // TODO: add test | ||
} | ||
getArg({ | ||
@@ -637,2 +671,18 @@ typeKind, | ||
removeSubscription({ | ||
name, | ||
cleanup = CLEANUP_DEFAULT | ||
}) { | ||
if (!this.subscriptionTypeName) { | ||
return false; | ||
} | ||
this.removeField({ | ||
typeKind: KIND_OBJECT, | ||
typeName: this.subscriptionTypeName, | ||
fieldName: name, | ||
cleanup | ||
}); | ||
} | ||
removeFieldsOfType({ | ||
@@ -738,3 +788,3 @@ kind, | ||
const typesEncountered = new Set(); | ||
const types = []; // The Query and Mutation Types should never be removed due to not being referenced | ||
const types = []; // The Query, Mutation and Subscription Types should never be removed due to not being referenced | ||
// by anything | ||
@@ -756,2 +806,9 @@ | ||
if (this.subscriptionTypeName) { | ||
typesEncountered.add(buildKey({ | ||
kind: KIND_OBJECT, | ||
name: this.subscriptionTypeName | ||
})); | ||
} | ||
for (const type of this.schema.types) { | ||
@@ -758,0 +815,0 @@ if (!type) { |
{ | ||
"name": "microfiber", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A library to query and manipulate GraphQL Introspection Query results in some useful ways.", | ||
@@ -35,3 +35,4 @@ "keywords": [ | ||
"pub:dry-run": "yarn prepare && npm publish --dry-run", | ||
"test": "mocha --config ./test/mocha-config.js" | ||
"test:watch": "nodemon -x 'yarn test' --ignore dist/", | ||
"test": "yarn prepare && yarn mocha --config ./test/mocha-config.js" | ||
}, | ||
@@ -55,4 +56,5 @@ "dependencies": { | ||
"mocha": "^9.2.1", | ||
"nodemon": "^2.0.15", | ||
"rimraf": "^3.0.2" | ||
} | ||
} |
25488
750
13