Comparing version 0.0.0-main-e383eda5 to 0.0.0-main-e6abe1f1
{ | ||
"name": "grats", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"main": "dist/src/index.js", | ||
@@ -22,3 +22,3 @@ "bin": "dist/src/cli.js", | ||
"graphql": "^16.6.0", | ||
"typescript": "^4.9.5" | ||
"typescript": "^5.0.2" | ||
}, | ||
@@ -33,5 +33,5 @@ "devDependencies": { | ||
"path-browserify": "^1.0.1", | ||
"prettier": "^2.8.7", | ||
"process": "^0.11.10", | ||
"ts-node": "^10.9.1", | ||
"prettier": "^2.8.7" | ||
"ts-node": "^10.9.1" | ||
}, | ||
@@ -38,0 +38,0 @@ "prettier": { |
@@ -39,3 +39,3 @@ #!/usr/bin/env node | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.formatLoc = void 0; | ||
@@ -51,2 +51,3 @@ var graphql_1 = require("graphql"); | ||
var printSchema_1 = require("./printSchema"); | ||
var ts = require("typescript"); | ||
var program = new commander_1.Command(); | ||
@@ -57,9 +58,8 @@ program | ||
.version(package_json_1.version) | ||
.option("-o, --output <SCHEMA_FILE>", "Where to write the schema file. Defaults to stdout") | ||
.option("--tsconfig <TSCONFIG>", "Path to tsconfig.json. Defaults to auto-detecting based on the current working directory") | ||
.action(function (_a) { | ||
var output = _a.output, tsconfig = _a.tsconfig; | ||
var tsconfig = _a.tsconfig; | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_b) { | ||
build(output, tsconfig); | ||
build(tsconfig); | ||
return [2 /*return*/]; | ||
@@ -75,3 +75,7 @@ }); | ||
var tsconfig = _a.tsconfig; | ||
var options = (0, _1.getParsedTsConfig)(tsconfig); | ||
var optionsResult = (0, _1.getParsedTsConfig)(tsconfig); | ||
if (optionsResult.kind === "ERROR") { | ||
throw new Error("TODO"); | ||
} | ||
var options = optionsResult.value; | ||
var schema = buildSchema(options); | ||
@@ -86,26 +90,24 @@ var loc = (0, Locate_1.locate)(schema, entity); | ||
program.parse(); | ||
function build(output, tsconfig) { | ||
var options = (0, _1.getParsedTsConfig)(tsconfig); | ||
var schema = buildSchema(options); | ||
var sortedSchema = (0, graphql_1.lexicographicSortSchema)(schema); | ||
var schemaStr = (0, printSchema_1.printGratsSchema)(sortedSchema, options.raw.grats); | ||
if (output) { | ||
var absOutput = (0, path_1.resolve)(process.cwd(), output); | ||
(0, fs_1.writeFileSync)(absOutput, schemaStr); | ||
console.error("Grats: Wrote schema to `".concat(absOutput, "`.")); | ||
function build(tsconfig) { | ||
var configFile = tsconfig || ts.findConfigFile(process.cwd(), ts.sys.fileExists); | ||
if (configFile == null) { | ||
throw new Error("Grats: Could not find tsconfig.json"); | ||
} | ||
else { | ||
console.log(schemaStr); | ||
} | ||
} | ||
function _buildSchema(tsconfig) { | ||
if (tsconfig && !(0, fs_1.existsSync)(tsconfig)) { | ||
console.error("Grats: Could not find tsconfig.json at `".concat(tsconfig, "`.")); | ||
var optionsResult = (0, _1.getParsedTsConfig)(configFile); | ||
if (optionsResult.kind === "ERROR") { | ||
console.error(optionsResult.err.formatDiagnosticsWithColorAndContext()); | ||
process.exit(1); | ||
} | ||
var parsed = (0, _1.getParsedTsConfig)(tsconfig); | ||
var options = (0, lib_1.validateGratsOptions)(parsed); | ||
// FIXME: Validate config! | ||
// https://github.com/tsconfig/bases | ||
return buildSchema(options); | ||
var options = optionsResult.value; | ||
var config = options.raw.grats; | ||
var schema = buildSchema(options); | ||
var dest = (0, path_1.resolve)((0, path_1.dirname)(configFile), config.tsSchema); | ||
var code = (0, printSchema_1.printExecutableSchema)(schema, config, dest); | ||
(0, fs_1.writeFileSync)(dest, code); | ||
console.error("Grats: Wrote TypeScript schema to `".concat(dest, "`.")); | ||
var sortedSchema = (0, graphql_1.lexicographicSortSchema)(schema); | ||
var schemaStr = (0, printSchema_1.printGratsSDL)(sortedSchema, config); | ||
var absOutput = (0, path_1.resolve)((0, path_1.dirname)(configFile), config.graphqlSchema); | ||
(0, fs_1.writeFileSync)(absOutput, schemaStr); | ||
console.error("Grats: Wrote schema to `".concat(absOutput, "`.")); | ||
} | ||
@@ -112,0 +114,0 @@ function buildSchema(options) { |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultArgPropertyMissingName = exports.defaultArgElementIsNotAssignment = exports.defaultValueIsNotLiteral = exports.ambiguousNumberType = exports.expectedOneNonNullishType = exports.propertyFieldMissingType = exports.cannotResolveSymbolForDescription = exports.promiseMissingTypeArg = 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 = void 0; | ||
@@ -9,3 +9,3 @@ 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.implementsTagMissingValue = exports.mergedInterfaces = exports.nonNullTypeCannotBeOptional = exports.killsParentOnExceptionOnNullable = exports.killsParentOnExceptionWithWrongConfig = exports.expectedIdentifier = exports.pluralTypeMissingParameter = exports.unknownGraphQLType = exports.unsupportedTypeLiteral = exports.defaultArgPropertyMissingInitializer = void 0; | ||
mergedInterfaces: "https://grats.capt.dev/docs/docblock-tags/interfaces/#merged-interfaces", | ||
parameterProperties: "https://grats.capt.dev/docs/docblock-tags/fields#class-based-fields" | ||
parameterProperties: "https://grats.capt.dev/docs/docblock-tags/fields#class-based-fields", | ||
}; | ||
@@ -12,0 +12,0 @@ /** |
@@ -110,5 +110,5 @@ import { FieldDefinitionNode, InputValueDefinitionNode, NamedTypeNode, NameNode, TypeNode, StringValueNode, ConstValueNode, ConstDirectiveNode, EnumValueDefinitionNode, ConstObjectFieldNode, ConstObjectValueNode, ConstListValueNode } from "graphql"; | ||
handleErrorBubbling(parentNode: ts.Node, type: TypeNode): TypeNode; | ||
exportDirective(nameNode: ts.Node, jsModulePath: string, tsModulePath: string, functionName: string): ConstDirectiveNode; | ||
exportDirective(nameNode: ts.Node, jsModulePath: string, tsModulePath: string, functionName: string, argCount: number): ConstDirectiveNode; | ||
fieldNameDirective(nameNode: ts.Node, name: string): ConstDirectiveNode; | ||
} | ||
export {}; |
@@ -29,3 +29,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Extractor = exports.ALL_TAGS = exports.KILLS_PARENT_ON_EXCEPTION_TAG = exports.IMPLEMENTS_TAG_DEPRECATED = exports.INPUT_TAG = exports.UNION_TAG = exports.ENUM_TAG = exports.INTERFACE_TAG = exports.SCALAR_TAG = exports.FIELD_TAG = exports.TYPE_TAG = exports.ISSUE_URL = exports.LIBRARY_NAME = exports.LIBRARY_IMPORT_NAME = void 0; | ||
@@ -149,3 +149,3 @@ var graphql_1 = require("graphql"); | ||
try { | ||
if (ALL_TAGS_1_1 && !ALL_TAGS_1_1.done && (_a = ALL_TAGS_1["return"])) _a.call(ALL_TAGS_1); | ||
if (ALL_TAGS_1_1 && !ALL_TAGS_1_1.done && (_a = ALL_TAGS_1.return)) _a.call(ALL_TAGS_1); | ||
} | ||
@@ -233,3 +233,3 @@ finally { if (e_1) throw e_1.error; } | ||
length: length, | ||
relatedInformation: relatedInformation | ||
relatedInformation: relatedInformation, | ||
}); | ||
@@ -252,3 +252,3 @@ return null; | ||
length: node.getWidth(), | ||
messageText: message | ||
messageText: message, | ||
}; | ||
@@ -286,3 +286,3 @@ }; | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
@@ -331,3 +331,3 @@ finally { if (e_2) throw e_2.error; } | ||
var directives = [ | ||
this.exportDirective(funcName, jsModulePath, tsModulePath, funcName.text), | ||
this.exportDirective(funcName, jsModulePath, tsModulePath, funcName.text, node.parameters.length), | ||
]; | ||
@@ -415,3 +415,3 @@ if (isStream) { | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
@@ -671,3 +671,3 @@ finally { if (e_3) throw e_3.error; } | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
@@ -772,3 +772,3 @@ finally { if (e_4) throw e_4.error; } | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
@@ -795,3 +795,3 @@ finally { if (e_5) throw e_5.error; } | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
@@ -812,3 +812,3 @@ finally { if (e_6) throw e_6.error; } | ||
else if (this.isNullish(node)) { | ||
return this.gql["null"](node); | ||
return this.gql.null(node); | ||
} | ||
@@ -848,3 +848,3 @@ else if (node.kind === ts.SyntaxKind.TrueKeyword) { | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
@@ -877,3 +877,3 @@ finally { if (e_7) throw e_7.error; } | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
@@ -1017,3 +1017,3 @@ finally { if (e_8) throw e_8.error; } | ||
try { | ||
if (_d && !_d.done && (_a = _c["return"])) _a.call(_c); | ||
if (_d && !_d.done && (_a = _c.return)) _a.call(_c); | ||
} | ||
@@ -1043,3 +1043,3 @@ finally { if (e_9) throw e_9.error; } | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
@@ -1117,3 +1117,3 @@ finally { if (e_10) throw e_10.error; } | ||
declaration: declaration, | ||
firstReference: node.type.typeName | ||
firstReference: node.type.typeName, | ||
}; | ||
@@ -1415,3 +1415,3 @@ } | ||
/* Grats directives */ | ||
Extractor.prototype.exportDirective = function (nameNode, jsModulePath, tsModulePath, functionName) { | ||
Extractor.prototype.exportDirective = function (nameNode, jsModulePath, tsModulePath, functionName, argCount) { | ||
return this.gql.constDirective(nameNode, this.gql.name(nameNode, serverDirectives_1.EXPORTED_DIRECTIVE), [ | ||
@@ -1421,2 +1421,3 @@ this.gql.constArgument(nameNode, this.gql.name(nameNode, serverDirectives_1.JS_MODULE_PATH_ARG), this.gql.string(nameNode, jsModulePath)), | ||
this.gql.constArgument(nameNode, this.gql.name(nameNode, serverDirectives_1.EXPORTED_FUNCTION_NAME_ARG), this.gql.string(nameNode, functionName)), | ||
this.gql.constArgument(nameNode, this.gql.name(nameNode, serverDirectives_1.ARG_COUNT), this.gql.int(nameNode, String(argCount))), | ||
]); | ||
@@ -1423,0 +1424,0 @@ }; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GraphQLConstructor = void 0; | ||
@@ -16,3 +16,3 @@ var graphql_1 = require("graphql"); | ||
name: name, | ||
types: types | ||
types: types, | ||
}; | ||
@@ -28,3 +28,3 @@ }; | ||
fields: fields, | ||
interfaces: interfaces !== null && interfaces !== void 0 ? interfaces : undefined | ||
interfaces: interfaces !== null && interfaces !== void 0 ? interfaces : undefined, | ||
}; | ||
@@ -40,3 +40,3 @@ }; | ||
fields: fields, | ||
interfaces: interfaces !== null && interfaces !== void 0 ? interfaces : undefined | ||
interfaces: interfaces !== null && interfaces !== void 0 ? interfaces : undefined, | ||
}; | ||
@@ -50,3 +50,3 @@ }; | ||
name: name, | ||
values: values | ||
values: values, | ||
}; | ||
@@ -60,3 +60,3 @@ }; | ||
onType: onType, | ||
field: field | ||
field: field, | ||
}; | ||
@@ -73,3 +73,3 @@ }; | ||
arguments: args !== null && args !== void 0 ? args : undefined, | ||
directives: this._optionalList(directives) | ||
directives: this._optionalList(directives), | ||
}; | ||
@@ -88,3 +88,3 @@ }; | ||
defaultValue: defaultValue !== null && defaultValue !== void 0 ? defaultValue : undefined, | ||
directives: this._optionalList(directives) | ||
directives: this._optionalList(directives), | ||
}; | ||
@@ -98,3 +98,3 @@ }; | ||
name: name, | ||
directives: directives | ||
directives: directives, | ||
}; | ||
@@ -108,3 +108,3 @@ }; | ||
name: name, | ||
directives: undefined | ||
directives: undefined, | ||
}; | ||
@@ -119,3 +119,3 @@ }; | ||
fields: fields !== null && fields !== void 0 ? fields : undefined, | ||
directives: this._optionalList(directives) | ||
directives: this._optionalList(directives), | ||
}; | ||
@@ -131,3 +131,3 @@ }; | ||
loc: this._loc(node), | ||
name: this.name(node, value) | ||
name: this.name(node, value), | ||
}; | ||
@@ -166,3 +166,3 @@ }; | ||
name: name, | ||
arguments: this._optionalList(args) | ||
arguments: this._optionalList(args), | ||
}; | ||
@@ -179,3 +179,3 @@ }; | ||
}; | ||
GraphQLConstructor.prototype["null"] = function (node) { | ||
GraphQLConstructor.prototype.null = function (node) { | ||
return { kind: graphql_1.Kind.NULL, loc: this._loc(node) }; | ||
@@ -182,0 +182,0 @@ }; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveRelativePath = exports.getRelativeOutputPath = void 0; | ||
@@ -4,0 +4,0 @@ var path_1 = require("path"); |
@@ -1,10 +0,6 @@ | ||
import { GraphQLSchema } from "graphql"; | ||
import { ParsedCommandLineGrats } from "./lib"; | ||
import { ReportableDiagnostics, Result } from "./utils/DiagnosticError"; | ||
export * from "./Types"; | ||
export * from "./lib"; | ||
type RuntimeOptions = { | ||
emitSchemaFile?: string; | ||
}; | ||
export declare function extractGratsSchemaAtRuntime(runtimeOptions: RuntimeOptions): GraphQLSchema; | ||
export declare function buildSchemaFromSDL(sdl: string): GraphQLSchema; | ||
export declare function getParsedTsConfig(configPath?: string): ParsedCommandLineGrats; | ||
export { codegen } from "./codegen"; | ||
export declare function getParsedTsConfig(configFile: string): Result<ParsedCommandLineGrats, ReportableDiagnostics>; |
@@ -16,39 +16,13 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
exports.getParsedTsConfig = exports.buildSchemaFromSDL = exports.extractGratsSchemaAtRuntime = void 0; | ||
var graphql_1 = require("graphql"); | ||
var fs = require("fs"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getParsedTsConfig = exports.codegen = void 0; | ||
var ts = require("typescript"); | ||
var lib_1 = require("./lib"); | ||
var printSchema_1 = require("./printSchema"); | ||
var DiagnosticError_1 = require("./utils/DiagnosticError"); | ||
__exportStar(require("./Types"), exports); | ||
__exportStar(require("./lib"), exports); | ||
// Build an executable schema from a set of files. Note that if extraction | ||
// fails, this function will exit the process and print a helpful error | ||
// message. | ||
function extractGratsSchemaAtRuntime(runtimeOptions) { | ||
var parsedTsConfig = getParsedTsConfig(); | ||
var schemaResult = (0, lib_1.buildSchemaResult)(parsedTsConfig); | ||
if (schemaResult.kind === "ERROR") { | ||
console.error(schemaResult.err.formatDiagnosticsWithColorAndContext()); | ||
process.exit(1); | ||
} | ||
var runtimeSchema = schemaResult.value; | ||
if (runtimeOptions.emitSchemaFile) { | ||
runtimeSchema = (0, graphql_1.lexicographicSortSchema)(runtimeSchema); | ||
var sdl = (0, printSchema_1.printGratsSchema)(runtimeSchema, parsedTsConfig.raw.grats); | ||
var filePath = runtimeOptions.emitSchemaFile; | ||
fs.writeFileSync(filePath, sdl); | ||
} | ||
return runtimeSchema; | ||
} | ||
exports.extractGratsSchemaAtRuntime = extractGratsSchemaAtRuntime; | ||
function buildSchemaFromSDL(sdl) { | ||
var schema = (0, graphql_1.buildSchema)(sdl); | ||
return (0, lib_1.applyServerDirectives)(schema); | ||
} | ||
exports.buildSchemaFromSDL = buildSchemaFromSDL; | ||
var codegen_1 = require("./codegen"); | ||
Object.defineProperty(exports, "codegen", { enumerable: true, get: function () { return codegen_1.codegen; } }); | ||
// #FIXME: Report diagnostics instead of throwing! | ||
function getParsedTsConfig(configPath) { | ||
var configFile = configPath || ts.findConfigFile(process.cwd(), ts.sys.fileExists); | ||
function getParsedTsConfig(configFile) { | ||
if (!configFile) { | ||
@@ -60,7 +34,10 @@ throw new Error("Grats: Could not find tsconfig.json"); | ||
var parsed = ts.getParsedCommandLineOfConfigFile(configFile, undefined, configFileHost); | ||
if (!parsed || parsed.errors.length > 0) { | ||
throw new Error("Grats: Could not parse tsconfig.json"); | ||
if (!parsed) { | ||
throw new Error("Grats: Could not locate tsconfig.json"); | ||
} | ||
return (0, lib_1.validateGratsOptions)(parsed); | ||
if (parsed.errors.length > 0) { | ||
return (0, DiagnosticError_1.err)(DiagnosticError_1.ReportableDiagnostics.fromDiagnostics(parsed.errors)); | ||
} | ||
return (0, DiagnosticError_1.ok)((0, lib_1.validateGratsOptions)(parsed)); | ||
} | ||
exports.getParsedTsConfig = getParsedTsConfig; |
@@ -13,3 +13,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.computeInterfaceMap = void 0; | ||
@@ -47,3 +47,3 @@ var DiagnosticError_1 = require("./utils/DiagnosticError"); | ||
kind: "INTERFACE", | ||
name: doc.name.value | ||
name: doc.name.value, | ||
}); | ||
@@ -55,3 +55,3 @@ } | ||
try { | ||
if (_g && !_g.done && (_b = _f["return"])) _b.call(_f); | ||
if (_g && !_g.done && (_b = _f.return)) _b.call(_f); | ||
} | ||
@@ -77,3 +77,3 @@ finally { if (e_2) throw e_2.error; } | ||
try { | ||
if (_j && !_j.done && (_c = _h["return"])) _c.call(_h); | ||
if (_j && !_j.done && (_c = _h.return)) _c.call(_h); | ||
} | ||
@@ -89,3 +89,3 @@ finally { if (e_3) throw e_3.error; } | ||
try { | ||
if (docs_1_1 && !docs_1_1.done && (_a = docs_1["return"])) _a.call(docs_1); | ||
if (docs_1_1 && !docs_1_1.done && (_a = docs_1.return)) _a.call(docs_1); | ||
} | ||
@@ -92,0 +92,0 @@ finally { if (e_1) throw e_1.error; } |
import { GraphQLSchema } from "graphql"; | ||
import { Result, ReportableDiagnostics } from "./utils/DiagnosticError"; | ||
import * as ts from "typescript"; | ||
export { applyServerDirectives } from "./serverDirectives"; | ||
export type ConfigOptions = { | ||
nullableByDefault?: boolean; | ||
reportTypeScriptTypeErrors?: boolean; | ||
schemaHeader?: string | null; | ||
}; | ||
export type ParsedCommandLineGrats = ts.ParsedCommandLine & { | ||
raw: { | ||
grats: ConfigOptions; | ||
}; | ||
}; | ||
import { ParsedCommandLineGrats } from "./gratsConfig"; | ||
export * from "./gratsConfig"; | ||
export declare function buildSchemaResult(options: ParsedCommandLineGrats): Result<GraphQLSchema, ReportableDiagnostics>; | ||
export declare function buildSchemaResultWithHost(options: ParsedCommandLineGrats, compilerHost: ts.CompilerHost): Result<GraphQLSchema, ReportableDiagnostics>; | ||
export declare function validateGratsOptions(options: ts.ParsedCommandLine): ParsedCommandLineGrats; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
@@ -24,2 +13,5 @@ if (k2 === undefined) k2 = k; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
@@ -36,4 +28,4 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
}; | ||
exports.__esModule = true; | ||
exports.validateGratsOptions = exports.buildSchemaResultWithHost = exports.buildSchemaResult = exports.applyServerDirectives = void 0; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.buildSchemaResultWithHost = exports.buildSchemaResult = void 0; | ||
var graphql_1 = require("graphql"); | ||
@@ -47,4 +39,3 @@ var DiagnosticError_1 = require("./utils/DiagnosticError"); | ||
var helpers_1 = require("./utils/helpers"); | ||
var serverDirectives_2 = require("./serverDirectives"); | ||
__createBinding(exports, serverDirectives_2, "applyServerDirectives"); | ||
__exportStar(require("./gratsConfig"), exports); | ||
// Construct a schema, using GraphQL schema language | ||
@@ -65,32 +56,5 @@ // Exported for tests that want to intercept diagnostic errors. | ||
} | ||
return (0, DiagnosticError_1.ok)((0, serverDirectives_1.applyServerDirectives)(schemaResult.value)); | ||
return (0, DiagnosticError_1.ok)(schemaResult.value); | ||
} | ||
exports.buildSchemaResultWithHost = buildSchemaResultWithHost; | ||
var DEFAULT_HEADER = "# Schema generated by Grats (https://grats.capt.dev)\n# Do not manually edit. Regenerate by running `npx grats`.\n# @generated"; | ||
// TODO: Make this return diagnostics | ||
function validateGratsOptions(options) { | ||
var _a, _b; | ||
var gratsOptions = __assign({}, ((_b = (_a = options.raw) === null || _a === void 0 ? void 0 : _a.grats) !== null && _b !== void 0 ? _b : {})); | ||
if (gratsOptions.nullableByDefault === undefined) { | ||
gratsOptions.nullableByDefault = true; | ||
} | ||
else if (typeof gratsOptions.nullableByDefault !== "boolean") { | ||
throw new Error("Grats: The Grats config option `nullableByDefault` must be a boolean if provided."); | ||
} | ||
if (gratsOptions.reportTypeScriptTypeErrors === undefined) { | ||
gratsOptions.reportTypeScriptTypeErrors = false; | ||
} | ||
else if (typeof gratsOptions.reportTypeScriptTypeErrors !== "boolean") { | ||
throw new Error("Grats: The Grats config option `reportTypeScriptTypeErrors` must be a boolean if provided."); | ||
} | ||
if (gratsOptions.schemaHeader === undefined) { | ||
gratsOptions.schemaHeader = DEFAULT_HEADER; | ||
} | ||
else if (typeof gratsOptions.schemaHeader !== "string" && | ||
gratsOptions.schemaHeader !== null) { | ||
throw new Error("Grats: The Grats config option `schemaHeader` must be a string or `null` if provided."); | ||
} | ||
return __assign(__assign({}, options), { raw: __assign(__assign({}, options.raw), { grats: gratsOptions }) }); | ||
} | ||
exports.validateGratsOptions = validateGratsOptions; | ||
function extractSchema(options, host) { | ||
@@ -144,3 +108,3 @@ var e_1, _a, e_2, _b; | ||
try { | ||
if (_f && !_f.done && (_b = _e["return"])) _b.call(_e); | ||
if (_f && !_f.done && (_b = _e.return)) _b.call(_e); | ||
} | ||
@@ -154,3 +118,3 @@ finally { if (e_2) throw e_2.error; } | ||
try { | ||
if (_d && !_d.done && (_a = _c["return"])) _a.call(_c); | ||
if (_d && !_d.done && (_a = _c.return)) _a.call(_c); | ||
} | ||
@@ -171,3 +135,3 @@ finally { if (e_1) throw e_1.error; } | ||
kind: graphql_1.Kind.DOCUMENT, | ||
definitions: definitionsResult.value | ||
definitions: definitionsResult.value, | ||
}); | ||
@@ -229,3 +193,3 @@ if (docResult.kind === "ERROR") | ||
try { | ||
if (typeImplementors_1_1 && !typeImplementors_1_1.done && (_b = typeImplementors_1["return"])) _b.call(typeImplementors_1); | ||
if (typeImplementors_1_1 && !typeImplementors_1_1.done && (_b = typeImplementors_1.return)) _b.call(typeImplementors_1); | ||
} | ||
@@ -239,3 +203,3 @@ finally { if (e_4) throw e_4.error; } | ||
try { | ||
if (abstractTypes_1_1 && !abstractTypes_1_1.done && (_a = abstractTypes_1["return"])) _a.call(abstractTypes_1); | ||
if (abstractTypes_1_1 && !abstractTypes_1_1.done && (_a = abstractTypes_1.return)) _a.call(abstractTypes_1); | ||
} | ||
@@ -242,0 +206,0 @@ finally { if (e_3) throw e_3.error; } |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.locate = void 0; | ||
@@ -4,0 +4,0 @@ var graphql_1 = require("graphql"); |
import { GraphQLSchema } from "graphql"; | ||
import { ConfigOptions } from "./lib"; | ||
export declare function printGratsSchema(schema: GraphQLSchema, config: ConfigOptions): string; | ||
/** | ||
* Prints code for a TypeScript module that exports a GraphQLSchema. | ||
* Includes the user-defined (or default) header comment if provided. | ||
*/ | ||
export declare function printExecutableSchema(schema: GraphQLSchema, config: ConfigOptions, destination: string): string; | ||
/** | ||
* Prints SDL, potentially omitting directives depending upon the config. | ||
* Includes the user-defined (or default) header comment if provided. | ||
*/ | ||
export declare function printGratsSDL(schema: GraphQLSchema, config: ConfigOptions): string; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.printGratsSchema = void 0; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.printGratsSDL = exports.printExecutableSchema = void 0; | ||
var utils_1 = require("@graphql-tools/utils"); | ||
function printGratsSchema(schema, config) { | ||
var sdl = (0, utils_1.printSchemaWithDirectives)(schema, { | ||
assumeValid: true | ||
}); | ||
var graphql_1 = require("graphql"); | ||
var codegen_1 = require("./codegen"); | ||
/** | ||
* Prints code for a TypeScript module that exports a GraphQLSchema. | ||
* Includes the user-defined (or default) header comment if provided. | ||
*/ | ||
function printExecutableSchema(schema, config, destination) { | ||
var code = (0, codegen_1.codegen)(schema, destination); | ||
if (config.tsSchemaHeader) { | ||
return "".concat(config.tsSchemaHeader, "\n").concat(code); | ||
} | ||
return code; | ||
} | ||
exports.printExecutableSchema = printExecutableSchema; | ||
/** | ||
* Prints SDL, potentially omitting directives depending upon the config. | ||
* Includes the user-defined (or default) header comment if provided. | ||
*/ | ||
function printGratsSDL(schema, config) { | ||
var includeDirectives = !config.graphqlSchema; | ||
var sdl = printSDL(schema, includeDirectives); | ||
if (config.schemaHeader) { | ||
@@ -14,2 +42,13 @@ return "".concat(config.schemaHeader, "\n").concat(sdl); | ||
} | ||
exports.printGratsSchema = printGratsSchema; | ||
exports.printGratsSDL = printGratsSDL; | ||
function printSDL(schema, includeDirectives) { | ||
if (includeDirectives) { | ||
return (0, utils_1.printSchemaWithDirectives)(schema, { | ||
assumeValid: true, | ||
}); | ||
} | ||
return (0, graphql_1.printSchema)(new graphql_1.GraphQLSchema(__assign(__assign({}, schema.toConfig()), { | ||
// TODO: Only filter out our directives. Note that | ||
// the playground duplicates this logic. | ||
directives: [] }))); | ||
} |
@@ -1,2 +0,2 @@ | ||
import { DocumentNode, GraphQLSchema } from "graphql"; | ||
import { DocumentNode } from "graphql"; | ||
export declare const METHOD_NAME_DIRECTIVE = "methodName"; | ||
@@ -7,5 +7,5 @@ export declare const METHOD_NAME_ARG = "name"; | ||
export declare const TS_MODULE_PATH_ARG = "tsModulePath"; | ||
export declare const ARG_COUNT = "argCount"; | ||
export declare const EXPORTED_FUNCTION_NAME_ARG = "functionName"; | ||
export declare const ASYNC_ITERABLE_TYPE_DIRECTIVE = "asyncIterable"; | ||
export declare const DIRECTIVES_AST: DocumentNode; | ||
export declare function applyServerDirectives(schema: GraphQLSchema): GraphQLSchema; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
exports.__esModule = true; | ||
exports.applyServerDirectives = exports.DIRECTIVES_AST = exports.ASYNC_ITERABLE_TYPE_DIRECTIVE = exports.EXPORTED_FUNCTION_NAME_ARG = exports.TS_MODULE_PATH_ARG = exports.JS_MODULE_PATH_ARG = exports.EXPORTED_DIRECTIVE = exports.METHOD_NAME_ARG = exports.METHOD_NAME_DIRECTIVE = void 0; | ||
var utils_1 = require("@graphql-tools/utils"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DIRECTIVES_AST = exports.ASYNC_ITERABLE_TYPE_DIRECTIVE = exports.EXPORTED_FUNCTION_NAME_ARG = exports.ARG_COUNT = exports.TS_MODULE_PATH_ARG = exports.JS_MODULE_PATH_ARG = exports.EXPORTED_DIRECTIVE = exports.METHOD_NAME_ARG = exports.METHOD_NAME_DIRECTIVE = void 0; | ||
var graphql_1 = require("graphql"); | ||
var gratsRoot_1 = require("./gratsRoot"); | ||
// TODO: Rename to be generic since it can apply to properties as well as methods. | ||
@@ -60,125 +11,5 @@ exports.METHOD_NAME_DIRECTIVE = "methodName"; | ||
exports.TS_MODULE_PATH_ARG = "tsModulePath"; | ||
exports.ARG_COUNT = "argCount"; | ||
exports.EXPORTED_FUNCTION_NAME_ARG = "functionName"; | ||
exports.ASYNC_ITERABLE_TYPE_DIRECTIVE = "asyncIterable"; | ||
exports.DIRECTIVES_AST = (0, graphql_1.parse)("\n directive @".concat(exports.ASYNC_ITERABLE_TYPE_DIRECTIVE, " on FIELD_DEFINITION\n directive @").concat(exports.METHOD_NAME_DIRECTIVE, "(").concat(exports.METHOD_NAME_ARG, ": String!) on FIELD_DEFINITION\n directive @").concat(exports.EXPORTED_DIRECTIVE, "(\n ").concat(exports.JS_MODULE_PATH_ARG, ": String!,\n ").concat(exports.TS_MODULE_PATH_ARG, ": String!,\n ").concat(exports.EXPORTED_FUNCTION_NAME_ARG, ": String!\n ) on FIELD_DEFINITION\n")); | ||
function applyServerDirectives(schema) { | ||
// TODO: Throw if the schema is missing our directives! | ||
var _a; | ||
// TODO: Do we really need all of mapSchema here or can we create our own | ||
// thing that's simpler. | ||
return (0, utils_1.mapSchema)(schema, (_a = {}, | ||
_a[utils_1.MapperKind.OBJECT_FIELD] = function (fieldConfig) { | ||
var _a, _b, _c; | ||
var newFieldConfig = fieldConfig; | ||
var methodNameDirective = (_a = (0, utils_1.getDirective)(schema, fieldConfig, exports.METHOD_NAME_DIRECTIVE)) === null || _a === void 0 ? void 0 : _a[0]; | ||
if (methodNameDirective != null) { | ||
newFieldConfig = applyMethodNameDirective(newFieldConfig, methodNameDirective); | ||
} | ||
var exportedDirective = (_b = (0, utils_1.getDirective)(schema, fieldConfig, exports.EXPORTED_DIRECTIVE)) === null || _b === void 0 ? void 0 : _b[0]; | ||
if (exportedDirective != null) { | ||
newFieldConfig = applyExportDirective(newFieldConfig, exportedDirective); | ||
} | ||
var asyncIterableDirective = (_c = (0, utils_1.getDirective)(schema, fieldConfig, exports.ASYNC_ITERABLE_TYPE_DIRECTIVE)) === null || _c === void 0 ? void 0 : _c[0]; | ||
if (asyncIterableDirective != null) { | ||
newFieldConfig = __assign(__assign({}, newFieldConfig), { subscribe: newFieldConfig.resolve, resolve: function (payload) { return payload; } }); | ||
} | ||
return newFieldConfig; | ||
}, | ||
_a)); | ||
} | ||
exports.applyServerDirectives = applyServerDirectives; | ||
/** | ||
* Field renaming directive: | ||
* | ||
* By default, when resolving a field, the server will take the schema field | ||
* name, and look for a resolver/property by that name on the parent object. | ||
* Since we support exposing a method/property under a different name, we need | ||
* to modify that field's resolver to look for the implementation name rather | ||
* than the schema name. | ||
*/ | ||
function applyMethodNameDirective(fieldConfig, methodNameDirective) { | ||
var _a = fieldConfig.resolve, resolve = _a === void 0 ? graphql_1.defaultFieldResolver : _a; | ||
return __assign(__assign({}, fieldConfig), { resolve: function (source, args, context, info) { | ||
var newInfo = __assign(__assign({}, info), { fieldName: methodNameDirective[exports.METHOD_NAME_ARG] }); | ||
return resolve(source, args, context, newInfo); | ||
} }); | ||
} | ||
/** | ||
* Export directive: | ||
* | ||
* By default, when resolving a field, the server will look for a resolver | ||
* function on the parent object. This directive allows you to specify a | ||
* module and function name to import and use as the resolver. | ||
*/ | ||
function applyExportDirective(fieldConfig, methodNameDirective) { | ||
// TODO: Does this work in the browser? | ||
var jsModulePath = (0, gratsRoot_1.resolveRelativePath)(methodNameDirective[exports.JS_MODULE_PATH_ARG]); | ||
var tsModulePath = (0, gratsRoot_1.resolveRelativePath)(methodNameDirective[exports.TS_MODULE_PATH_ARG]); | ||
var functionName = methodNameDirective[exports.EXPORTED_FUNCTION_NAME_ARG]; | ||
var mod = undefined; | ||
var modPromise = undefined; | ||
return __assign(__assign({}, fieldConfig), { resolve: function (source, args, context, info) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var e_1, resolve; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (modPromise == null) { | ||
modPromise = importWithFallback(jsModulePath, tsModulePath); | ||
} | ||
if (!(mod == null)) return [3 /*break*/, 4]; | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, modPromise]; | ||
case 2: | ||
mod = _a.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
e_1 = _a.sent(); | ||
console.error(loadModuleErrorMessage(jsModulePath, tsModulePath)); | ||
throw e_1; | ||
case 4: | ||
resolve = mod[functionName]; | ||
if (typeof resolve !== "function") { | ||
// TODO: Better error message that indicates if it was loaded from JS or TS. | ||
throw new Error("Grats Error: Expected `".concat(tsModulePath, "` to have a named export `").concat(functionName, "` that is a function, but it was `").concat(typeof resolve, "`. You may need to rerun Grats or regenerate the JavaScript version of your module by rerunning the TypeScript compiler.")); | ||
} | ||
return [2 /*return*/, resolve(source, args, context, info)]; | ||
} | ||
}); | ||
}); | ||
} }); | ||
} | ||
// When people use Grats with loaders like `esbuild-register` or `ts-node`, the | ||
// compiled JavaScript version of the file may not exist on disk. In these specific | ||
// cases, esbuild or ts-node can load the file via its TypeScript source, so we try | ||
// falling back to that. | ||
function importWithFallback(jsModulePath, tsModulePath) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var e_2; | ||
return __generator(this, function (_a) { | ||
var _b, _c; | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 4]); | ||
return [4 /*yield*/, (_b = tsModulePath, Promise.resolve().then(function () { return require(_b); }))]; | ||
case 1: | ||
// We start with the .ts version because if both exist, and can be loaded, the .ts version is | ||
// going to be more up to date. The downside is that this causes some extra work to be done in | ||
// in prod. This should be manageable since we cache the loaded module for each field. | ||
// It's important that we await here so that we catch the error if the module doesn't exist or | ||
// cannot be parsed. | ||
return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
e_2 = _a.sent(); | ||
return [4 /*yield*/, (_c = jsModulePath, Promise.resolve().then(function () { return require(_c); }))]; | ||
case 3: return [2 /*return*/, _a.sent()]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
function loadModuleErrorMessage(jsPath, tsPath) { | ||
return "Grats Error: Failed to import module. Tried loading from two locations:\n* `".concat(jsPath, "`\n* `").concat(tsPath, "`\n\nThis can happen for a few reasons:\n\n* You resolver has moved and you need to rerun Grats to regenerate your schema.\n* Your TypeScript code has changed and you need to rerun `tsc` to generate the JavaScript variant of the file.\n* You compiled your TypeScript with a different TSConfig than what you ran Grats with.\n* The Grats NPM module moved between when you ran Grats and when you ran your server."); | ||
} | ||
exports.DIRECTIVES_AST = (0, graphql_1.parse)("\n directive @".concat(exports.ASYNC_ITERABLE_TYPE_DIRECTIVE, " on FIELD_DEFINITION\n directive @").concat(exports.METHOD_NAME_DIRECTIVE, "(").concat(exports.METHOD_NAME_ARG, ": String!) on FIELD_DEFINITION\n directive @").concat(exports.EXPORTED_DIRECTIVE, "(\n ").concat(exports.JS_MODULE_PATH_ARG, ": String!,\n ").concat(exports.TS_MODULE_PATH_ARG, ": String!,\n ").concat(exports.EXPORTED_FUNCTION_NAME_ARG, ": String!\n ").concat(exports.ARG_COUNT, ": Int!\n ) on FIELD_DEFINITION\n")); |
@@ -60,3 +60,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var path = require("path"); | ||
@@ -70,3 +70,5 @@ var TestRunner_1 = require("./TestRunner"); | ||
var DiagnosticError_1 = require("../utils/DiagnosticError"); | ||
var printSchema_1 = require("../printSchema"); | ||
var fs_1 = require("fs"); | ||
var codegen_1 = require("../codegen"); | ||
var utils_1 = require("@graphql-tools/utils"); | ||
var program = new commander_1.Command(); | ||
@@ -81,3 +83,3 @@ program | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
var filterRegex, failures, testDirs_1, testDirs_1_1, _b, fixturesDir_1, transformer, runner, e_1_1; | ||
var filterRegex, failures, testDirs_1, testDirs_1_1, _b, fixturesDir_1, transformer, testFilePattern, ignoreFilePattern, runner, e_1_1; | ||
var e_1, _c; | ||
@@ -96,4 +98,4 @@ return __generator(this, function (_d) { | ||
if (!!testDirs_1_1.done) return [3 /*break*/, 5]; | ||
_b = testDirs_1_1.value, fixturesDir_1 = _b.fixturesDir, transformer = _b.transformer; | ||
runner = new TestRunner_1["default"](fixturesDir_1, !!write, filterRegex, transformer); | ||
_b = testDirs_1_1.value, fixturesDir_1 = _b.fixturesDir, transformer = _b.transformer, testFilePattern = _b.testFilePattern, ignoreFilePattern = _b.ignoreFilePattern; | ||
runner = new TestRunner_1.default(fixturesDir_1, !!write, filterRegex, testFilePattern, ignoreFilePattern, transformer); | ||
return [4 /*yield*/, runner.run()]; | ||
@@ -113,3 +115,3 @@ case 3: | ||
try { | ||
if (testDirs_1_1 && !testDirs_1_1.done && (_c = testDirs_1["return"])) _c.call(testDirs_1); | ||
if (testDirs_1_1 && !testDirs_1_1.done && (_c = testDirs_1.return)) _c.call(testDirs_1); | ||
} | ||
@@ -130,5 +132,8 @@ finally { if (e_1) throw e_1.error; } | ||
var integrationFixturesDir = path.join(__dirname, "integrationFixtures"); | ||
var codegenFixturesDir = path.join(__dirname, "codegenFixtures"); | ||
var testDirs = [ | ||
{ | ||
fixturesDir: fixturesDir, | ||
testFilePattern: /\.ts$/, | ||
ignoreFilePattern: null, | ||
transformer: function (code, fileName) { | ||
@@ -138,3 +143,3 @@ var firstLine = code.split("\n")[0]; | ||
nullableByDefault: true, | ||
schemaHeader: null | ||
schemaHeader: null, | ||
}; | ||
@@ -150,6 +155,6 @@ if (firstLine.startsWith("// {")) { | ||
raw: { | ||
grats: options | ||
grats: options, | ||
}, | ||
errors: [], | ||
fileNames: files | ||
fileNames: files, | ||
}); | ||
@@ -164,2 +169,4 @@ // https://stackoverflow.com/a/66604532/1263117 | ||
} | ||
// We run codegen here just ensure that it doesn't throw. | ||
(0, codegen_1.codegen)(schemaResult.value, "".concat(fixturesDir, "/").concat(fileName)); | ||
var LOCATION_REGEX = /^\/\/ Locate: (.*)/; | ||
@@ -177,26 +184,24 @@ var locationMatch = code.match(LOCATION_REGEX); | ||
else { | ||
return (0, printSchema_1.printGratsSchema)(schemaResult.value, options); | ||
return (0, utils_1.printSchemaWithDirectives)(schemaResult.value, { | ||
assumeValid: true, | ||
}); | ||
} | ||
} | ||
}, | ||
}, | ||
{ | ||
fixturesDir: integrationFixturesDir, | ||
testFilePattern: /index.ts$/, | ||
ignoreFilePattern: /schema.ts$/, | ||
transformer: function (code, fileName) { return __awaiter(void 0, void 0, void 0, function () { | ||
var filePath, server, options, files, parsedOptions, schemaResult, schema, data; | ||
var filePath, schemaPath, options, files, parsedOptions, schemaResult, tsSchema, server, schemaModule, data; | ||
return __generator(this, function (_a) { | ||
var _b; | ||
switch (_a.label) { | ||
case 0: | ||
filePath = "".concat(integrationFixturesDir, "/").concat(fileName); | ||
return [4 /*yield*/, (_b = filePath, Promise.resolve().then(function () { return require(_b); }))]; | ||
case 1: | ||
server = _a.sent(); | ||
if (server.query == null || typeof server.query !== "string") { | ||
throw new Error("Expected `".concat(filePath, "` to export a query text as `query`")); | ||
} | ||
schemaPath = path.join(path.dirname(filePath), "schema.ts"); | ||
options = { | ||
nullableByDefault: true | ||
nullableByDefault: true, | ||
}; | ||
files = [filePath, "src/Types.ts"]; | ||
parsedOptions = { | ||
parsedOptions = (0, lib_1.validateGratsOptions)({ | ||
options: { | ||
@@ -206,10 +211,10 @@ // Required to enable ts-node to locate function exports | ||
outDir: "dist", | ||
configFilePath: "tsconfig.json" | ||
configFilePath: "tsconfig.json", | ||
}, | ||
raw: { | ||
grats: options | ||
grats: options, | ||
}, | ||
errors: [], | ||
fileNames: files | ||
}; | ||
fileNames: files, | ||
}); | ||
schemaResult = (0, lib_1.buildSchemaResult)(parsedOptions); | ||
@@ -219,8 +224,18 @@ if (schemaResult.kind === "ERROR") { | ||
} | ||
schema = schemaResult.value; | ||
tsSchema = (0, codegen_1.codegen)(schemaResult.value, schemaPath); | ||
(0, fs_1.writeFileSync)(schemaPath, tsSchema); | ||
return [4 /*yield*/, Promise.resolve("".concat(filePath)).then(function (s) { return require(s); })]; | ||
case 1: | ||
server = _a.sent(); | ||
if (server.query == null || typeof server.query !== "string") { | ||
throw new Error("Expected `".concat(filePath, "` to export a query text as `query`")); | ||
} | ||
return [4 /*yield*/, Promise.resolve("".concat(schemaPath)).then(function (s) { return require(s); })]; | ||
case 2: | ||
schemaModule = _a.sent(); | ||
return [4 /*yield*/, (0, graphql_1.graphql)({ | ||
schema: schema, | ||
source: server.query | ||
schema: schemaModule.schema, | ||
source: server.query, | ||
})]; | ||
case 2: | ||
case 3: | ||
data = _a.sent(); | ||
@@ -230,5 +245,19 @@ return [2 /*return*/, JSON.stringify(data, null, 2)]; | ||
}); | ||
}); } | ||
}); }, | ||
}, | ||
{ | ||
fixturesDir: codegenFixturesDir, | ||
testFilePattern: /\.graphql$/, | ||
ignoreFilePattern: null, | ||
transformer: function (code, fileName) { return __awaiter(void 0, void 0, void 0, function () { | ||
var filePath, sdl, schema; | ||
return __generator(this, function (_a) { | ||
filePath = "".concat(codegenFixturesDir, "/").concat(fileName); | ||
sdl = (0, fs_1.readFileSync)(filePath, "utf8"); | ||
schema = (0, graphql_1.buildSchema)(sdl); | ||
return [2 /*return*/, (0, codegen_1.codegen)(schema, filePath)]; | ||
}); | ||
}); }, | ||
}, | ||
]; | ||
program.parse(); |
@@ -15,3 +15,3 @@ type Transformer = (code: string, filename: string) => Promise<string> | string; | ||
_transformer: Transformer; | ||
constructor(fixturesDir: string, write: boolean, filter: string | null, transformer: Transformer); | ||
constructor(fixturesDir: string, write: boolean, filter: string | null, testFilePattern: RegExp, ignoreFilePattern: RegExp | null, transformer: Transformer); | ||
run(): Promise<boolean>; | ||
@@ -18,0 +18,0 @@ _testFixture(fixture: string): Promise<void>; |
@@ -49,3 +49,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var fs = require("fs"); | ||
@@ -60,3 +60,3 @@ var path = require("path"); | ||
var TestRunner = /** @class */ (function () { | ||
function TestRunner(fixturesDir, write, filter, transformer) { | ||
function TestRunner(fixturesDir, write, filter, testFilePattern, ignoreFilePattern, transformer) { | ||
var e_1, _a; | ||
@@ -74,3 +74,3 @@ this._testFixtures = []; | ||
var fileName = _c.value; | ||
if (fileName.endsWith(".ts")) { | ||
if (testFilePattern.test(fileName)) { | ||
this._testFixtures.push(fileName); | ||
@@ -82,3 +82,3 @@ var filePath = path.join(fixturesDir, fileName); | ||
} | ||
else { | ||
else if (!ignoreFilePattern || !ignoreFilePattern.test(fileName)) { | ||
this._otherFiles.add(fileName); | ||
@@ -91,3 +91,3 @@ } | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
@@ -125,3 +125,3 @@ finally { if (e_1) throw e_1.error; } | ||
try { | ||
if (_b && !_b.done && (_g = _a["return"])) _g.call(_a); | ||
if (_b && !_b.done && (_g = _a.return)) _g.call(_a); | ||
} | ||
@@ -151,3 +151,3 @@ finally { if (e_2) throw e_2.error; } | ||
try { | ||
if (_d && !_d.done && (_h = _c["return"])) _h.call(_c); | ||
if (_d && !_d.done && (_h = _c.return)) _h.call(_c); | ||
} | ||
@@ -168,3 +168,3 @@ finally { if (e_3) throw e_3.error; } | ||
try { | ||
if (_f && !_f.done && (_j = _e["return"])) _j.call(_e); | ||
if (_f && !_f.done && (_j = _e.return)) _j.call(_e); | ||
} | ||
@@ -191,3 +191,3 @@ finally { if (e_4) throw e_4.error; } | ||
if (this._otherFiles.has(expectedFileName)) { | ||
this._otherFiles["delete"](expectedFileName); | ||
this._otherFiles.delete(expectedFileName); | ||
} | ||
@@ -247,3 +247,3 @@ else { | ||
}()); | ||
exports["default"] = TestRunner; | ||
exports.default = TestRunner; | ||
function readdirSyncRecursive(dir) { | ||
@@ -266,3 +266,3 @@ var e_6, _a, e_7, _b; | ||
try { | ||
if (_f && !_f.done && (_b = _e["return"])) _b.call(_e); | ||
if (_f && !_f.done && (_b = _e.return)) _b.call(_e); | ||
} | ||
@@ -280,3 +280,3 @@ finally { if (e_7) throw e_7.error; } | ||
try { | ||
if (_d && !_d.done && (_a = _c["return"])) _a.call(_c); | ||
if (_d && !_d.done && (_a = _c.return)) _a.call(_c); | ||
} | ||
@@ -283,0 +283,0 @@ finally { if (e_6) throw e_6.error; } |
@@ -24,3 +24,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TypeContext = exports.UNRESOLVED_REFERENCE_NAME = void 0; | ||
@@ -178,3 +178,3 @@ var graphql_1 = require("graphql"); | ||
try { | ||
if (_d && !_d.done && (_a = _c["return"])) _a.call(_c); | ||
if (_d && !_d.done && (_a = _c.return)) _a.call(_c); | ||
} | ||
@@ -214,3 +214,3 @@ finally { if (e_1) throw e_1.error; } | ||
try { | ||
if (docs_1_1 && !docs_1_1.done && (_a = docs_1["return"])) _a.call(docs_1); | ||
if (docs_1_1 && !docs_1_1.done && (_a = docs_1.return)) _a.call(docs_1); | ||
} | ||
@@ -251,3 +251,3 @@ finally { if (e_2) throw e_2.error; } | ||
fields: [doc.field], | ||
loc: doc.loc | ||
loc: doc.loc, | ||
}); | ||
@@ -266,3 +266,3 @@ break; | ||
name: doc.onType, | ||
fields: [__assign(__assign({}, doc.field), { directives: directives })] | ||
fields: [__assign(__assign({}, doc.field), { directives: directives })], | ||
}); | ||
@@ -275,3 +275,3 @@ try { | ||
value: implementor.name, | ||
loc: doc.loc | ||
loc: doc.loc, // Bit of a lie, but I don't see a better option. | ||
}; | ||
@@ -284,3 +284,3 @@ switch (implementor.kind) { | ||
fields: [doc.field], | ||
loc: doc.loc | ||
loc: doc.loc, | ||
}); | ||
@@ -293,3 +293,3 @@ break; | ||
fields: [__assign(__assign({}, doc.field), { directives: directives })], | ||
loc: doc.loc | ||
loc: doc.loc, | ||
}); | ||
@@ -303,3 +303,3 @@ break; | ||
try { | ||
if (_d && !_d.done && (_a = _c["return"])) _a.call(_c); | ||
if (_d && !_d.done && (_a = _c.return)) _a.call(_c); | ||
} | ||
@@ -355,3 +355,3 @@ finally { if (e_3) throw e_3.error; } | ||
file: ts.createSourceFile(loc.source.name, loc.source.body, ts.ScriptTarget.Latest), | ||
relatedInformation: relatedInformation | ||
relatedInformation: relatedInformation, | ||
}; | ||
@@ -366,3 +366,3 @@ }; | ||
start: loc.start, | ||
length: loc.end - loc.start | ||
length: loc.end - loc.start, | ||
}; | ||
@@ -369,0 +369,0 @@ }; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -17,5 +17,6 @@ import { GraphQLError, Location, Source } from "graphql"; | ||
export declare class ReportableDiagnostics { | ||
_host: ts.CompilerHost; | ||
_host: ts.FormatDiagnosticsHost; | ||
_diagnostics: ts.Diagnostic[]; | ||
constructor(host: ts.CompilerHost, diagnostics: ts.Diagnostic[]); | ||
constructor(host: ts.FormatDiagnosticsHost, diagnostics: ts.Diagnostic[]); | ||
static fromDiagnostics(diagnostics: ts.Diagnostic[]): ReportableDiagnostics; | ||
formatDiagnosticsWithColorAndContext(): string; | ||
@@ -22,0 +23,0 @@ formatDiagnosticsWithContext(): string; |
@@ -29,3 +29,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.graphqlSourceToSourceFile = exports.diagnosticAtGraphQLLocation = exports.graphQlErrorToDiagnostic = exports.FAKE_ERROR_CODE = exports.ReportableDiagnostics = exports.err = exports.ok = void 0; | ||
@@ -46,2 +46,12 @@ var ts = require("typescript"); | ||
} | ||
// If you don't have a host, for example if you error while parsing the | ||
// tsconfig, you can use this method and one will be created for you. | ||
ReportableDiagnostics.fromDiagnostics = function (diagnostics) { | ||
var formatHost = { | ||
getCanonicalFileName: function (path) { return path; }, | ||
getCurrentDirectory: ts.sys.getCurrentDirectory, | ||
getNewLine: function () { return ts.sys.newLine; }, | ||
}; | ||
return new ReportableDiagnostics(formatHost, diagnostics); | ||
}; | ||
ReportableDiagnostics.prototype.formatDiagnosticsWithColorAndContext = function () { | ||
@@ -101,3 +111,3 @@ var formatted = ts.formatDiagnosticsWithColorAndContext(this._diagnostics, this._host); | ||
start: relatedNode.loc.start, | ||
length: relatedNode.loc.end - relatedNode.loc.start | ||
length: relatedNode.loc.end - relatedNode.loc.start, | ||
}); | ||
@@ -109,3 +119,3 @@ } | ||
try { | ||
if (rest_1_1 && !rest_1_1.done && (_a = rest_1["return"])) _a.call(rest_1); | ||
if (rest_1_1 && !rest_1_1.done && (_a = rest_1.return)) _a.call(rest_1); | ||
} | ||
@@ -128,3 +138,3 @@ finally { if (e_1) throw e_1.error; } | ||
length: length, | ||
relatedInformation: relatedInformation | ||
relatedInformation: relatedInformation, | ||
}; | ||
@@ -140,3 +150,3 @@ } | ||
start: loc.start, | ||
length: loc.end - loc.start | ||
length: loc.end - loc.start, | ||
}; | ||
@@ -143,0 +153,0 @@ } |
@@ -13,3 +13,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.extend = exports.DefaultMap = void 0; | ||
@@ -43,3 +43,3 @@ var DefaultMap = /** @class */ (function () { | ||
try { | ||
if (b_1_1 && !b_1_1.done && (_a = b_1["return"])) _a.call(b_1); | ||
if (b_1_1 && !b_1_1.done && (_a = b_1.return)) _a.call(b_1); | ||
} | ||
@@ -46,0 +46,0 @@ finally { if (e_1) throw e_1.error; } |
@@ -13,3 +13,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.traverseJSDocTags = void 0; | ||
@@ -42,3 +42,3 @@ var ts = require("typescript"); | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
@@ -45,0 +45,0 @@ finally { if (e_1) throw e_1.error; } |
{ | ||
"name": "grats", | ||
"version": "0.0.0-main-e383eda5", | ||
"version": "0.0.0-main-e6abe1f1", | ||
"main": "dist/src/index.js", | ||
@@ -15,3 +15,3 @@ "bin": "dist/src/cli.js", | ||
"graphql": "^16.6.0", | ||
"typescript": "^4.9.5" | ||
"typescript": "^5.0.2" | ||
}, | ||
@@ -26,5 +26,5 @@ "devDependencies": { | ||
"path-browserify": "^1.0.1", | ||
"prettier": "^2.8.7", | ||
"process": "^0.11.10", | ||
"ts-node": "^10.9.1", | ||
"prettier": "^2.8.7" | ||
"ts-node": "^10.9.1" | ||
}, | ||
@@ -31,0 +31,0 @@ "prettier": { |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
251299
71
5275
6
+ Addedtypescript@5.7.3(transitive)
- Removedtypescript@4.9.5(transitive)
Updatedtypescript@^5.0.2