Socket
Socket
Sign inDemoInstall

@graphql-codegen/visitor-plugin-common

Package Overview
Dependencies
Maintainers
5
Versions
5966
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.5-alpha-0048f936.0 to 1.0.5-alpha-179f90c8.4

5

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

@@ -111,5 +111,9 @@ import { ParsedConfig, RawConfig, BaseVisitor } from './base-visitor';

protected _variablesTransfomer: OperationVariablesToObject;
protected _usedMappers: {
[key: string]: boolean;
};
constructor(rawConfig: TRawConfig, additionalConfig: TPluginConfig, _schema: GraphQLSchema, defaultScalars?: ScalarsMap);
readonly schema: GraphQLSchema;
readonly defaultMapperType: string;
readonly unusedMappers: string[];
readonly mappersImports: string[];

@@ -127,2 +131,3 @@ protected buildMapperImport(source: string, types: string[]): string;

NonNullType(node: NonNullTypeNode): string;
protected markMapperAsUsed(name: string): void;
protected getTypeToUse(name: string, node: {

@@ -129,0 +134,0 @@ name: any;

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

this._collectedDirectiveResolvers = {};
this._usedMappers = {};
autoBind(this);

@@ -27,2 +28,5 @@ this._variablesTransfomer = new variables_to_object_1.OperationVariablesToObject(this.scalars, this.convertName);

}
get unusedMappers() {
return Object.keys(this.config.mappers).filter(name => !this._usedMappers[name]);
}
get mappersImports() {

@@ -145,4 +149,8 @@ const groupedMappers = {};

}
markMapperAsUsed(name) {
this._usedMappers[name] = true;
}
getTypeToUse(name, node) {
if (this.config.mappers[name]) {
this.markMapperAsUsed(name);
return this.config.mappers[name].type;

@@ -149,0 +157,0 @@ }

3

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

@@ -47,3 +47,3 @@ import { DirectiveDefinitionNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, ListTypeNode, NamedTypeNode, NameNode, NonNullTypeNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, UnionTypeDefinitionNode, StringValueNode } from 'graphql';

ObjectTypeDefinition(node: ObjectTypeDefinitionNode, key: number | string, parent: any): string;
InterfaceTypeDefinition(node: InterfaceTypeDefinitionNode): string;
InterfaceTypeDefinition(node: InterfaceTypeDefinitionNode, key: number | string, parent: any): string;
ScalarTypeDefinition(node: ScalarTypeDefinitionNode): string;

@@ -56,2 +56,3 @@ protected _buildEnumImport(identifier: string, source: string): string;

DirectiveDefinition(node: DirectiveDefinitionNode): string;
protected buildArgumentsBlock(node: InterfaceTypeDefinitionNode | ObjectTypeDefinitionNode): string;
protected _getScalar(name: string): string;

@@ -58,0 +59,0 @@ protected _getTypeForNode(node: NamedTypeNode): string;

@@ -78,21 +78,8 @@ "use strict";

.withBlock(node.fields.join('\n')).string;
const original = parent[key];
const fieldsWithArguments = original.fields.filter(field => field.arguments && field.arguments.length > 0);
const fieldsArguments = fieldsWithArguments.map(field => {
const name = original.name.value +
this.convertName(field, {
useTypesPrefix: false,
}) +
'Args';
return new utils_1.DeclarationBlock(this._declarationBlockConfig)
.export()
.asKind('type')
.withName(this.convertName(name))
.withComment(node.description)
.withBlock(this._argumentsTransformer.transform(field.arguments)).string;
});
return [typeDefinition, ...fieldsArguments].filter(f => f).join('\n\n');
const argumentsBlock = this.buildArgumentsBlock(originalNode);
return [typeDefinition, argumentsBlock].filter(f => f).join('\n\n');
}
InterfaceTypeDefinition(node) {
return new utils_1.DeclarationBlock(this._declarationBlockConfig)
InterfaceTypeDefinition(node, key, parent) {
const argumentsBlock = this.buildArgumentsBlock(parent[key]);
const interfaceDefinition = new utils_1.DeclarationBlock(this._declarationBlockConfig)
.export()

@@ -103,2 +90,3 @@ .asKind('type')

.withBlock(node.fields.join('\n')).string;
return [interfaceDefinition, argumentsBlock].filter(f => f).join('\n\n');
}

@@ -161,2 +149,20 @@ ScalarTypeDefinition(node) {

}
buildArgumentsBlock(node) {
const fieldsWithArguments = node.fields.filter(field => field.arguments && field.arguments.length > 0) || [];
return fieldsWithArguments
.map(field => {
const name = node.name.value +
this.convertName(field, {
useTypesPrefix: false,
}) +
'Args';
return new utils_1.DeclarationBlock(this._declarationBlockConfig)
.export()
.asKind('type')
.withName(this.convertName(name))
.withComment(node.description)
.withBlock(this._argumentsTransformer.transform(field.arguments)).string;
})
.join('\n\n');
}
_getScalar(name) {

@@ -163,0 +169,0 @@ return `Scalars['${name}']`;

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

import { NameNode, TypeNode, NamedTypeNode, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLOutputType, GraphQLNamedType, GraphQLSchema } from 'graphql';
import { NameNode, TypeNode, NamedTypeNode, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLOutputType, GraphQLNamedType, GraphQLSchema, StringValueNode } from 'graphql';
import { ScalarsMap } from './types';

@@ -15,3 +15,3 @@ export declare const getConfigValue: <T = any>(value: T, defaultValue: T) => T;

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

@@ -30,3 +30,3 @@ private _config;

asKind(kind: string): DeclarationBlock;
withComment(comment: string | null): DeclarationBlock;
withComment(comment: string | StringValueNode | null): DeclarationBlock;
withMethodCall(methodName: string): DeclarationBlock;

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

@@ -55,2 +55,5 @@ "use strict";

}
if (isStringValueNode(comment)) {
comment = comment.value;
}
const lines = comment.split('\n');

@@ -193,2 +196,5 @@ return lines

exports.buildScalars = buildScalars;
function isStringValueNode(node) {
return node && typeof node === 'object' && node.kind === 'StringValue';
}
//# sourceMappingURL=utils.js.map

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

: this._convertName(baseType, {
useTypesPrefix: true
useTypesPrefix: true,
});

@@ -63,2 +63,5 @@ }

formatTypeString(fieldType, isNonNullType, hasDefaultValue) {
if (hasDefaultValue) {
return `Maybe<${fieldType}>`;
}
return fieldType;

@@ -65,0 +68,0 @@ }

@@ -111,5 +111,9 @@ import { ParsedConfig, RawConfig, BaseVisitor } from './base-visitor';

protected _variablesTransfomer: OperationVariablesToObject;
protected _usedMappers: {
[key: string]: boolean;
};
constructor(rawConfig: TRawConfig, additionalConfig: TPluginConfig, _schema: GraphQLSchema, defaultScalars?: ScalarsMap);
readonly schema: GraphQLSchema;
readonly defaultMapperType: string;
readonly unusedMappers: string[];
readonly mappersImports: string[];

@@ -127,2 +131,3 @@ protected buildMapperImport(source: string, types: string[]): string;

NonNullType(node: NonNullTypeNode): string;
protected markMapperAsUsed(name: string): void;
protected getTypeToUse(name: string, node: {

@@ -129,0 +134,0 @@ name: any;

@@ -15,2 +15,3 @@ import { BaseVisitor } from './base-visitor';

this._collectedDirectiveResolvers = {};
this._usedMappers = {};
autoBind(this);

@@ -25,2 +26,5 @@ this._variablesTransfomer = new OperationVariablesToObject(this.scalars, this.convertName);

}
get unusedMappers() {
return Object.keys(this.config.mappers).filter(name => !this._usedMappers[name]);
}
get mappersImports() {

@@ -143,4 +147,8 @@ const groupedMappers = {};

}
markMapperAsUsed(name) {
this._usedMappers[name] = true;
}
getTypeToUse(name, node) {
if (this.config.mappers[name]) {
this.markMapperAsUsed(name);
return this.config.mappers[name].type;

@@ -147,0 +155,0 @@ }

@@ -47,3 +47,3 @@ import { DirectiveDefinitionNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, ListTypeNode, NamedTypeNode, NameNode, NonNullTypeNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, UnionTypeDefinitionNode, StringValueNode } from 'graphql';

ObjectTypeDefinition(node: ObjectTypeDefinitionNode, key: number | string, parent: any): string;
InterfaceTypeDefinition(node: InterfaceTypeDefinitionNode): string;
InterfaceTypeDefinition(node: InterfaceTypeDefinitionNode, key: number | string, parent: any): string;
ScalarTypeDefinition(node: ScalarTypeDefinitionNode): string;

@@ -56,2 +56,3 @@ protected _buildEnumImport(identifier: string, source: string): string;

DirectiveDefinition(node: DirectiveDefinitionNode): string;
protected buildArgumentsBlock(node: InterfaceTypeDefinitionNode | ObjectTypeDefinitionNode): string;
protected _getScalar(name: string): string;

@@ -58,0 +59,0 @@ protected _getTypeForNode(node: NamedTypeNode): string;

@@ -76,21 +76,8 @@ import { BaseVisitor } from './base-visitor';

.withBlock(node.fields.join('\n')).string;
const original = parent[key];
const fieldsWithArguments = original.fields.filter(field => field.arguments && field.arguments.length > 0);
const fieldsArguments = fieldsWithArguments.map(field => {
const name = original.name.value +
this.convertName(field, {
useTypesPrefix: false,
}) +
'Args';
return new DeclarationBlock(this._declarationBlockConfig)
.export()
.asKind('type')
.withName(this.convertName(name))
.withComment(node.description)
.withBlock(this._argumentsTransformer.transform(field.arguments)).string;
});
return [typeDefinition, ...fieldsArguments].filter(f => f).join('\n\n');
const argumentsBlock = this.buildArgumentsBlock(originalNode);
return [typeDefinition, argumentsBlock].filter(f => f).join('\n\n');
}
InterfaceTypeDefinition(node) {
return new DeclarationBlock(this._declarationBlockConfig)
InterfaceTypeDefinition(node, key, parent) {
const argumentsBlock = this.buildArgumentsBlock(parent[key]);
const interfaceDefinition = new DeclarationBlock(this._declarationBlockConfig)
.export()

@@ -101,2 +88,3 @@ .asKind('type')

.withBlock(node.fields.join('\n')).string;
return [interfaceDefinition, argumentsBlock].filter(f => f).join('\n\n');
}

@@ -159,2 +147,20 @@ ScalarTypeDefinition(node) {

}
buildArgumentsBlock(node) {
const fieldsWithArguments = node.fields.filter(field => field.arguments && field.arguments.length > 0) || [];
return fieldsWithArguments
.map(field => {
const name = node.name.value +
this.convertName(field, {
useTypesPrefix: false,
}) +
'Args';
return new DeclarationBlock(this._declarationBlockConfig)
.export()
.asKind('type')
.withName(this.convertName(name))
.withComment(node.description)
.withBlock(this._argumentsTransformer.transform(field.arguments)).string;
})
.join('\n\n');
}
_getScalar(name) {

@@ -161,0 +167,0 @@ return `Scalars['${name}']`;

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

import { NameNode, TypeNode, NamedTypeNode, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLOutputType, GraphQLNamedType, GraphQLSchema } from 'graphql';
import { NameNode, TypeNode, NamedTypeNode, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLOutputType, GraphQLNamedType, GraphQLSchema, StringValueNode } from 'graphql';
import { ScalarsMap } from './types';

@@ -15,3 +15,3 @@ export declare const getConfigValue: <T = any>(value: T, defaultValue: T) => T;

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

@@ -30,3 +30,3 @@ private _config;

asKind(kind: string): DeclarationBlock;
withComment(comment: string | null): DeclarationBlock;
withComment(comment: string | StringValueNode | null): DeclarationBlock;
withMethodCall(methodName: string): DeclarationBlock;

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

@@ -47,2 +47,5 @@ import { pascalCase } from 'change-case';

}
if (isStringValueNode(comment)) {
comment = comment.value;
}
const lines = comment.split('\n');

@@ -180,2 +183,5 @@ return lines

}
function isStringValueNode(node) {
return node && typeof node === 'object' && node.kind === 'StringValue';
}
//# sourceMappingURL=utils.js.map

@@ -42,3 +42,3 @@ import { Kind } from 'graphql';

: this._convertName(baseType, {
useTypesPrefix: true
useTypesPrefix: true,
});

@@ -61,2 +61,5 @@ }

formatTypeString(fieldType, isNonNullType, hasDefaultValue) {
if (hasDefaultValue) {
return `Maybe<${fieldType}>`;
}
return fieldType;

@@ -63,0 +66,0 @@ }

{
"name": "@graphql-codegen/visitor-plugin-common",
"version": "1.0.5-alpha-0048f936.0+0048f936",
"version": "1.0.5-alpha-179f90c8.4+179f90c8",
"license": "MIT",

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

"dependencies": {
"@graphql-codegen/plugin-helpers": "1.0.5-alpha-0048f936.0+0048f936",
"@graphql-codegen/plugin-helpers": "1.0.5-alpha-179f90c8.4+179f90c8",
"auto-bind": "2.0.0",

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

"devDependencies": {
"@graphql-codegen/testing": "1.0.5-alpha-0048f936.0+0048f936",
"@graphql-codegen/testing": "1.0.5-alpha-179f90c8.4+179f90c8",
"@types/graphql": "14.0.7",

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

},
"gitHead": "0048f936c29eb66c57fa76242943b0c80629101b"
"gitHead": "179f90c85ca33a1203a76f2068095fe24dc8cfa2"
}

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

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