Comparing version 0.0.18 to 0.0.19
{ | ||
"name": "grats", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"main": "dist/src/index.js", | ||
@@ -5,0 +5,0 @@ "bin": "dist/src/cli.js", |
@@ -34,2 +34,3 @@ export declare const ISSUE_URL = "https://github.com/captbaritone/grats/issues"; | ||
export declare function inputTypeFieldNotProperty(): string; | ||
export declare function inputInterfaceFieldNotProperty(): string; | ||
export declare function inputFieldUntyped(): string; | ||
@@ -36,0 +37,0 @@ export declare function typeTagOnUnnamedClass(): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultArgElementIsNotAssignment = exports.defaultValueIsNotLiteral = exports.ambiguousNumberType = exports.expectedOneNonNullishType = exports.propertyFieldMissingType = exports.cannotResolveSymbolForDescription = exports.wrapperMissingTypeArg = exports.methodMissingType = exports.gqlEntityMissingName = exports.enumVariantMissingInitializer = exports.enumVariantNotStringLiteral = exports.enumTagOnInvalidNode = exports.argNotTyped = exports.argNameNotLiteral = exports.argIsNotProperty = exports.argumentParamIsNotObject = exports.argumentParamIsMissingType = exports.typeNameDoesNotMatchExpected = exports.typeNameTypeNotStringLiteral = exports.typeNameMissingTypeAnnotation = exports.typeNameInitializerWrong = exports.typeNameInitializeNotString = exports.typeNameMissingInitializer = exports.typeNameNotDeclaration = exports.typeTagOnAliasOfNonObjectOrUnknown = exports.typeTagOnUnnamedClass = exports.inputFieldUntyped = exports.inputTypeFieldNotProperty = exports.inputTypeNotLiteral = exports.functionFieldNotNamedExport = exports.functionFieldDefaultExport = exports.functionFieldNotNamed = exports.functionFieldParentTypeNotValid = exports.functionFieldParentTypeMissing = exports.functionFieldNotTopLevel = exports.invalidReturnTypeForFunctionField = exports.invalidParentArgForFunctionField = exports.expectedUnionTypeReference = exports.expectedUnionTypeNode = exports.invalidUnionTagUsage = exports.invalidInputTagUsage = exports.invalidEnumTagUsage = exports.invalidInterfaceTagUsage = exports.invalidScalarTagUsage = exports.invalidTypeTagUsage = exports.invalidGratsTag = exports.wrongCasingForGratsTag = exports.killsParentOnExceptionOnWrongNode = exports.fieldTagOnWrongNode = exports.ISSUE_URL = void 0; | ||
exports.gqlTagInDetachedJSDocBlockComment = exports.gqlTagInNonJSDocBlockComment = exports.gqlTagInLineComment = exports.expectedNullableArgumentToBeOptional = exports.operationTypeNotUnknown = exports.nonSubscriptionFieldAsyncIterable = exports.subscriptionFieldNotAsyncIterable = exports.graphQLTagNameHasWhitespace = exports.graphQLNameHasLeadingNewlines = exports.multipleContextTypes = exports.unexpectedParamSpreadForContextParam = exports.expectedTypeAnnotationOnContextToHaveDeclaration = exports.expectedTypeAnnotationOnContextToBeResolvable = exports.expectedTypeAnnotationOfReferenceOnContext = exports.expectedTypeAnnotationOnContext = exports.unresolvedTypeReference = exports.invalidTypePassedToFieldFunction = exports.parameterPropertyMissingType = exports.parameterPropertyNotPublic = exports.parameterWithoutModifiers = exports.duplicateInterfaceTag = exports.duplicateTag = exports.implementsTagOnTypeAlias = exports.implementsTagOnInterface = exports.implementsTagOnClass = exports.mergedInterfaces = exports.nonNullTypeCannotBeOptional = exports.killsParentOnExceptionOnNullable = exports.killsParentOnExceptionWithWrongConfig = exports.expectedNameIdentifier = exports.pluralTypeMissingParameter = exports.unknownGraphQLType = exports.unsupportedTypeLiteral = exports.defaultArgPropertyMissingInitializer = exports.defaultArgPropertyMissingName = void 0; | ||
exports.defaultValueIsNotLiteral = exports.ambiguousNumberType = exports.expectedOneNonNullishType = exports.propertyFieldMissingType = exports.cannotResolveSymbolForDescription = exports.wrapperMissingTypeArg = exports.methodMissingType = exports.gqlEntityMissingName = exports.enumVariantMissingInitializer = exports.enumVariantNotStringLiteral = exports.enumTagOnInvalidNode = exports.argNotTyped = exports.argNameNotLiteral = exports.argIsNotProperty = exports.argumentParamIsNotObject = exports.argumentParamIsMissingType = exports.typeNameDoesNotMatchExpected = exports.typeNameTypeNotStringLiteral = exports.typeNameMissingTypeAnnotation = exports.typeNameInitializerWrong = exports.typeNameInitializeNotString = exports.typeNameMissingInitializer = exports.typeNameNotDeclaration = exports.typeTagOnAliasOfNonObjectOrUnknown = exports.typeTagOnUnnamedClass = exports.inputFieldUntyped = exports.inputInterfaceFieldNotProperty = exports.inputTypeFieldNotProperty = exports.inputTypeNotLiteral = exports.functionFieldNotNamedExport = exports.functionFieldDefaultExport = exports.functionFieldNotNamed = exports.functionFieldParentTypeNotValid = exports.functionFieldParentTypeMissing = exports.functionFieldNotTopLevel = exports.invalidReturnTypeForFunctionField = exports.invalidParentArgForFunctionField = exports.expectedUnionTypeReference = exports.expectedUnionTypeNode = exports.invalidUnionTagUsage = exports.invalidInputTagUsage = exports.invalidEnumTagUsage = exports.invalidInterfaceTagUsage = exports.invalidScalarTagUsage = exports.invalidTypeTagUsage = exports.invalidGratsTag = exports.wrongCasingForGratsTag = exports.killsParentOnExceptionOnWrongNode = exports.fieldTagOnWrongNode = exports.ISSUE_URL = void 0; | ||
exports.gqlTagInDetachedJSDocBlockComment = exports.gqlTagInNonJSDocBlockComment = exports.gqlTagInLineComment = exports.expectedNullableArgumentToBeOptional = exports.operationTypeNotUnknown = exports.nonSubscriptionFieldAsyncIterable = exports.subscriptionFieldNotAsyncIterable = exports.graphQLTagNameHasWhitespace = exports.graphQLNameHasLeadingNewlines = exports.multipleContextTypes = exports.unexpectedParamSpreadForContextParam = exports.expectedTypeAnnotationOnContextToHaveDeclaration = exports.expectedTypeAnnotationOnContextToBeResolvable = exports.expectedTypeAnnotationOfReferenceOnContext = exports.expectedTypeAnnotationOnContext = exports.unresolvedTypeReference = exports.invalidTypePassedToFieldFunction = exports.parameterPropertyMissingType = exports.parameterPropertyNotPublic = exports.parameterWithoutModifiers = exports.duplicateInterfaceTag = exports.duplicateTag = exports.implementsTagOnTypeAlias = exports.implementsTagOnInterface = exports.implementsTagOnClass = exports.mergedInterfaces = exports.nonNullTypeCannotBeOptional = exports.killsParentOnExceptionOnNullable = exports.killsParentOnExceptionWithWrongConfig = exports.expectedNameIdentifier = exports.pluralTypeMissingParameter = exports.unknownGraphQLType = exports.unsupportedTypeLiteral = exports.defaultArgPropertyMissingInitializer = exports.defaultArgPropertyMissingName = exports.defaultArgElementIsNotAssignment = void 0; | ||
var Extractor_1 = require("./Extractor"); | ||
@@ -57,3 +57,3 @@ exports.ISSUE_URL = "https://github.com/captbaritone/grats/issues"; | ||
function invalidInputTagUsage() { | ||
return "`@".concat(Extractor_1.INPUT_TAG, "` can only be used on type alias declarations. e.g. `type MyInput = { foo: string }`"); | ||
return "`@".concat(Extractor_1.INPUT_TAG, "` can only be used on type alias or interface declarations. e.g. `type MyInput = { foo: string }` or `interface MyInput { foo: string }`"); | ||
} | ||
@@ -114,2 +114,6 @@ exports.invalidInputTagUsage = invalidInputTagUsage; | ||
exports.inputTypeFieldNotProperty = inputTypeFieldNotProperty; | ||
function inputInterfaceFieldNotProperty() { | ||
return "`@".concat(Extractor_1.INPUT_TAG, "` interfaces only support property signature members. e.g. `interface MyInput { foo: string }`"); | ||
} | ||
exports.inputInterfaceFieldNotProperty = inputInterfaceFieldNotProperty; | ||
function inputFieldUntyped() { | ||
@@ -264,3 +268,3 @@ return 'Input field must have an explicit type annotation. Grats uses the type annotation to determine the type of the field, so it must be explicit in order for Grats to "see" the type.'; | ||
"If an interface is declared multiple times in a scope, TypeScript merges them.", | ||
"To avoid ambiguity Grats does not support using merged interfaces as GraphQL interfaces.", | ||
"To avoid ambiguity Grats does not support using merged interfaces as GraphQL definitions.", | ||
"Consider using a unique name for your TypeScript interface and renaming it.\n\n", | ||
@@ -267,0 +271,0 @@ "Learn more: ".concat(DOC_URLS.mergedInterfaces), |
@@ -237,4 +237,6 @@ "use strict"; | ||
this.inputTypeAliasDeclaration(node, tag); | ||
// TODO: Could we support interfaces? | ||
} | ||
else if (ts.isInterfaceDeclaration(node)) { | ||
this.inputInterfaceDeclaration(node, tag); | ||
} | ||
else { | ||
@@ -403,5 +405,36 @@ this.report(tag, E.invalidInputTagUsage()); | ||
}; | ||
Extractor.prototype.collectInputFields = function (node) { | ||
Extractor.prototype.inputInterfaceDeclaration = function (node, tag) { | ||
var e_3, _a; | ||
var name = this.entityName(node, tag); | ||
if (name == null) | ||
return null; | ||
var description = this.collectDescription(node); | ||
this.recordTypeName(node.name, name, "INPUT_OBJECT"); | ||
var fields = []; | ||
try { | ||
for (var _b = __values(node.members), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var member = _c.value; | ||
if (!ts.isPropertySignature(member)) { | ||
this.reportUnhandled(member, "input field", E.inputTypeFieldNotProperty()); | ||
continue; | ||
} | ||
var field = this.collectInputField(member); | ||
if (field != null) | ||
fields.push(field); | ||
} | ||
} | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_3) throw e_3.error; } | ||
} | ||
this.interfaceDeclarations.push(node); | ||
var deprecatedDirective = this.collectDeprecated(node); | ||
this.definitions.push(this.gql.inputObjectTypeDefinition(node, name, fields, deprecatedDirective == null ? null : [deprecatedDirective], description)); | ||
}; | ||
Extractor.prototype.collectInputFields = function (node) { | ||
var e_4, _a; | ||
var fields = []; | ||
if (!ts.isTypeLiteralNode(node.type)) { | ||
@@ -422,3 +455,3 @@ return this.reportUnhandled(node, "input", E.inputTypeNotLiteral()); | ||
} | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
catch (e_4_1) { e_4 = { error: e_4_1 }; } | ||
finally { | ||
@@ -428,3 +461,3 @@ try { | ||
} | ||
finally { if (e_3) throw e_3.error; } | ||
finally { if (e_4) throw e_4.error; } | ||
} | ||
@@ -639,3 +672,3 @@ return fields.length === 0 ? null : fields; | ||
ts.forEachChild(node, function (node) { | ||
var e_4, _a; | ||
var e_5, _a; | ||
if (ts.isConstructorDeclaration(node)) { | ||
@@ -653,3 +686,3 @@ try { | ||
} | ||
catch (e_4_1) { e_4 = { error: e_4_1 }; } | ||
catch (e_5_1) { e_5 = { error: e_5_1 }; } | ||
finally { | ||
@@ -659,3 +692,3 @@ try { | ||
} | ||
finally { if (e_4) throw e_4.error; } | ||
finally { if (e_5) throw e_5.error; } | ||
} | ||
@@ -741,3 +774,3 @@ } | ||
Extractor.prototype.collectArgs = function (argsParam) { | ||
var e_5, _a; | ||
var e_6, _a; | ||
var args = []; | ||
@@ -767,3 +800,3 @@ var argsType = argsParam.type; | ||
} | ||
catch (e_5_1) { e_5 = { error: e_5_1 }; } | ||
catch (e_6_1) { e_6 = { error: e_6_1 }; } | ||
finally { | ||
@@ -773,3 +806,3 @@ try { | ||
} | ||
finally { if (e_5) throw e_5.error; } | ||
finally { if (e_6) throw e_6.error; } | ||
} | ||
@@ -779,3 +812,3 @@ return args; | ||
Extractor.prototype.collectArgDefaults = function (node) { | ||
var e_6, _a; | ||
var e_7, _a; | ||
var defaults = new Map(); | ||
@@ -792,3 +825,3 @@ try { | ||
} | ||
catch (e_6_1) { e_6 = { error: e_6_1 }; } | ||
catch (e_7_1) { e_7 = { error: e_7_1 }; } | ||
finally { | ||
@@ -798,3 +831,3 @@ try { | ||
} | ||
finally { if (e_6) throw e_6.error; } | ||
finally { if (e_7) throw e_7.error; } | ||
} | ||
@@ -830,3 +863,3 @@ return defaults; | ||
Extractor.prototype.collectArrayLiteral = function (node) { | ||
var e_7, _a; | ||
var e_8, _a; | ||
var values = []; | ||
@@ -846,3 +879,3 @@ var errors = false; | ||
} | ||
catch (e_7_1) { e_7 = { error: e_7_1 }; } | ||
catch (e_8_1) { e_8 = { error: e_8_1 }; } | ||
finally { | ||
@@ -852,3 +885,3 @@ try { | ||
} | ||
finally { if (e_7) throw e_7.error; } | ||
finally { if (e_8) throw e_8.error; } | ||
} | ||
@@ -861,3 +894,3 @@ if (errors) { | ||
Extractor.prototype.collectObjectLiteral = function (node) { | ||
var e_8, _a; | ||
var e_9, _a; | ||
var fields = []; | ||
@@ -877,3 +910,3 @@ var errors = false; | ||
} | ||
catch (e_8_1) { e_8 = { error: e_8_1 }; } | ||
catch (e_9_1) { e_9 = { error: e_9_1 }; } | ||
finally { | ||
@@ -883,3 +916,3 @@ try { | ||
} | ||
finally { if (e_8) throw e_8.error; } | ||
finally { if (e_9) throw e_9.error; } | ||
} | ||
@@ -976,3 +1009,3 @@ if (errors) { | ||
Extractor.prototype.enumTypeAliasVariants = function (node) { | ||
var e_9, _a; | ||
var e_10, _a; | ||
// Semantically we only support deriving enums from type aliases that | ||
@@ -1007,3 +1040,3 @@ // are unions of string literals. However, in the edge case of a union | ||
} | ||
catch (e_9_1) { e_9 = { error: e_9_1 }; } | ||
catch (e_10_1) { e_10 = { error: e_10_1 }; } | ||
finally { | ||
@@ -1013,3 +1046,3 @@ try { | ||
} | ||
finally { if (e_9) throw e_9.error; } | ||
finally { if (e_10) throw e_10.error; } | ||
} | ||
@@ -1019,3 +1052,3 @@ return values; | ||
Extractor.prototype.collectEnumValues = function (node) { | ||
var e_10, _a; | ||
var e_11, _a; | ||
var values = []; | ||
@@ -1035,3 +1068,3 @@ try { | ||
} | ||
catch (e_10_1) { e_10 = { error: e_10_1 }; } | ||
catch (e_11_1) { e_11 = { error: e_11_1 }; } | ||
finally { | ||
@@ -1041,3 +1074,3 @@ try { | ||
} | ||
finally { if (e_10) throw e_10.error; } | ||
finally { if (e_11) throw e_11.error; } | ||
} | ||
@@ -1044,0 +1077,0 @@ return values; |
{ | ||
"name": "grats", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"main": "dist/src/index.js", | ||
@@ -5,0 +5,0 @@ "bin": "dist/src/cli.js", |
289715
5990