UNPKG

annotated-graphql

Version:

Annotated GraphQL

73 lines (58 loc) 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Base class for schema annotations * * An annotation can be placed in the GraphQL schema at two different levels: * * Type: it will have typeName defined * * Field: it will have typeName and fieldName defined * * Note: argument level is not yet supported * */ var BaseSchemaAnnotation = function () { _createClass(BaseSchemaAnnotation, null, [{ key: "asArgumentsMap", value: function asArgumentsMap(argumentsList) { return argumentsList.reduce(function (argumentsMap, argument) { argumentsMap[argument.name] = argument.value; return argumentsMap; }, {}); } }]); function BaseSchemaAnnotation(tag, typeName, fieldName) { _classCallCheck(this, BaseSchemaAnnotation); // TODO: add validation this.tag = tag; this.typeName = typeName; this.fieldName = fieldName; } /** * This is a lifecycle method which is called to give this annotation the chance of generating a resolver * * @param resolvers current map of resolvers where to add new resolvers * @param resolversContext context object to be used by the resolvers */ _createClass(BaseSchemaAnnotation, [{ key: "onCreateResolver", value: function onCreateResolver(resolvers, resolversContext) {} // noop /** * This is a lifecycle method which is called to give this annotation the chance of modfiying the schema types * (i.e. adding documentation) * * @param schemaTypes map of the schema types to annotate */ }, { key: "onAnnotateTypes", value: function onAnnotateTypes(schemaTypes) { // noop } }]); return BaseSchemaAnnotation; }(); exports.default = BaseSchemaAnnotation;