Socket
Socket
Sign inDemoInstall

@graphql-codegen/visitor-plugin-common

Package Overview
Dependencies
Maintainers
5
Versions
5953
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-codegen/visitor-plugin-common - npm Package Compare versions

Comparing version 1.0.1-alpha-d343ec0b.18 to 1.0.1

3

dist/commonjs/base-types-visitor.d.ts

@@ -1,2 +0,2 @@

import { DirectiveDefinitionNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, ListTypeNode, NamedTypeNode, NameNode, NonNullTypeNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, UnionTypeDefinitionNode } from 'graphql';
import { DirectiveDefinitionNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, ListTypeNode, NamedTypeNode, NameNode, NonNullTypeNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, UnionTypeDefinitionNode, StringValueNode } from 'graphql';
import { BaseVisitor, ParsedConfig, RawConfig } from './base-visitor';

@@ -52,2 +52,3 @@ import { EnumValuesMap, ScalarsMap } from './types';

EnumTypeDefinition(node: EnumTypeDefinitionNode): string;
StringValue(node: StringValueNode): string;
protected buildEnumValuesBlock(typeName: string, values: ReadonlyArray<EnumValueDefinitionNode>): string;

@@ -54,0 +55,0 @@ DirectiveDefinition(node: DirectiveDefinitionNode): string;

@@ -17,3 +17,5 @@ "use strict";

const scalarValue = this.config.scalars[scalarName];
return utils_1.indent(`${scalarName}: ${scalarValue},`);
const scalarType = this._schema.getType(scalarName);
const comment = scalarType && scalarType.astNode && scalarType.description ? utils_1.transformComment(scalarType.description, 1) : '';
return comment + utils_1.indent(`${scalarName}: ${scalarValue},`);
});

@@ -24,2 +26,3 @@ return new utils_1.DeclarationBlock(this._declarationBlockConfig)

.withName('Scalars')
.withComment('All built-in and custom scalars, mapped to their actual values')
.withBlock(allScalars.join('\n')).string;

@@ -42,6 +45,8 @@ }

.withName(this.convertName(node))
.withComment(node.description)
.withBlock(node.fields.join('\n')).string;
}
InputValueDefinition(node) {
return utils_1.indent(`${node.name}: ${node.type},`);
const comment = utils_1.transformComment(node.description, 1);
return comment + utils_1.indent(`${node.name}: ${node.type},`);
}

@@ -53,3 +58,4 @@ Name(node) {

const typeString = node.type;
return utils_1.indent(`${node.name}: ${typeString},`);
const comment = utils_1.transformComment(node.description, 1);
return comment + utils_1.indent(`${node.name}: ${typeString},`);
}

@@ -63,2 +69,3 @@ UnionTypeDefinition(node, key, parent) {

.withName(this.convertName(node))
.withComment(node.description)
.withContent(possibleTypes).string;

@@ -74,2 +81,3 @@ }

.withContent(interfaces)
.withComment(node.description)
.withBlock(node.fields.join('\n')).string;

@@ -88,2 +96,3 @@ const original = parent[key];

.withName(this.convertName(name))
.withComment(node.description)
.withBlock(this._argumentsTransformer.transform(field.arguments)).string;

@@ -98,2 +107,3 @@ });

.withName(this.convertName(node))
.withComment(node.description)
.withBlock(node.fields.join('\n')).string;

@@ -134,4 +144,9 @@ }

.withName(this.convertName(node))
.withComment(node.description)
.withBlock(this.buildEnumValuesBlock(enumName, node.values)).string;
}
// We are using it in order to transform "description" field
StringValue(node) {
return node.value;
}
buildEnumValuesBlock(typeName, values) {

@@ -141,2 +156,3 @@ return values

const optionName = this.convertName(enumOption);
const comment = utils_1.transformComment(enumOption.description, 1);
let enumValue = enumOption.name;

@@ -146,3 +162,3 @@ if (this.config.enumValues[typeName] && typeof this.config.enumValues[typeName] === 'object' && this.config.enumValues[typeName][enumValue]) {

}
return utils_1.indent(`${optionName}${this._declarationBlockConfig.enumNameValueSeparator} ${utils_1.wrapWithSingleQuotes(enumValue)}`);
return comment + utils_1.indent(`${optionName}${this._declarationBlockConfig.enumNameValueSeparator} ${utils_1.wrapWithSingleQuotes(enumValue)}`);
})

@@ -149,0 +165,0 @@ .join(',\n');

