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

gql-types-generator

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gql-types-generator - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

10

dist/cli.js

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

.option('--operations <globs>', 'globs to find queries and mutations')
.option('--flatten-operations', 'states if operations should be placed in a single file')
// .option('--flatten-operations', 'states if operations should be placed in a single file')
.option('--remove-description', 'states if description should be removed')

@@ -64,7 +64,9 @@ .option('--display <sort>', 'how to display compiled types. Valid values are "as-is" and ' +

.action(function (schemaPath) { return __awaiter(void 0, void 0, void 0, function () {
var operations, flattenOperations, removeDescription, display, outputDirectory, _a, _b, _c;
var operations,
// flattenOperations,
removeDescription, display, outputDirectory, _a, _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
operations = program.operations, flattenOperations = program.flattenOperations, removeDescription = program.removeDescription, display = program.display, outputDirectory = program.outputDirectory;
operations = program.operations, removeDescription = program.removeDescription, display = program.display, outputDirectory = program.outputDirectory;
_a = compiler_1.compile;

@@ -82,3 +84,3 @@ _b = {};

_b.operationsPath = _c,
_b.flattenOperations = flattenOperations,
// flattenOperations,
_b.removeDescription = removeDescription;

@@ -85,0 +87,0 @@ return [4 /*yield*/, fs_1.withCwdAndGlob(schemaPath)];

2

dist/compiler.d.ts

@@ -26,2 +26,2 @@ import { GraphQLSchema } from 'graphql';

*/
export declare function compileOperations(operationsString: string, outputDirectory: string, schema: GraphQLSchema, flattenOperations: boolean): void;
export declare function compileOperations(operationsString: string, outputDirectory: string, schema: GraphQLSchema): void;

@@ -50,7 +50,9 @@ "use strict";

return __awaiter(this, void 0, void 0, function () {
var operationsPath, _a, flattenOperations, outputDirectory, _b, display, _c, removeDescription, includeDescription, schemaString, schema, operationsString, _d;
return __generator(this, function (_e) {
switch (_e.label) {
var operationsPath,
// flattenOperations = false,
outputDirectory, _a, display, _b, removeDescription, includeDescription, schemaString, schema, operationsString, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
operationsPath = options.operationsPath, _a = options.flattenOperations, flattenOperations = _a === void 0 ? false : _a, outputDirectory = options.outputDirectory, _b = options.display, display = _b === void 0 ? 'default' : _b, _c = options.removeDescription, removeDescription = _c === void 0 ? false : _c;
operationsPath = options.operationsPath, outputDirectory = options.outputDirectory, _a = options.display, display = _a === void 0 ? 'default' : _a, _b = options.removeDescription, removeDescription = _b === void 0 ? false : _b;
includeDescription = !removeDescription;

@@ -61,11 +63,11 @@ schemaString = null;

case 1:
schemaString = _e.sent();
schemaString = _d.sent();
return [3 /*break*/, 3];
case 2:
schemaString = options.schema;
_e.label = 3;
_d.label = 3;
case 3:
console.log(chalk_1.yellow('Starting compilation with options:'), {
operationsPath: operationsPath,
flattenOperations: flattenOperations,
// flattenOperations,
outputDirectory: outputDirectory,

@@ -82,9 +84,9 @@ display: display,

case 4:
_d = _e.sent();
_c = _d.sent();
return [3 /*break*/, 6];
case 5:
_d = null;
_e.label = 6;
_c = null;
_d.label = 6;
case 6:
operationsString = _d;
operationsString = _c;
if (typeof operationsString === 'string') {

@@ -94,3 +96,3 @@ if (operationsString.length === 0) {

}
compileOperations(operationsString, outputDirectory, schema, flattenOperations);
compileOperations(operationsString, outputDirectory, schema);
}

@@ -140,3 +142,3 @@ console.log(chalk_1.yellow('Compilation completed successfully!'));

*/
function compileOperations(operationsString, outputDirectory, schema, flattenOperations) {
function compileOperations(operationsString, outputDirectory, schema) {
var documentNode = graphql_1.parse(operationsString);

@@ -147,7 +149,10 @@ var compiledTypes = documentNode

if (node.kind === 'OperationDefinition') {
var name = node.name, operation = node.operation;
var compiledText = utils_1.generateGQLOperation(utils_1.parseOperation(node, schema));
var name = node.name, operation = node.operation, loc = node.loc;
var operationText = operationsString.slice(loc.start, loc.end);
var ts = utils_1.generateGQLOperation(utils_1.parseOperation(node, schema));
var js = "module.exports = `" + operationText + "`;";
acc.push({
operationName: utils_1.getCompiledOperationName(name.value, operation),
compiledText: compiledText,
operationName: name.value + utils_1.toCamelCase(operation),
ts: ts,
js: js,
});

@@ -158,13 +163,14 @@ }

// Write all the operations into a single file
if (flattenOperations) {
var contents = compiledTypes.map(function (c) { return c.compiledText; }).join('\n\n');
fs_1.write(outputDirectory, 'operations.d.ts', utils_1.wrapWithWarning(contents));
}
// Or create a new file for each query
else {
compiledTypes.forEach(function (c) {
fs_1.write(utils_1.wrapWithWarning(c.compiledText), outputDirectory, c.operationName + ".d.ts");
});
}
// if (flattenOperations) {
// const contents = compiledTypes.map(c => c.compiledText).join('\n\n');
// write(wrapWithWarning(contents), outputDirectory, 'operations.d.ts');
// }
// // Or create a new file for each query
// else {
compiledTypes.forEach(function (c) {
fs_1.write(utils_1.wrapWithWarning(c.ts), outputDirectory, c.operationName + ".d.ts");
fs_1.write(utils_1.wrapWithWarning(c.js), outputDirectory, c.operationName + ".js");
});
// }
}
exports.compileOperations = compileOperations;

@@ -14,6 +14,2 @@ /**

/**
* States if all operations should be
*/
flattenOperations?: boolean;
/**
* Full path to output directory

@@ -58,3 +54,4 @@ */

operationName: string;
compiledText: string;
js: string;
ts: string;
}

@@ -93,6 +93,9 @@ "use strict";

var operationName = misc_1.getCompiledOperationName(originalName, operationType);
var operationStringName = originalName + misc_1.toCamelCase(operationType);
return misc_1.formatRequiredTypes(requiredTypes)
+ ("export declare interface " + operationName + " " + operationDefinition + "\n\n")
+ generateGQLInterface(variables);
+ generateGQLInterface(variables) + '\n\n'
+ ("declare const " + operationStringName + ": string;\n")
+ ("export default " + operationStringName + ";");
}
exports.generateGQLOperation = generateGQLOperation;

@@ -211,2 +211,3 @@ "use strict";

operationDefinition: definition,
// operationContent: node.
requiredTypes: typesToImport,

@@ -213,0 +214,0 @@ variables: variables,

{
"name": "gql-types-generator",
"version": "1.2.2",
"main": "index.js",
"types": "index.d.ts",
"version": "1.2.3",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": "https://github.com/wolframdeus/gql-types-generator.git",

@@ -7,0 +7,0 @@ "author": "wolframdeus <wolframdeus@gmail.com>",

@@ -46,3 +46,2 @@ gql-types-generator

--operations <globs> globs to find queries and mutations
--flatten-operations states if operations should be placed in a single file
--remove-description states if description should be removed

@@ -49,0 +48,0 @@ --display <sort> how to display compiled types. Valid values are "as-is" and "default". By default, generator compiles scalars first, then enums, interfaces, inputs, unions and then types. "as-is" places types as they are placed in schema

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