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

@genql/cli

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@genql/cli - npm Package Compare versions

Comparing version 2.6.0 to 2.7.0

5

dist/render/client/renderClient.d.ts
import { GraphQLSchema } from 'graphql';
import { RenderContext } from '../common/RenderContext';
export declare const renderClientCjs: (_: GraphQLSchema, ctx: RenderContext) => void;
export declare const renderClientEsm: (_: GraphQLSchema, ctx: RenderContext) => void;
export declare function renderEnumsMaps(schema: GraphQLSchema, moduleType: 'esm' | 'cjs' | 'type'): string;
export declare const renderClientCjs: (schema: GraphQLSchema, ctx: RenderContext) => void;
export declare const renderClientEsm: (schema: GraphQLSchema, ctx: RenderContext) => void;

56

dist/render/client/renderClient.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderClientEsm = exports.renderClientCjs = void 0;
exports.renderClientEsm = exports.renderClientCjs = exports.renderEnumsMaps = void 0;
const graphql_1 = require("graphql");
const config_1 = require("../../config");
const excludedTypes_1 = require("../common/excludedTypes");
const { version } = require('../../../package.json');
const camelCase_1 = __importDefault(require("lodash/camelCase"));
const renderClientCode = (ctx) => {

@@ -24,3 +30,43 @@ var _a;

};
const renderClientCjs = (_, ctx) => {
function renderEnumsMaps(schema, moduleType) {
let typeMap = schema.getTypeMap();
const enums = [];
for (const name in typeMap) {
if (excludedTypes_1.excludedTypes.includes(name))
continue;
const type = typeMap[name];
if (graphql_1.isEnumType(type)) {
enums.push(type);
}
}
if (enums.length === 0)
return '';
const declaration = (() => {
if (moduleType === 'esm') {
return 'export const ';
}
else if (moduleType === 'cjs') {
return 'module.exports.';
}
else if (moduleType === 'type') {
return 'export declare const ';
}
return '';
})();
return enums
.map((type) => `${declaration}${camelCase_1.default('enum' + type.name)} = {\n` +
type
.getValues()
.map((v) => {
if (!(v === null || v === void 0 ? void 0 : v.name)) {
return '';
}
return ` ${v.name}: '${v.name}'`;
})
.join(',\n') +
'\n};\n')
.join('\n');
}
exports.renderEnumsMaps = renderEnumsMaps;
const renderClientCjs = (schema, ctx) => {
ctx.addCodeBlock(`

@@ -41,2 +87,4 @@ const {

module.exports.createClient = ${renderClientCode(ctx)}
${renderEnumsMaps(schema, 'cjs')}

@@ -63,3 +111,3 @@ module.exports.generateQueryOp = function(fields) {

exports.renderClientCjs = renderClientCjs;
const renderClientEsm = (_, ctx) => {
const renderClientEsm = (schema, ctx) => {
ctx.addCodeBlock(`

@@ -81,2 +129,4 @@ import {

${renderEnumsMaps(schema, 'esm')}
export var generateQueryOp = function(fields) {

@@ -83,0 +133,0 @@ return generateGraphqlOperation('query', typeMap.Query, fields)

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

const config_1 = require("../../config");
const renderClient_1 = require("./renderClient");
const renderClientDefinition = (schema, ctx) => {

@@ -29,2 +30,3 @@ const queryType = schema.getQueryType();

}));
ctx.addCodeBlock(renderClient_1.renderEnumsMaps(schema, 'type'));
};

@@ -31,0 +33,0 @@ exports.renderClientDefinition = renderClientDefinition;

{
"name": "@genql/cli",
"_": "[bump]",
"version": "2.6.0",
"version": "2.7.0",
"description": "Generate a client sdl from your GraphQl API",

@@ -42,3 +42,5 @@ "main": "dist/index.js",

"@types/node": "^14.0.14",
"@types/prettier": "^1.19.0",
"@types/rimraf": "^2.0.2",
"@types/yargs": "^15.0.5",
"common-tags": "^1.8.0",

@@ -56,5 +58,2 @@ "dotenv": "^8.2.0",

"@graphql-tools/load": "^6.0.10",
"@types/node": "*",
"@types/prettier": "^1.19.0",
"@types/yargs": "^15.0.5",
"chalk": "^4.1.0",

@@ -100,3 +99,3 @@ "fs-extra": "^9.0.1",

},
"gitHead": "4e431e1a6e2cea513cad91614f3a9ef794f94d07"
"gitHead": "185130a380f50c800f02a19334d99f173c284170"
}

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

import { GraphQLSchema } from 'graphql'
import { GraphQLEnumType, GraphQLSchema, isEnumType } from 'graphql'
import { RenderContext } from '../common/RenderContext'
import { RUNTIME_LIB_NAME } from '../../config'
import { excludedTypes } from '../common/excludedTypes'
const { version } = require('../../../package.json')
import camelCase from 'lodash/camelCase'

@@ -23,4 +25,48 @@ const renderClientCode = (ctx: RenderContext) => {

}
export function renderEnumsMaps(
schema: GraphQLSchema,
moduleType: 'esm' | 'cjs' | 'type',
) {
let typeMap = schema.getTypeMap()
export const renderClientCjs = (_: GraphQLSchema, ctx: RenderContext) => {
const enums: GraphQLEnumType[] = []
for (const name in typeMap) {
if (excludedTypes.includes(name)) continue
const type = typeMap[name]
if (isEnumType(type)) {
enums.push(type)
}
}
if (enums.length === 0) return ''
const declaration = (() => {
if (moduleType === 'esm') {
return 'export const '
} else if (moduleType === 'cjs') {
return 'module.exports.'
} else if (moduleType === 'type') {
return 'export declare const '
}
return ''
})()
return enums
.map(
(type) =>
`${declaration}${camelCase('enum' + type.name)} = {\n` +
type
.getValues()
.map((v) => {
if (!v?.name) {
return ''
}
return ` ${v.name}: '${v.name}'`
})
.join(',\n') +
'\n};\n',
)
.join('\n')
}
export const renderClientCjs = (schema: GraphQLSchema, ctx: RenderContext) => {
ctx.addCodeBlock(`

@@ -41,2 +87,4 @@ const {

module.exports.createClient = ${renderClientCode(ctx)}
${renderEnumsMaps(schema, 'cjs')}

@@ -63,3 +111,3 @@ module.exports.generateQueryOp = function(fields) {

export const renderClientEsm = (_: GraphQLSchema, ctx: RenderContext) => {
export const renderClientEsm = (schema: GraphQLSchema, ctx: RenderContext) => {
ctx.addCodeBlock(`

@@ -81,2 +129,4 @@ import {

${renderEnumsMaps(schema, 'esm')}
export var generateQueryOp = function(fields) {

@@ -83,0 +133,0 @@ return generateGraphqlOperation('query', typeMap.Query, fields)

@@ -6,2 +6,3 @@ import { GraphQLSchema } from 'graphql'

import { RUNTIME_LIB_NAME } from '../../config'
import { renderEnumsMaps } from './renderClient'

@@ -39,2 +40,4 @@ export const renderClientDefinition = (

)
ctx.addCodeBlock(renderEnumsMaps(schema, 'type'))
}

@@ -41,0 +44,0 @@

@@ -70,2 +70,5 @@ import {

)
}

@@ -72,0 +75,0 @@

@@ -5,3 +5,7 @@ import Listr, { ListrTask } from 'listr'

import { renderChainTypes } from '../render/chain/renderChainTypes'
import { renderClientCjs, renderClientEsm } from '../render/client/renderClient'
import {
renderClientCjs,
renderClientEsm,
renderEnumsMaps,
} from '../render/client/renderClient'
import { renderClientDefinition } from '../render/client/renderClientDefinition'

@@ -8,0 +12,0 @@ import { RenderContext } from '../render/common/RenderContext'

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc