New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

grats

Package Overview
Dependencies
Maintainers
1
Versions
240
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grats - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

dist/src/tests/integrationFixtures/complexDefaultInput/index.d.ts

12

dist/package.json
{
"name": "grats",
"version": "0.0.9",
"version": "0.0.10",
"main": "dist/src/index.js",

@@ -19,8 +19,8 @@ "bin": "dist/src/cli.js",

"dependencies": {
"@graphql-tools/utils": "^9.2.1",
"commander": "^10.0.0",
"graphql": "^16.6.0",
"typescript": "^4.9.5"
"typescript": "^5.0.2"
},
"devDependencies": {
"@graphql-tools/utils": "^9.2.1",
"@types/node": "^18.14.6",

@@ -33,5 +33,5 @@ "@typescript-eslint/eslint-plugin": "^5.55.0",

"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"
},

@@ -41,3 +41,3 @@ "prettier": {

},
"packageManager": "pnpm@8.1.1",
"packageManager": "pnpm@8.12.0",
"engines": {

@@ -44,0 +44,0 @@ "node": ">=16 <=21",

@@ -39,3 +39,3 @@ #!/usr/bin/env node

};
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatLoc = void 0;

@@ -73,8 +73,4 @@ var graphql_1 = require("graphql");

var tsconfig = _a.tsconfig;
var optionsResult = (0, _1.getParsedTsConfig)(tsconfig);
if (optionsResult.kind === "ERROR") {
throw new Error("TODO");
}
var options = optionsResult.value;
var schema = buildSchema(options);
var config = getTsConfig(tsconfig).config;
var schema = buildSchema(config);
var loc = (0, Locate_1.locate)(schema, entity);

@@ -89,7 +85,22 @@ if (loc.kind === "ERROR") {

function build(tsconfig) {
var configFile = tsconfig || ts.findConfigFile(process.cwd(), ts.sys.fileExists);
if (configFile == null) {
var _a = getTsConfig(tsconfig), config = _a.config, configPath = _a.configPath;
var schema = buildSchema(config);
var sortedSchema = (0, graphql_1.lexicographicSortSchema)(schema);
var gratsOptions = config.raw.grats;
var dest = (0, path_1.resolve)((0, path_1.dirname)(configPath), gratsOptions.tsSchema);
var code = (0, printSchema_1.printExecutableSchema)(sortedSchema, gratsOptions, dest);
(0, fs_1.writeFileSync)(dest, code);
console.error("Grats: Wrote TypeScript schema to `".concat(dest, "`."));
var schemaStr = (0, printSchema_1.printGratsSDL)(sortedSchema, gratsOptions);
var absOutput = (0, path_1.resolve)((0, path_1.dirname)(configPath), gratsOptions.graphqlSchema);
(0, fs_1.writeFileSync)(absOutput, schemaStr);
console.error("Grats: Wrote schema to `".concat(absOutput, "`."));
}
// Locate and read the tsconfig.json file
function getTsConfig(tsconfig) {
var configPath = tsconfig || ts.findConfigFile(process.cwd(), ts.sys.fileExists);
if (configPath == null) {
throw new Error("Grats: Could not find tsconfig.json");
}
var optionsResult = (0, _1.getParsedTsConfig)(configFile);
var optionsResult = (0, _1.getParsedTsConfig)(configPath);
if (optionsResult.kind === "ERROR") {

@@ -99,14 +110,3 @@ console.error(optionsResult.err.formatDiagnosticsWithColorAndContext());

}
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)(process.cwd(), config.graphqlSchema);
(0, fs_1.writeFileSync)(absOutput, schemaStr);
console.error("Grats: Wrote schema to `".concat(absOutput, "`."));
return { configPath: configPath, config: optionsResult.value };
}

@@ -113,0 +113,0 @@ function buildSchema(options) {

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

};
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.codegen = void 0;

@@ -93,2 +93,7 @@ var graphql_1 = require("graphql");

};
Codegen.prototype.deprecated = function (obj) {
if (!obj.deprecationReason)
return null;
return F.createPropertyAssignment("deprecationReason", F.createStringLiteral(obj.deprecationReason));
};
Codegen.prototype.description = function (description) {

@@ -147,3 +152,3 @@ if (!description)

var resolverName = formatResolverFunctionVarName(parentTypeName, funcName);
this["import"]("./".concat(relative), [{ name: funcName, as: resolverName }]);
this.import("./".concat(relative), [{ name: funcName, as: resolverName }]);
var usedArgs = args.slice(0, argCount);

@@ -216,3 +221,3 @@ return this.method(methodName, usedArgs.map(function (name) {

// the definition.
F.createTypeReferenceNode(this.graphQLImport("GraphQLInterfaceType")));
F.createTypeReferenceNode(this.graphQLImport("GraphQLUnionType")));
}

@@ -277,2 +282,3 @@ return F.createIdentifier(varName);

this.description(field.description),
this.deprecated(field),
F.createPropertyAssignment("name", F.createStringLiteral(field.name)),

@@ -285,2 +291,3 @@ F.createPropertyAssignment("type", this.typeReference(field.type)),

this.description(field.description),
this.deprecated(field),
F.createPropertyAssignment("name", F.createStringLiteral(field.name)),

@@ -313,2 +320,3 @@ F.createPropertyAssignment("type", this.typeReference(field.type)),

this.description(arg.description),
this.deprecated(arg),
F.createPropertyAssignment("name", F.createStringLiteral(arg.name)),

@@ -352,2 +360,3 @@ F.createPropertyAssignment("type", this.typeReference(arg.type)),

this.description(obj.description),
this.deprecated(obj),
F.createPropertyAssignment("value", F.createStringLiteral(obj.name)),

@@ -445,3 +454,3 @@ ]);

};
Codegen.prototype["import"] = function (from, names) {
Codegen.prototype.import = function (from, names) {
var namedImports = names.map(function (name) {

@@ -460,3 +469,3 @@ if (name.as) {

var sourceFile = ts.createSourceFile("tempFile.ts", "", ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
this["import"]("graphql", __spreadArray([], __read(this._graphQLImports), false).map(function (name) { return ({ name: name }); }));
this.import("graphql", __spreadArray([], __read(this._graphQLImports), false).map(function (name) { return ({ name: name }); }));
return printer.printList(ts.ListFormat.MultiLine, F.createNodeArray(__spreadArray(__spreadArray([], __read(this._imports), false), __read(this._statements), false)), sourceFile);

@@ -463,0 +472,0 @@ };

@@ -92,1 +92,2 @@ /**

export declare function operationTypeNotUnknown(): string;
export declare function expectedNullableArgumentToBeOptional(): string;
"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;
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;
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.implementsTagMissingValue = exports.mergedInterfaces = exports.nonNullTypeCannotBeOptional = exports.killsParentOnExceptionOnNullable = exports.killsParentOnExceptionWithWrongConfig = exports.expectedIdentifier = exports.pluralTypeMissingParameter = exports.unknownGraphQLType = exports.unsupportedTypeLiteral = exports.defaultArgPropertyMissingInitializer = void 0;
var Extractor_1 = require("./Extractor");

@@ -9,3 +9,3 @@ // TODO: Move these to short URLS that are easier to keep from breaking.

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",
};

@@ -361,1 +361,5 @@ /**

exports.operationTypeNotUnknown = operationTypeNotUnknown;
function expectedNullableArgumentToBeOptional() {
return "Expected nullable argument to be optional. graphql-js may not define properties where an undefined argument is passed. To guard against this add a `?` to the end of the argument name to make it optional.";
}
exports.expectedNullableArgumentToBeOptional = expectedNullableArgumentToBeOptional;

@@ -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);
}

@@ -414,3 +414,3 @@ finally { if (e_2) throw e_2.error; }

try {
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}

@@ -670,3 +670,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);
}

@@ -771,3 +771,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);
}

@@ -794,3 +794,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);
}

@@ -811,3 +811,3 @@ finally { if (e_6) throw e_6.error; }

else if (this.isNullish(node)) {
return this.gql["null"](node);
return this.gql.null(node);
}

@@ -847,3 +847,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);
}

@@ -876,3 +876,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);
}

@@ -920,9 +920,17 @@ finally { if (e_8) throw e_8.error; }

return null;
if (type.kind !== graphql_1.Kind.NON_NULL_TYPE && !node.questionToken) {
// If a field is passed an argument value, and that argument is not defined in the request,
// `graphql-js` will not define the argument property. Therefore we must ensure the argument
// is not just nullable, but optional.
return this.report(node.name, E.expectedNullableArgumentToBeOptional());
}
if (node.questionToken) {
/*
// TODO: Don't allow args that are optional but don't accept null
if (type.kind === Kind.NON_NULL_TYPE) {
return this.report(node.questionToken, E.nonNullTypeCannotBeOptional());
// Question mark means we can handle the argument being undefined in the
// object literal, but if we are going to type the GraphQL arg as
// optional, the code must also be able to handle an explicit null.
//
// TODO: This will catch { a?: string } but not { a?: string | undefined }.
if (type.kind === graphql_1.Kind.NON_NULL_TYPE) {
return this.report(node.questionToken, E.nonNullTypeCannotBeOptional());
}
*/
type = this.gql.nullableType(type);

@@ -1017,3 +1025,3 @@ }

try {
if (_d && !_d.done && (_a = _c["return"])) _a.call(_c);
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}

@@ -1043,3 +1051,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 +1125,3 @@ finally { if (e_10) throw e_10.error; }

declaration: declaration,
firstReference: node.type.typeName
firstReference: node.type.typeName,
};

@@ -1120,0 +1128,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 @@ };

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

};
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateGratsOptions = void 0;

@@ -16,0 +16,0 @@ var DEFAULT_SDL_HEADER = "# Schema generated by Grats (https://grats.capt.dev)\n# Do not manually edit. Regenerate by running `npx grats`.";

"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");

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

};
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getParsedTsConfig = exports.codegen = void 0;

