Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-transformer-core

Package Overview
Dependencies
Maintainers
2
Versions
988
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-transformer-core - npm Package Compare versions

Comparing version 1.1.0-alpha.694cc790 to 1.1.0-alpha.69cfb43a

106

CHANGELOG.md

@@ -6,2 +6,108 @@ # Change Log

<a name="1.0.33"></a>
## [1.0.33](https://github.com/aws-amplify/amplify-cli/compare/graphql-transformer-core@1.0.33-beta.0...graphql-transformer-core@1.0.33) (2018-11-09)
**Note:** Version bump only for package graphql-transformer-core
<a name="1.0.33-beta.0"></a>
## [1.0.33-beta.0](https://github.com/aws-amplify/amplify-cli/compare/graphql-transformer-core@1.0.12...graphql-transformer-core@1.0.33-beta.0) (2018-11-09)
### Bug Fixes
* **graphql-transformer-core:** Fix Readme.md docs for the `[@auth](https://github.com/auth)` directive ([db6ff7a](https://github.com/aws-amplify/amplify-cli/commit/db6ff7a))
<a name="1.0.32"></a>
## [1.0.32](https://github.com/aws-amplify/amplify-cli/compare/graphql-transformer-core@1.0.32-beta.0...graphql-transformer-core@1.0.32) (2018-11-05)
**Note:** Version bump only for package graphql-transformer-core
<a name="1.0.32-beta.0"></a>
## [1.0.32-beta.0](https://github.com/aws-amplify/amplify-cli/compare/graphql-transformer-core@1.0.12...graphql-transformer-core@1.0.32-beta.0) (2018-11-05)
### Bug Fixes
* **graphql-transformer-core:** Fix Readme.md docs for the `[@auth](https://github.com/auth)` directive ([db6ff7a](https://github.com/aws-amplify/amplify-cli/commit/db6ff7a))
<a name="1.0.31"></a>
## [1.0.31](https://github.com/aws-amplify/amplify-cli/compare/graphql-transformer-core@1.0.12...graphql-transformer-core@1.0.31) (2018-11-02)
### Bug Fixes
* **graphql-transformer-core:** Fix Readme.md docs for the `[@auth](https://github.com/auth)` directive ([db6ff7a](https://github.com/aws-amplify/amplify-cli/commit/db6ff7a))
<a name="1.0.30"></a>
## [1.0.30](https://github.com/aws-amplify/amplify-cli/compare/graphql-transformer-core@1.0.30-beta.0...graphql-transformer-core@1.0.30) (2018-11-02)
**Note:** Version bump only for package graphql-transformer-core
<a name="1.0.30-beta.0"></a>
## [1.0.30-beta.0](https://github.com/aws-amplify/amplify-cli/compare/graphql-transformer-core@1.0.12...graphql-transformer-core@1.0.30-beta.0) (2018-11-02)
### Bug Fixes
* **graphql-transformer-core:** Fix Readme.md docs for the `[@auth](https://github.com/auth)` directive ([db6ff7a](https://github.com/aws-amplify/amplify-cli/commit/db6ff7a))
<a name="1.0.29"></a>
## [1.0.29](https://github.com/aws-amplify/amplify-cli/compare/graphql-transformer-core@1.0.29-beta.0...graphql-transformer-core@1.0.29) (2018-10-23)
**Note:** Version bump only for package graphql-transformer-core
<a name="1.0.29-beta.0"></a>
## [1.0.29-beta.0](https://github.com/aws-amplify/amplify-cli/compare/graphql-transformer-core@1.0.12...graphql-transformer-core@1.0.29-beta.0) (2018-10-23)
### Bug Fixes
* **graphql-transformer-core:** Fix Readme.md docs for the `[@auth](https://github.com/auth)` directive ([db6ff7a](https://github.com/aws-amplify/amplify-cli/commit/db6ff7a))
<a name="1.0.28"></a>
## [1.0.28](https://github.com/aws-amplify/amplify-cli/compare/graphql-transformer-core@1.0.28-beta.0...graphql-transformer-core@1.0.28) (2018-10-18)
**Note:** Version bump only for package graphql-transformer-core
<a name="1.0.28-beta.0"></a>
## [1.0.28-beta.0](https://github.com/aws-amplify/amplify-cli/compare/graphql-transformer-core@1.0.12...graphql-transformer-core@1.0.28-beta.0) (2018-10-12)
### Bug Fixes
* **graphql-transformer-core:** Fix Readme.md docs for the `[@auth](https://github.com/auth)` directive ([db6ff7a](https://github.com/aws-amplify/amplify-cli/commit/db6ff7a))
<a name="1.0.12"></a>

@@ -8,0 +114,0 @@ ## [1.0.12](https://github.com/aws-amplify/amplify-cli/compare/graphql-transformer-core@1.0.11...graphql-transformer-core@1.0.12) (2018-08-23)

362

lib/GraphQLTransform.js

@@ -37,2 +37,5 @@ "use strict";

function matchDirective(definition, directive, node) {
if (!directive) {
return false;
}
if (definition.name.value !== directive.name.value) {

@@ -173,3 +176,3 @@ // The definition is for the wrong directive. Do not match.

return (__assign({}, acc, (_a = {}, _a[t.directive.name.value] = true, _a)));
}, { aws_subscribe: true });
}, { aws_subscribe: true, aws_auth: true });
var allModelDefinitions = context.inputDocument.definitions.slice();

@@ -195,31 +198,25 @@ for (var _i = 0, _a = this.transformers; _i < _a.length; _i++) {

var def = _e[_d];
for (var _f = 0, _g = def.directives; _f < _g.length; _f++) {
var dir = _g[_f];
if (!validDirectiveNameMap[dir.name.value]) {
throw new errors_1.UnknownDirectiveError("Unknown directive '" + dir.name.value + "'. Either remove the directive from the schema or add a transformer to handle it.");
}
switch (def.kind) {
case 'ObjectTypeDefinition':
this.transformObject(transformer, def, dir, context);
// Walk the fields and call field transformers.
break;
case 'InterfaceTypeDefinition':
this.transformInterface(transformer, def, dir, context);
// Walk the fields and call field transformers.
break;
case 'ScalarTypeDefinition':
this.transformScalar(transformer, def, dir, context);
break;
case 'UnionTypeDefinition':
this.transformUnion(transformer, def, dir, context);
break;
case 'EnumTypeDefinition':
this.transformEnum(transformer, def, dir, context);
break;
case 'InputObjectTypeDefinition':
this.transformInputObject(transformer, def, dir, context);
break;
default:
continue;
}
switch (def.kind) {
case 'ObjectTypeDefinition':
this.transformObject(transformer, def, validDirectiveNameMap, context);
// Walk the fields and call field transformers.
break;
case 'InterfaceTypeDefinition':
this.transformInterface(transformer, def, validDirectiveNameMap, context);
// Walk the fields and call field transformers.
break;
case 'ScalarTypeDefinition':
this.transformScalar(transformer, def, validDirectiveNameMap, context);
break;
case 'UnionTypeDefinition':
this.transformUnion(transformer, def, validDirectiveNameMap, context);
break;
case 'EnumTypeDefinition':
this.transformEnum(transformer, def, validDirectiveNameMap, context);
break;
case 'InputObjectTypeDefinition':
this.transformInputObject(transformer, def, validDirectiveNameMap, context);
break;
default:
continue;
}

@@ -245,175 +242,220 @@ }

};
GraphQLTransform.prototype.transformObject = function (transformer, def, dir, context) {
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.object)) {
var transformKey = makeSeenTransformationKey(dir, def);
if (!this.seenTransformations[transformKey]) {
transformer.object(def, dir, context);
this.seenTransformations[transformKey] = true;
GraphQLTransform.prototype.transformObject = function (transformer, def, validDirectiveNameMap, context) {
for (var _i = 0, _a = def.directives; _i < _a.length; _i++) {
var dir = _a[_i];
if (!validDirectiveNameMap[dir.name.value]) {
throw new errors_1.UnknownDirectiveError("Unknown directive '" + dir.name.value + "'. Either remove the directive from the schema or add a transformer to handle it.");
}
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.object)) {
var transformKey = makeSeenTransformationKey(dir, def);
if (!this.seenTransformations[transformKey]) {
transformer.object(def, dir, context);
this.seenTransformations[transformKey] = true;
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'object()' method");
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'object()' method");
}
}
for (var _i = 0, _a = def.fields; _i < _a.length; _i++) {
var field = _a[_i];
for (var _b = 0, _c = field.directives; _b < _c.length; _b++) {
var fDir = _c[_b];
this.transformField(transformer, def, field, fDir, context);
}
for (var _b = 0, _c = def.fields; _b < _c.length; _b++) {
var field = _c[_b];
this.transformField(transformer, def, field, validDirectiveNameMap, context);
}
};
GraphQLTransform.prototype.transformField = function (transformer, parent, def, dir, context) {
if (matchFieldDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.field)) {
var transformKey = makeSeenTransformationKey(dir, parent, def);
if (!this.seenTransformations[transformKey]) {
transformer.field(parent, def, dir, context);
this.seenTransformations[transformKey] = true;
GraphQLTransform.prototype.transformField = function (transformer, parent, def, validDirectiveNameMap, context) {
for (var _i = 0, _a = def.directives; _i < _a.length; _i++) {
var dir = _a[_i];
if (!validDirectiveNameMap[dir.name.value]) {
throw new errors_1.UnknownDirectiveError("Unknown directive '" + dir.name.value + "'. Either remove the directive from the schema or add a transformer to handle it.");
}
if (matchFieldDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.field)) {
var transformKey = makeSeenTransformationKey(dir, parent, def);
if (!this.seenTransformations[transformKey]) {
transformer.field(parent, def, dir, context);
this.seenTransformations[transformKey] = true;
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'field()' method");
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'field()' method");
}
}
for (var _i = 0, _a = def.arguments; _i < _a.length; _i++) {
var arg = _a[_i];
for (var _b = 0, _c = arg.directives; _b < _c.length; _b++) {
var aDir = _c[_b];
this.transformArgument(transformer, parent, def, arg, aDir, context);
}
for (var _b = 0, _c = def.arguments; _b < _c.length; _b++) {
var arg = _c[_b];
this.transformArgument(transformer, parent, def, arg, validDirectiveNameMap, context);
}
};
GraphQLTransform.prototype.transformArgument = function (transformer, parent, field, arg, dir, context) {
if (matchArgumentDirective(transformer.directive, dir, arg)) {
if (isFunction(transformer.argument)) {
var transformKey = makeSeenTransformationKey(dir, parent, field, arg);
if (!this.seenTransformations[transformKey]) {
transformer.argument(arg, dir, context);
this.seenTransformations[transformKey] = true;
GraphQLTransform.prototype.transformArgument = function (transformer, parent, field, arg, validDirectiveNameMap, context) {
for (var _i = 0, _a = arg.directives; _i < _a.length; _i++) {
var dir = _a[_i];
if (!validDirectiveNameMap[dir.name.value]) {
throw new errors_1.UnknownDirectiveError("Unknown directive '" + dir.name.value + "'. Either remove the directive from the schema or add a transformer to handle it.");
}
if (matchArgumentDirective(transformer.directive, dir, arg)) {
if (isFunction(transformer.argument)) {
var transformKey = makeSeenTransformationKey(dir, parent, field, arg);
if (!this.seenTransformations[transformKey]) {
transformer.argument(arg, dir, context);
this.seenTransformations[transformKey] = true;
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'argument()' method");
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'argument()' method");
}
}
};
GraphQLTransform.prototype.transformInterface = function (transformer, def, dir, context) {
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.interface)) {
var transformKey = makeSeenTransformationKey(dir, def);
if (!this.seenTransformations[transformKey]) {
transformer.interface(def, dir, context);
this.seenTransformations[transformKey] = true;
GraphQLTransform.prototype.transformInterface = function (transformer, def, validDirectiveNameMap, context) {
for (var _i = 0, _a = def.directives; _i < _a.length; _i++) {
var dir = _a[_i];
if (!validDirectiveNameMap[dir.name.value]) {
throw new errors_1.UnknownDirectiveError("Unknown directive '" + dir.name.value + "'. Either remove the directive from the schema or add a transformer to handle it.");
}
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.interface)) {
var transformKey = makeSeenTransformationKey(dir, def);
if (!this.seenTransformations[transformKey]) {
transformer.interface(def, dir, context);
this.seenTransformations[transformKey] = true;
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'interface()' method");
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'interface()' method");
}
}
for (var _i = 0, _a = def.fields; _i < _a.length; _i++) {
var field = _a[_i];
for (var _b = 0, _c = field.directives; _b < _c.length; _b++) {
var fDir = _c[_b];
this.transformField(transformer, def, field, fDir, context);
}
for (var _b = 0, _c = def.fields; _b < _c.length; _b++) {
var field = _c[_b];
this.transformField(transformer, def, field, validDirectiveNameMap, context);
}
};
GraphQLTransform.prototype.transformScalar = function (transformer, def, dir, context) {
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.scalar)) {
var transformKey = makeSeenTransformationKey(dir, def);
if (!this.seenTransformations[transformKey]) {
transformer.scalar(def, dir, context);
this.seenTransformations[transformKey] = true;
GraphQLTransform.prototype.transformScalar = function (transformer, def, validDirectiveNameMap, context) {
for (var _i = 0, _a = def.directives; _i < _a.length; _i++) {
var dir = _a[_i];
if (!validDirectiveNameMap[dir.name.value]) {
throw new errors_1.UnknownDirectiveError("Unknown directive '" + dir.name.value + "'. Either remove the directive from the schema or add a transformer to handle it.");
}
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.scalar)) {
var transformKey = makeSeenTransformationKey(dir, def);
if (!this.seenTransformations[transformKey]) {
transformer.scalar(def, dir, context);
this.seenTransformations[transformKey] = true;
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'scalar()' method");
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'scalar()' method");
}
}
};
GraphQLTransform.prototype.transformUnion = function (transformer, def, dir, context) {
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.union)) {
var transformKey = makeSeenTransformationKey(dir, def);
if (!this.seenTransformations[transformKey]) {
transformer.union(def, dir, context);
this.seenTransformations[transformKey] = true;
GraphQLTransform.prototype.transformUnion = function (transformer, def, validDirectiveNameMap, context) {
for (var _i = 0, _a = def.directives; _i < _a.length; _i++) {
var dir = _a[_i];
if (!validDirectiveNameMap[dir.name.value]) {
throw new errors_1.UnknownDirectiveError("Unknown directive '" + dir.name.value + "'. Either remove the directive from the schema or add a transformer to handle it.");
}
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.union)) {
var transformKey = makeSeenTransformationKey(dir, def);
if (!this.seenTransformations[transformKey]) {
transformer.union(def, dir, context);
this.seenTransformations[transformKey] = true;
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'union()' method");
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'union()' method");
}
}
};
GraphQLTransform.prototype.transformEnum = function (transformer, def, dir, context) {
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.enum)) {
var transformKey = makeSeenTransformationKey(dir, def);
if (!this.seenTransformations[transformKey]) {
transformer.enum(def, dir, context);
this.seenTransformations[transformKey] = true;
GraphQLTransform.prototype.transformEnum = function (transformer, def, validDirectiveNameMap, context) {
for (var _i = 0, _a = def.directives; _i < _a.length; _i++) {
var dir = _a[_i];
if (!validDirectiveNameMap[dir.name.value]) {
throw new errors_1.UnknownDirectiveError("Unknown directive '" + dir.name.value + "'. Either remove the directive from the schema or add a transformer to handle it.");
}
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.enum)) {
var transformKey = makeSeenTransformationKey(dir, def);
if (!this.seenTransformations[transformKey]) {
transformer.enum(def, dir, context);
this.seenTransformations[transformKey] = true;
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'enum()' method");
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'enum()' method");
}
}
for (var _i = 0, _a = def.values; _i < _a.length; _i++) {
var value = _a[_i];
for (var _b = 0, _c = value.directives; _b < _c.length; _b++) {
var vDir = _c[_b];
this.transformEnumValue(transformer, def, value, vDir, context);
}
for (var _b = 0, _c = def.values; _b < _c.length; _b++) {
var value = _c[_b];
this.transformEnumValue(transformer, def, value, validDirectiveNameMap, context);
}
};
GraphQLTransform.prototype.transformEnumValue = function (transformer, enm, def, dir, context) {
if (matchEnumValueDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.enumValue)) {
var transformKey = makeSeenTransformationKey(dir, enm, def);
if (!this.seenTransformations[transformKey]) {
transformer.enumValue(def, dir, context);
this.seenTransformations[transformKey] = true;
GraphQLTransform.prototype.transformEnumValue = function (transformer, enm, def, validDirectiveNameMap, context) {
for (var _i = 0, _a = def.directives; _i < _a.length; _i++) {
var dir = _a[_i];
if (!validDirectiveNameMap[dir.name.value]) {
throw new errors_1.UnknownDirectiveError("Unknown directive '" + dir.name.value + "'. Either remove the directive from the schema or add a transformer to handle it.");
}
if (matchEnumValueDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.enumValue)) {
var transformKey = makeSeenTransformationKey(dir, enm, def);
if (!this.seenTransformations[transformKey]) {
transformer.enumValue(def, dir, context);
this.seenTransformations[transformKey] = true;
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'enumValue()' method");
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'enumValue()' method");
}
}
};
GraphQLTransform.prototype.transformInputObject = function (transformer, def, dir, context) {
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.input)) {
var transformKey = makeSeenTransformationKey(dir, def);
if (!this.seenTransformations[transformKey]) {
transformer.input(def, dir, context);
this.seenTransformations[transformKey] = true;
GraphQLTransform.prototype.transformInputObject = function (transformer, def, validDirectiveNameMap, context) {
for (var _i = 0, _a = def.directives; _i < _a.length; _i++) {
var dir = _a[_i];
if (!validDirectiveNameMap[dir.name.value]) {
throw new errors_1.UnknownDirectiveError("Unknown directive '" + dir.name.value + "'. Either remove the directive from the schema or add a transformer to handle it.");
}
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.input)) {
var transformKey = makeSeenTransformationKey(dir, def);
if (!this.seenTransformations[transformKey]) {
transformer.input(def, dir, context);
this.seenTransformations[transformKey] = true;
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'input()' method");
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'input()' method");
}
}
for (var _i = 0, _a = def.fields; _i < _a.length; _i++) {
var field = _a[_i];
for (var _b = 0, _c = field.directives; _b < _c.length; _b++) {
var fDir = _c[_b];
this.transformInputField(transformer, def, field, fDir, context);
}
for (var _b = 0, _c = def.fields; _b < _c.length; _b++) {
var field = _c[_b];
this.transformInputField(transformer, def, field, validDirectiveNameMap, context);
}
};
GraphQLTransform.prototype.transformInputField = function (transformer, input, def, dir, context) {
if (matchInputFieldDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.inputValue)) {
var transformKey = makeSeenTransformationKey(dir, input, def);
if (!this.seenTransformations[transformKey]) {
transformer.inputValue(def, dir, context);
this.seenTransformations[transformKey] = true;
GraphQLTransform.prototype.transformInputField = function (transformer, input, def, validDirectiveNameMap, context) {
for (var _i = 0, _a = def.directives; _i < _a.length; _i++) {
var dir = _a[_i];
if (!validDirectiveNameMap[dir.name.value]) {
throw new errors_1.UnknownDirectiveError("Unknown directive '" + dir.name.value + "'. Either remove the directive from the schema or add a transformer to handle it.");
}
if (matchInputFieldDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.inputValue)) {
var transformKey = makeSeenTransformationKey(dir, input, def);
if (!this.seenTransformations[transformKey]) {
transformer.inputValue(def, dir, context);
this.seenTransformations[transformKey] = true;
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'inputValue()' method");
}
}
else {
throw new errors_1.InvalidTransformerError("The transformer '" + transformer.name + "' must implement the 'inputValue()' method");
}
}

@@ -420,0 +462,0 @@ };

@@ -66,3 +66,3 @@ "use strict";

var EXTRA_SCALARS_DOCUMENT = language_1.parse("\nscalar AWSDate\nscalar AWSTime\nscalar AWSDateTime\nscalar AWSTimestamp\nscalar AWSEmail\nscalar AWSJSON\nscalar AWSURL\nscalar AWSPhone\nscalar AWSIPAddress\nscalar BigInt\nscalar Double\n");
var EXTRA_DIRECTIVES_DOCUMENT = language_1.parse("\ndirective @aws_subscribe(mutations: [String!]!) on FIELD_DEFINITION\n");
var EXTRA_DIRECTIVES_DOCUMENT = language_1.parse("\ndirective @aws_subscribe(mutations: [String!]!) on FIELD_DEFINITION\ndirective @aws_auth(cognito_groups: [String!]!) on FIELD_DEFINITION\n");
function astBuilder(doc) {

@@ -69,0 +69,0 @@ var nodeMap = doc.definitions

{
"name": "graphql-transformer-core",
"version": "1.1.0-alpha.694cc790",
"version": "1.1.0-alpha.69cfb43a",
"description": "A framework to transform from GraphQL SDL to AWS CloudFormation.",

@@ -8,2 +8,3 @@ "main": "lib/index.js",

"test": "jest",
"test-ci": "jest --ci -i",
"build": "tsc",

@@ -10,0 +11,0 @@ "clean": "rm -rf ./lib"

@@ -41,2 +41,5 @@ import Template from 'cloudform/types/template'

function matchDirective(definition: DirectiveDefinitionNode, directive: DirectiveNode, node: TypeSystemDefinitionNode) {
if (!directive) {
return false;
}
if (definition.name.value !== directive.name.value) {

@@ -189,3 +192,3 @@ // The definition is for the wrong directive. Do not match.

(acc: any, t: Transformer) => ({ ...acc, [t.directive.name.value]: true }),
{ aws_subscribe: true }
{ aws_subscribe: true, aws_auth: true }
)

@@ -214,32 +217,25 @@ let allModelDefinitions = [...context.inputDocument.definitions]

for (const def of context.inputDocument.definitions as TypeDefinitionNode[]) {
for (const dir of def.directives) {
if (!validDirectiveNameMap[dir.name.value]) {
throw new UnknownDirectiveError(
`Unknown directive '${dir.name.value}'. Either remove the directive from the schema or add a transformer to handle it.`
)
}
switch (def.kind) {
case 'ObjectTypeDefinition':
this.transformObject(transformer, def, dir, context)
// Walk the fields and call field transformers.
break
case 'InterfaceTypeDefinition':
this.transformInterface(transformer, def, dir, context)
// Walk the fields and call field transformers.
break;
case 'ScalarTypeDefinition':
this.transformScalar(transformer, def, dir, context)
break;
case 'UnionTypeDefinition':
this.transformUnion(transformer, def, dir, context)
break;
case 'EnumTypeDefinition':
this.transformEnum(transformer, def, dir, context)
break;
case 'InputObjectTypeDefinition':
this.transformInputObject(transformer, def, dir, context)
break;
default:
continue
}
switch (def.kind) {
case 'ObjectTypeDefinition':
this.transformObject(transformer, def, validDirectiveNameMap, context)
// Walk the fields and call field transformers.
break
case 'InterfaceTypeDefinition':
this.transformInterface(transformer, def, validDirectiveNameMap, context)
// Walk the fields and call field transformers.
break;
case 'ScalarTypeDefinition':
this.transformScalar(transformer, def, validDirectiveNameMap, context)
break;
case 'UnionTypeDefinition':
this.transformUnion(transformer, def, validDirectiveNameMap, context)
break;
case 'EnumTypeDefinition':
this.transformEnum(transformer, def, validDirectiveNameMap, context)
break;
case 'InputObjectTypeDefinition':
this.transformInputObject(transformer, def, validDirectiveNameMap, context)
break;
default:
continue
}

@@ -266,18 +262,28 @@ }

private transformObject(transformer: Transformer, def: ObjectTypeDefinitionNode, dir: DirectiveNode, context: TransformerContext) {
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.object)) {
const transformKey = makeSeenTransformationKey(dir, def)
if (!this.seenTransformations[transformKey]) {
transformer.object(def, dir, context)
this.seenTransformations[transformKey] = true
private transformObject(
transformer: Transformer,
def: ObjectTypeDefinitionNode,
validDirectiveNameMap: { [k: string]: boolean },
context: TransformerContext
) {
for (const dir of def.directives) {
if (!validDirectiveNameMap[dir.name.value]) {
throw new UnknownDirectiveError(
`Unknown directive '${dir.name.value}'. Either remove the directive from the schema or add a transformer to handle it.`
)
}
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.object)) {
const transformKey = makeSeenTransformationKey(dir, def)
if (!this.seenTransformations[transformKey]) {
transformer.object(def, dir, context)
this.seenTransformations[transformKey] = true
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'object()' method`)
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'object()' method`)
}
}
for (const field of def.fields) {
for (const fDir of field.directives) {
this.transformField(transformer, def, field, fDir, context)
}
this.transformField(transformer, def, field, validDirectiveNameMap, context)
}

@@ -290,20 +296,25 @@ }

def: FieldDefinitionNode,
dir: DirectiveNode,
validDirectiveNameMap: { [k: string]: boolean },
context: TransformerContext
) {
if (matchFieldDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.field)) {
const transformKey = makeSeenTransformationKey(dir, parent, def)
if (!this.seenTransformations[transformKey]) {
transformer.field(parent, def, dir, context)
this.seenTransformations[transformKey] = true
for (const dir of def.directives) {
if (!validDirectiveNameMap[dir.name.value]) {
throw new UnknownDirectiveError(
`Unknown directive '${dir.name.value}'. Either remove the directive from the schema or add a transformer to handle it.`
)
}
if (matchFieldDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.field)) {
const transformKey = makeSeenTransformationKey(dir, parent, def)
if (!this.seenTransformations[transformKey]) {
transformer.field(parent, def, dir, context)
this.seenTransformations[transformKey] = true
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'field()' method`)
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'field()' method`)
}
}
for (const arg of def.arguments) {
for (const aDir of arg.directives) {
this.transformArgument(transformer, parent, def, arg, aDir, context)
}
this.transformArgument(transformer, parent, def, arg, validDirectiveNameMap, context)
}

@@ -317,14 +328,21 @@ }

arg: InputValueDefinitionNode,
dir: DirectiveNode,
validDirectiveNameMap: { [k: string]: boolean },
context: TransformerContext
) {
if (matchArgumentDirective(transformer.directive, dir, arg)) {
if (isFunction(transformer.argument)) {
const transformKey = makeSeenTransformationKey(dir, parent, field, arg)
if (!this.seenTransformations[transformKey]) {
transformer.argument(arg, dir, context)
this.seenTransformations[transformKey] = true
for (const dir of arg.directives) {
if (!validDirectiveNameMap[dir.name.value]) {
throw new UnknownDirectiveError(
`Unknown directive '${dir.name.value}'. Either remove the directive from the schema or add a transformer to handle it.`
)
}
if (matchArgumentDirective(transformer.directive, dir, arg)) {
if (isFunction(transformer.argument)) {
const transformKey = makeSeenTransformationKey(dir, parent, field, arg)
if (!this.seenTransformations[transformKey]) {
transformer.argument(arg, dir, context)
this.seenTransformations[transformKey] = true
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'argument()' method`)
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'argument()' method`)
}

@@ -334,31 +352,52 @@ }

private transformInterface(transformer: Transformer, def: InterfaceTypeDefinitionNode, dir: DirectiveNode, context: TransformerContext) {
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.interface)) {
const transformKey = makeSeenTransformationKey(dir, def)
if (!this.seenTransformations[transformKey]) {
transformer.interface(def, dir, context)
this.seenTransformations[transformKey] = true
private transformInterface(
transformer: Transformer,
def: InterfaceTypeDefinitionNode,
validDirectiveNameMap: { [k: string]: boolean },
context: TransformerContext) {
for (const dir of def.directives) {
if (!validDirectiveNameMap[dir.name.value]) {
throw new UnknownDirectiveError(
`Unknown directive '${dir.name.value}'. Either remove the directive from the schema or add a transformer to handle it.`
)
}
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.interface)) {
const transformKey = makeSeenTransformationKey(dir, def)
if (!this.seenTransformations[transformKey]) {
transformer.interface(def, dir, context)
this.seenTransformations[transformKey] = true
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'interface()' method`)
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'interface()' method`)
}
}
for (const field of def.fields) {
for (const fDir of field.directives) {
this.transformField(transformer, def, field, fDir, context)
}
this.transformField(transformer, def, field, validDirectiveNameMap, context)
}
}
private transformScalar(transformer: Transformer, def: ScalarTypeDefinitionNode, dir: DirectiveNode, context: TransformerContext) {
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.scalar)) {
const transformKey = makeSeenTransformationKey(dir, def)
if (!this.seenTransformations[transformKey]) {
transformer.scalar(def, dir, context)
this.seenTransformations[transformKey] = true
private transformScalar(
transformer: Transformer,
def: ScalarTypeDefinitionNode,
validDirectiveNameMap: { [k: string]: boolean },
context: TransformerContext
) {
for (const dir of def.directives) {
if (!validDirectiveNameMap[dir.name.value]) {
throw new UnknownDirectiveError(
`Unknown directive '${dir.name.value}'. Either remove the directive from the schema or add a transformer to handle it.`
)
}
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.scalar)) {
const transformKey = makeSeenTransformationKey(dir, def)
if (!this.seenTransformations[transformKey]) {
transformer.scalar(def, dir, context)
this.seenTransformations[transformKey] = true
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'scalar()' method`)
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'scalar()' method`)
}

@@ -368,12 +407,24 @@ }

private transformUnion(transformer: Transformer, def: UnionTypeDefinitionNode, dir: DirectiveNode, context: TransformerContext) {
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.union)) {
const transformKey = makeSeenTransformationKey(dir, def)
if (!this.seenTransformations[transformKey]) {
transformer.union(def, dir, context)
this.seenTransformations[transformKey] = true
private transformUnion(
transformer: Transformer,
def: UnionTypeDefinitionNode,
validDirectiveNameMap: { [k: string]: boolean },
context: TransformerContext
) {
for (const dir of def.directives) {
if (!validDirectiveNameMap[dir.name.value]) {
throw new UnknownDirectiveError(
`Unknown directive '${dir.name.value}'. Either remove the directive from the schema or add a transformer to handle it.`
)
}
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.union)) {
const transformKey = makeSeenTransformationKey(dir, def)
if (!this.seenTransformations[transformKey]) {
transformer.union(def, dir, context)
this.seenTransformations[transformKey] = true
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'union()' method`)
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'union()' method`)
}

@@ -383,18 +434,28 @@ }

private transformEnum(transformer: Transformer, def: EnumTypeDefinitionNode, dir: DirectiveNode, context: TransformerContext) {
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.enum)) {
const transformKey = makeSeenTransformationKey(dir, def)
if (!this.seenTransformations[transformKey]) {
transformer.enum(def, dir, context)
this.seenTransformations[transformKey] = true
private transformEnum(
transformer: Transformer,
def: EnumTypeDefinitionNode,
validDirectiveNameMap: { [k: string]: boolean },
context: TransformerContext
) {
for (const dir of def.directives) {
if (!validDirectiveNameMap[dir.name.value]) {
throw new UnknownDirectiveError(
`Unknown directive '${dir.name.value}'. Either remove the directive from the schema or add a transformer to handle it.`
)
}
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.enum)) {
const transformKey = makeSeenTransformationKey(dir, def)
if (!this.seenTransformations[transformKey]) {
transformer.enum(def, dir, context)
this.seenTransformations[transformKey] = true
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'enum()' method`)
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'enum()' method`)
}
}
for (const value of def.values) {
for (const vDir of value.directives) {
this.transformEnumValue(transformer, def, value, vDir, context)
}
this.transformEnumValue(transformer, def, value, validDirectiveNameMap, context)
}

@@ -404,13 +465,24 @@ }

private transformEnumValue(
transformer: Transformer, enm: EnumTypeDefinitionNode, def: EnumValueDefinitionNode, dir: DirectiveNode, context: TransformerContext
transformer: Transformer,
enm: EnumTypeDefinitionNode,
def: EnumValueDefinitionNode,
validDirectiveNameMap: { [k: string]: boolean },
context: TransformerContext
) {
if (matchEnumValueDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.enumValue)) {
const transformKey = makeSeenTransformationKey(dir, enm, def)
if (!this.seenTransformations[transformKey]) {
transformer.enumValue(def, dir, context)
this.seenTransformations[transformKey] = true
for (const dir of def.directives) {
if (!validDirectiveNameMap[dir.name.value]) {
throw new UnknownDirectiveError(
`Unknown directive '${dir.name.value}'. Either remove the directive from the schema or add a transformer to handle it.`
)
}
if (matchEnumValueDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.enumValue)) {
const transformKey = makeSeenTransformationKey(dir, enm, def)
if (!this.seenTransformations[transformKey]) {
transformer.enumValue(def, dir, context)
this.seenTransformations[transformKey] = true
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'enumValue()' method`)
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'enumValue()' method`)
}

@@ -420,18 +492,28 @@ }

private transformInputObject(transformer: Transformer, def: InputObjectTypeDefinitionNode, dir: DirectiveNode, context: TransformerContext) {
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.input)) {
const transformKey = makeSeenTransformationKey(dir, def)
if (!this.seenTransformations[transformKey]) {
transformer.input(def, dir, context)
this.seenTransformations[transformKey] = true
private transformInputObject(
transformer: Transformer,
def: InputObjectTypeDefinitionNode,
validDirectiveNameMap: { [k: string]: boolean },
context: TransformerContext
) {
for (const dir of def.directives) {
if (!validDirectiveNameMap[dir.name.value]) {
throw new UnknownDirectiveError(
`Unknown directive '${dir.name.value}'. Either remove the directive from the schema or add a transformer to handle it.`
)
}
if (matchDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.input)) {
const transformKey = makeSeenTransformationKey(dir, def)
if (!this.seenTransformations[transformKey]) {
transformer.input(def, dir, context)
this.seenTransformations[transformKey] = true
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'input()' method`)
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'input()' method`)
}
}
for (const field of def.fields) {
for (const fDir of field.directives) {
this.transformInputField(transformer, def, field, fDir, context)
}
this.transformInputField(transformer, def, field, validDirectiveNameMap, context)
}

@@ -441,14 +523,24 @@ }

private transformInputField(
transformer: Transformer, input: InputObjectTypeDefinitionNode, def: InputValueDefinitionNode,
dir: DirectiveNode, context: TransformerContext
transformer: Transformer,
input: InputObjectTypeDefinitionNode,
def: InputValueDefinitionNode,
validDirectiveNameMap: { [k: string]: boolean },
context: TransformerContext
) {
if (matchInputFieldDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.inputValue)) {
const transformKey = makeSeenTransformationKey(dir, input, def)
if (!this.seenTransformations[transformKey]) {
transformer.inputValue(def, dir, context)
this.seenTransformations[transformKey] = true
for (const dir of def.directives) {
if (!validDirectiveNameMap[dir.name.value]) {
throw new UnknownDirectiveError(
`Unknown directive '${dir.name.value}'. Either remove the directive from the schema or add a transformer to handle it.`
)
}
if (matchInputFieldDirective(transformer.directive, dir, def)) {
if (isFunction(transformer.inputValue)) {
const transformKey = makeSeenTransformationKey(dir, input, def)
if (!this.seenTransformations[transformKey]) {
transformer.inputValue(def, dir, context)
this.seenTransformations[transformKey] = true
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'inputValue()' method`)
}
} else {
throw new InvalidTransformerError(`The transformer '${transformer.name}' must implement the 'inputValue()' method`)
}

@@ -455,0 +547,0 @@ }

@@ -92,2 +92,3 @@ import { GraphQLScalarType } from 'graphql'

directive @aws_subscribe(mutations: [String!]!) on FIELD_DEFINITION
directive @aws_auth(cognito_groups: [String!]!) on FIELD_DEFINITION
`)

@@ -94,0 +95,0 @@

Sorry, the diff of this file is not supported yet

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