@@ -15,2 +15,3 @@ import { NameNode, TypeNode, NamedTypeNode, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLOutputType, GraphQLNamedType, GraphQLSchema } from 'graphql';

}
export declare function transformComment(comment: string, indentLevel?: number): string;
export declare class DeclarationBlock {

@@ -25,5 +26,7 @@ private _config;

_nameGenerics: any;
_comment: any;
constructor(_config: DeclarationBlockConfig);
export(exp?: boolean): DeclarationBlock;
asKind(kind: any): DeclarationBlock;
asKind(kind: string): DeclarationBlock;
withComment(comment: string | null): DeclarationBlock;
withMethodCall(methodName: string): DeclarationBlock;

@@ -30,0 +33,0 @@ withBlock(block: string): DeclarationBlock;

@@ -51,2 +51,19 @@ "use strict";

exports.indent = indent;
function transformComment(comment, indentLevel = 0) {
if (!comment || comment === '') {
return '';
}
const lines = comment.split('\n');
return lines
.map((line, index) => {
const isLast = lines.length === index + 1;
const isFirst = index === 0;
if (isFirst && isLast) {
return indent(`/** ${comment} */\n`, indentLevel);
}
return indent(`${isFirst ? '/** ' : ' * '}${line}${isLast ? '\n */\n' : ''}`, indentLevel);
})
.join('\n');
}
exports.transformComment = transformComment;
class DeclarationBlock {

@@ -62,2 +79,3 @@ constructor(_config) {

this._nameGenerics = null;
this._comment = null;
this._config = Object.assign({ blockWrapper: '', blockTransformer: block => block, enumNameValueSeparator: ':' }, this._config);

@@ -73,2 +91,8 @@ }

}
withComment(comment) {
if (comment) {
this._comment = transformComment(comment, 0);
}
return this;
}
withMethodCall(methodName) {

@@ -127,3 +151,3 @@ this._methodName = methodName;

}
return result + (this._kind === 'interface' || this._kind === 'enum' ? '' : ';') + '\n';
return (this._comment ? this._comment : '') + result + (this._kind === 'interface' || this._kind === 'enum' ? '' : ';') + '\n';
}

@@ -130,0 +154,0 @@ }

@@ -1,2 +0,2 @@

import { DirectiveDefinitionNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, ListTypeNode, NamedTypeNode, NameNode, NonNullTypeNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, UnionTypeDefinitionNode } from 'graphql';
import { DirectiveDefinitionNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, ListTypeNode, NamedTypeNode, NameNode, NonNullTypeNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, UnionTypeDefinitionNode, StringValueNode } from 'graphql';
import { BaseVisitor, ParsedConfig, RawConfig } from './base-visitor';

@@ -52,2 +52,3 @@ import { EnumValuesMap, ScalarsMap } from './types';

EnumTypeDefinition(node: EnumTypeDefinitionNode): string;
StringValue(node: StringValueNode): string;
protected buildEnumValuesBlock(typeName: string, values: ReadonlyArray<EnumValueDefinitionNode>): string;

@@ -54,0 +55,0 @@ DirectiveDefinition(node: DirectiveDefinitionNode): string;

import { BaseVisitor } from './base-visitor';
import { parseMapper } from './mappers';
import { DEFAULT_SCALARS } from './scalars';
import { buildScalars, DeclarationBlock, indent, wrapWithSingleQuotes } from './utils';
import { transformComment, buildScalars, DeclarationBlock, indent, wrapWithSingleQuotes } from './utils';
import { OperationVariablesToObject } from './variables-to-object';

@@ -15,3 +15,5 @@ export class BaseTypesVisitor extends BaseVisitor {

const scalarValue = this.config.scalars[scalarName];
return indent(`${scalarName}: ${scalarValue},`);
const scalarType = this._schema.getType(scalarName);
const comment = scalarType && scalarType.astNode && scalarType.description ? transformComment(scalarType.description, 1) : '';
return comment + indent(`${scalarName}: ${scalarValue},`);
});

@@ -22,2 +24,3 @@ return new DeclarationBlock(this._declarationBlockConfig)

.withName('Scalars')
.withComment('All built-in and custom scalars, mapped to their actual values')
.withBlock(allScalars.join('\n')).string;

@@ -40,6 +43,8 @@ }

.withName(this.convertName(node))
.withComment(node.description)
.withBlock(node.fields.join('\n')).string;
}
InputValueDefinition(node) {
return indent(`${node.name}: ${node.type},`);
const comment = transformComment(node.description, 1);
return comment + indent(`${node.name}: ${node.type},`);
}

@@ -51,3 +56,4 @@ Name(node) {

const typeString = node.type;
return indent(`${node.name}: ${typeString},`);
const comment = transformComment(node.description, 1);
return comment + indent(`${node.name}: ${typeString},`);
}

@@ -61,2 +67,3 @@ UnionTypeDefinition(node, key, parent) {

.withName(this.convertName(node))
.withComment(node.description)
.withContent(possibleTypes).string;

@@ -72,2 +79,3 @@ }