@@ -25,3 +25,3 @@ var ts = require("typescript");

var codegen_1 = require("./codegen");
__createBinding(exports, codegen_1, "codegen");
Object.defineProperty(exports, "codegen", { enumerable: true, get: function () { return codegen_1.codegen; } });
// #FIXME: Report diagnostics instead of throwing!

@@ -28,0 +28,0 @@ function getParsedTsConfig(configFile) {

@@ -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; }

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

};
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildSchemaResultWithHost = exports.buildSchemaResult = void 0;

@@ -105,3 +105,3 @@ var graphql_1 = require("graphql");

try {
if (_f && !_f.done && (_b = _e["return"])) _b.call(_e);
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}

@@ -115,3 +115,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);
}

@@ -132,3 +132,3 @@ finally { if (e_1) throw e_1.error; }

kind: graphql_1.Kind.DOCUMENT,
definitions: definitionsResult.value
definitions: definitionsResult.value,
});

@@ -190,3 +190,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);
}

@@ -200,3 +200,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);
}

@@ -203,0 +203,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");

@@ -13,1 +13,2 @@ import { GraphQLSchema } from "graphql";

export declare function printGratsSDL(schema: GraphQLSchema, config: ConfigOptions): string;
export declare function printSDLWithoutDirectives(schema: GraphQLSchema): string;

@@ -13,5 +13,4 @@ "use strict";

};
exports.__esModule = true;
exports.printGratsSDL = exports.printExecutableSchema = void 0;
var utils_1 = require("@graphql-tools/utils");
Object.defineProperty(exports, "__esModule", { value: true });
exports.printSDLWithoutDirectives = exports.printGratsSDL = exports.printExecutableSchema = void 0;
var graphql_1 = require("graphql");

@@ -36,4 +35,3 @@ var codegen_1 = require("./codegen");

function printGratsSDL(schema, config) {
var includeDirectives = !config.graphqlSchema;
var sdl = printSDL(schema, includeDirectives);
var sdl = printSDLWithoutDirectives(schema);
if (config.schemaHeader) {

@@ -45,8 +43,3 @@ return "".concat(config.schemaHeader, "\n").concat(sdl);

exports.printGratsSDL = printGratsSDL;
function printSDL(schema, includeDirectives) {
if (includeDirectives) {
return (0, utils_1.printSchemaWithDirectives)(schema, {
assumeValid: true
});
}
function printSDLWithoutDirectives(schema) {
return (0, graphql_1.printSchema)(new graphql_1.GraphQLSchema(__assign(__assign({}, schema.toConfig()), {

@@ -57,1 +50,2 @@ // TODO: Only filter out our directives. Note that

}
exports.printSDLWithoutDirectives = printSDLWithoutDirectives;
"use strict";
exports.__esModule = true;
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;

@@ -4,0 +4,0 @@ var graphql_1 = require("graphql");

@@ -6,9 +6,9 @@ import { Int } from "../../../Types";

export declare function firstHundredIntegers(_: Query, args: {
first: Int | null;
after: string | null;
first?: Int | null;
after?: string | null;
}): FirstHundredIntegersConnection;
/** @gqlType */
declare class FirstHundredIntegersConnection {
first: number | null;
after: string | null;
first?: number | null | undefined;
after?: string | null | undefined;
_max: number;

@@ -19,3 +19,3 @@ /** @gqlField */

edges: FirstHundredIntegersEdge[];
constructor(first: number | null, after: string | null);
constructor(first?: number | null | undefined, after?: string | null | undefined);
}

@@ -22,0 +22,0 @@ /** @gqlType */

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

};
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.query = exports.firstHundredIntegers = void 0;

@@ -31,3 +31,3 @@ /** @gqlField */

startCursor: this.edges[0].cursor,
endCursor: this.edges[this.edges.length - 1].cursor
endCursor: this.edges[this.edges.length - 1].cursor,
});

@@ -34,0 +34,0 @@ }

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.schema = void 0;

@@ -4,0 +4,0 @@ var index_1 = require("./index");

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.query = exports.hello = void 0;

@@ -4,0 +4,0 @@ /** @gqlField */

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.schema = void 0;

@@ -4,0 +4,0 @@ var index_1 = require("./index");

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.query = exports.notHello = void 0;

@@ -4,0 +4,0 @@ /** @gqlField hello */

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.schema = void 0;

@@ -4,0 +4,0 @@ var index_1 = require("./index");

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.query = exports.me = void 0;

@@ -4,0 +4,0 @@ /** @gqlField */

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.schema = void 0;

@@ -4,0 +4,0 @@ var index_1 = require("./index");

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.query = exports.hello = exports.alwaysThrowsKillsParentOnException = void 0;

@@ -4,0 +4,0 @@ /**

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.schema = void 0;

@@ -4,0 +4,0 @@ var index_1 = require("./index");

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.query = exports.me = void 0;

@@ -4,0 +4,0 @@ /** @gqlField */

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.schema = void 0;

@@ -4,0 +4,0 @@ var index_1 = require("./index");

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.query = exports.alwaysThrows = void 0;

@@ -4,0 +4,0 @@ /** @gqlField */

"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.schema = void 0;

@@ -4,0 +4,0 @@ var index_1 = require("./index");

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

};
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
var path = require("path");

@@ -73,2 +73,4 @@ var TestRunner_1 = require("./TestRunner");

var utils_1 = require("@graphql-tools/utils");
var jest_diff_1 = require("jest-diff");
var printSchema_1 = require("../printSchema");
var program = new commander_1.Command();

@@ -98,3 +100,3 @@ program

_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);
runner = new TestRunner_1.default(fixturesDir_1, !!write, filterRegex, testFilePattern, ignoreFilePattern, transformer);
return [4 /*yield*/, runner.run()];

@@ -114,3 +116,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);
}

@@ -141,3 +143,3 @@ finally { if (e_1) throw e_1.error; }

nullableByDefault: true,
schemaHeader: null
schemaHeader: null,
};

@@ -153,6 +155,6 @@ if (firstLine.startsWith("// {")) {

raw: {
grats: options
grats: options,
},
errors: [],
fileNames: files
fileNames: files,
});

@@ -182,6 +184,6 @@ // https://stackoverflow.com/a/66604532/1263117

return (0, utils_1.printSchemaWithDirectives)(schemaResult.value, {
assumeValid: true
assumeValid: true,
});
}
}
},
},

@@ -193,5 +195,4 @@ {

transformer: function (code, fileName) { return __awaiter(void 0, void 0, void 0, function () {
var filePath, schemaPath, options, files, parsedOptions, schemaResult, tsSchema, server, schemaModule, data;
var filePath, schemaPath, options, files, parsedOptions, schemaResult, tsSchema, server, schemaModule, schemaDiff, data;
return __generator(this, function (_a) {
var _b, _c;
switch (_a.label) {

@@ -202,3 +203,3 @@ case 0:

options = {
nullableByDefault: true
nullableByDefault: true,
};

@@ -211,9 +212,9 @@ files = [filePath, "src/Types.ts"];

outDir: "dist",
configFilePath: "tsconfig.json"
configFilePath: "tsconfig.json",
},
raw: {
grats: options
grats: options,
},
errors: [],
fileNames: files
fileNames: files,
});

@@ -226,3 +227,3 @@ schemaResult = (0, lib_1.buildSchemaResult)(parsedOptions);

(0, fs_1.writeFileSync)(schemaPath, tsSchema);
return [4 /*yield*/, (_b = filePath, Promise.resolve().then(function () { return require(_b); }))];
return [4 /*yield*/, Promise.resolve("".concat(filePath)).then(function (s) { return require(s); })];
case 1:

@@ -233,8 +234,15 @@ server = _a.sent();

}
return [4 /*yield*/, (_c = schemaPath, Promise.resolve().then(function () { return require(_c); }))];
return [4 /*yield*/, Promise.resolve("".concat(schemaPath)).then(function (s) { return require(s); })];
case 2:
schemaModule = _a.sent();
schemaDiff = compareSchemas(schemaModule.schema, schemaResult.value);
if (schemaDiff) {
console.log(schemaDiff);
// TODO: Make this an actual test failure, not an error
throw new Error("The codegen schema does not match the SDL schema.");
}
return [4 /*yield*/, (0, graphql_1.graphql)({
schema: schemaModule.schema,
source: server.query
source: server.query,
variableValues: server.variables,
})];

@@ -246,3 +254,3 @@ case 3:

});
}); }
}); },
},