.withContent(interfaces)
.withComment(node.description)
.withBlock(node.fields.join('\n')).string;

@@ -86,2 +94,3 @@ const original = parent[key];

.withName(this.convertName(name))
.withComment(node.description)
.withBlock(this._argumentsTransformer.transform(field.arguments)).string;

@@ -96,2 +105,3 @@ });

.withName(this.convertName(node))
.withComment(node.description)
.withBlock(node.fields.join('\n')).string;

@@ -132,4 +142,9 @@ }

.withName(this.convertName(node))
.withComment(node.description)
.withBlock(this.buildEnumValuesBlock(enumName, node.values)).string;
}
// We are using it in order to transform "description" field
StringValue(node) {
return node.value;
}
buildEnumValuesBlock(typeName, values) {

@@ -139,2 +154,3 @@ return values

const optionName = this.convertName(enumOption);
const comment = transformComment(enumOption.description, 1);
let enumValue = enumOption.name;

@@ -144,3 +160,3 @@ if (this.config.enumValues[typeName] && typeof this.config.enumValues[typeName] === 'object' && this.config.enumValues[typeName][enumValue]) {

}
return indent(`${optionName}${this._declarationBlockConfig.enumNameValueSeparator} ${wrapWithSingleQuotes(enumValue)}`);
return comment + indent(`${optionName}${this._declarationBlockConfig.enumNameValueSeparator} ${wrapWithSingleQuotes(enumValue)}`);
})

@@ -147,0 +163,0 @@ .join(',\n');

@@ -15,2 +15,3 @@ import { NameNode, TypeNode, NamedTypeNode, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLOutputType, GraphQLNamedType, GraphQLSchema } from 'graphql';

}
export declare function transformComment(comment: string, indentLevel?: number): string;
export declare class DeclarationBlock {

@@ -25,5 +26,7 @@ private _config;

_nameGenerics: any;
_comment: any;
constructor(_config: DeclarationBlockConfig);
export(exp?: boolean): DeclarationBlock;
asKind(kind: any): DeclarationBlock;
asKind(kind: string): DeclarationBlock;
withComment(comment: string | null): DeclarationBlock;
withMethodCall(methodName: string): DeclarationBlock;

@@ -30,0 +33,0 @@ withBlock(block: string): DeclarationBlock;

@@ -43,2 +43,18 @@ import { pascalCase } from 'change-case';

}
export function transformComment(comment, indentLevel = 0) {
if (!comment || comment === '') {
return '';
}
const lines = comment.split('\n');
return lines
.map((line, index) => {
const isLast = lines.length === index + 1;
const isFirst = index === 0;
if (isFirst && isLast) {
return indent(`/** ${comment} */\n`, indentLevel);
}
return indent(`${isFirst ? '/** ' : ' * '}${line}${isLast ? '\n */\n' : ''}`, indentLevel);
})
.join('\n');
}
export class DeclarationBlock {

@@ -54,2 +70,3 @@ constructor(_config) {

this._nameGenerics = null;
this._comment = null;
this._config = Object.assign({ blockWrapper: '', blockTransformer: block => block, enumNameValueSeparator: ':' }, this._config);

@@ -65,2 +82,8 @@ }

}
withComment(comment) {
if (comment) {
this._comment = transformComment(comment, 0);
}
return this;
}
withMethodCall(methodName) {

@@ -119,3 +142,3 @@ this._methodName = methodName;

}
return result + (this._kind === 'interface' || this._kind === 'enum' ? '' : ';') + '\n';
return (this._comment ? this._comment : '') + result + (this._kind === 'interface' || this._kind === 'enum' ? '' : ';') + '\n';
}

@@ -122,0 +145,0 @@ }

{
"name": "@graphql-codegen/visitor-plugin-common",
"version": "1.0.1-alpha-d343ec0b.18+d343ec0b",
"version": "1.0.1",
"license": "MIT",

@@ -9,3 +9,3 @@ "scripts": {

"dependencies": {
"@graphql-codegen/plugin-helpers": "1.0.1-alpha-d343ec0b.18+d343ec0b",
"@graphql-codegen/plugin-helpers": "1.0.1",
"auto-bind": "2.0.0",

@@ -20,3 +20,3 @@ "dependency-graph": "0.8.0",

"devDependencies": {
"@graphql-codegen/testing": "1.0.1-alpha-d343ec0b.18+d343ec0b",
"@graphql-codegen/testing": "1.0.1",
"@types/graphql": "14.0.7",

@@ -36,3 +36,3 @@ "graphql": "14.1.1",

},
"gitHead": "d343ec0baebd2fe1b17c6afb2971acafaaf31e79"
"gitHead": "8928b444997fa177dc106220637709370cc527f3"
}

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