@@ -261,5 +269,14 @@ {

});
}); }
}); },
},
];
// Returns null if the schemas are equal, otherwise returns a string diff.
function compareSchemas(actual, expected) {
var actualSDL = (0, printSchema_1.printSDLWithoutDirectives)(actual);
var expectedSDL = (0, printSchema_1.printSDLWithoutDirectives)(expected);
if (actualSDL === expectedSDL) {
return null;
}
return (0, jest_diff_1.diff)(expectedSDL, actualSDL);
}
program.parse();

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

};
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
var fs = require("fs");

@@ -88,3 +88,3 @@ var path = require("path");

try {
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}

@@ -122,3 +122,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);
}

@@ -148,3 +148,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);
}

@@ -165,3 +165,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);
}

@@ -188,3 +188,3 @@ finally { if (e_4) throw e_4.error; }

if (this._otherFiles.has(expectedFileName)) {
this._otherFiles["delete"](expectedFileName);
this._otherFiles.delete(expectedFileName);
}

@@ -244,3 +244,3 @@ else {

}());
exports["default"] = TestRunner;
exports.default = TestRunner;
function readdirSyncRecursive(dir) {

@@ -263,3 +263,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);
}

@@ -277,3 +277,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);
}

@@ -280,0 +280,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 });

@@ -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;

@@ -52,3 +52,3 @@ var ts = require("typescript");

getCurrentDirectory: ts.sys.getCurrentDirectory,
getNewLine: function () { return ts.sys.newLine; }
getNewLine: function () { return ts.sys.newLine; },
};

@@ -111,3 +111,3 @@ return new ReportableDiagnostics(formatHost, diagnostics);

start: relatedNode.loc.start,
length: relatedNode.loc.end - relatedNode.loc.start
length: relatedNode.loc.end - relatedNode.loc.start,
});

@@ -119,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);
}

@@ -138,3 +138,3 @@ finally { if (e_1) throw e_1.error; }

length: length,
relatedInformation: relatedInformation
relatedInformation: relatedInformation,
};

@@ -150,3 +150,3 @@ }

start: loc.start,
length: loc.end - loc.start
length: loc.end - loc.start,
};

@@ -153,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.9",
"version": "0.0.10",
"main": "dist/src/index.js",

@@ -12,8 +12,8 @@ "bin": "dist/src/cli.js",

"dependencies": {
"@graphql-tools/utils": "^9.2.1",
"commander": "^10.0.0",
"graphql": "^16.6.0",
"typescript": "^4.9.5"
"typescript": "^5.0.2"
},
"devDependencies": {
"@graphql-tools/utils": "^9.2.1",
"@types/node": "^18.14.6",

@@ -26,5 +26,5 @@ "@typescript-eslint/eslint-plugin": "^5.55.0",

"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"
},

@@ -34,3 +34,3 @@ "prettier": {

},
"packageManager": "pnpm@8.1.1",
"packageManager": "pnpm@8.12.0",
"engines": {

@@ -37,0 +37,0 @@ "node": ">=16 <=21",

@@ -1,5 +0,1 @@

# -=[ ALPHA SOFTWARE ]=-
**Grats is still experimental. Feel free to try it out and give feedback, but the api is still in flux**
# Grats: Implementation-First GraphQL for TypeScript

@@ -9,2 +5,4 @@

_Beta Software: Grats is largely stable and being used in production in multiple places. If you encounter any issues, dont hesitate to let us know._
**What if building a GraphQL server were as simple as just writing functions?**

@@ -21,4 +19,30 @@

## Read the docs: https://grats.capt.dev/
## Example
Here's what it looks like to define a User type with a greeting field using Grats:
```ts
/** @gqlType */
class User {
/** @gqlField */
name: string;
/** @gqlField */
greet(args: { greeting: string }): string {
return `${args.greeting}, ${this.name}`;
}
}
```
After running `npx grats`, you'll find a `schema.ts` module that exports an executable schema, and a `schema.graphql` file contins your GraphQL schema definition:
```graphql
type User {
name: String
greet(greeting: String!): String
}
```
That's just the begining! To learn more, **Read the docs: https://grats.capt.dev/**
## Contributing

@@ -25,0 +49,0 @@

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