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

@graphql-codegen/visitor-plugin-common

Package Overview
Dependencies
Maintainers
5
Versions
6021
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.3 to 1.0.4-alpha-105519d7.21

2

dist/commonjs/base-resolvers-visitor.js

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

const possibleTypes = originalNode.types
.map(node => this.convertName(node))
.map(node => node.name.value)
.map(f => `'${f}'`)

@@ -198,0 +198,0 @@ .join(' | ');

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

.map(enumOption => {
const optionName = this.convertName(enumOption);
const optionName = this.convertName(enumOption, { useTypesPrefix: false });
const comment = utils_1.transformComment(enumOption.description, 1);

@@ -149,0 +149,0 @@ let enumValue = enumOption.name;

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

suffix: 'Document',
useTypesPrefix: false,
});

@@ -108,0 +109,0 @@ const documentString = `export const ${documentVariableName}${this.config.noGraphQLTag ? ': DocumentNode' : ''} = ${this._gql(node)};`;

@@ -16,4 +16,3 @@ import { SelectionSetNode, FieldNode, FragmentSpreadNode, InlineFragmentNode, GraphQLNamedType, GraphQLSchema } from 'graphql';

};
export declare type FragmentSpreadField = string;
export declare type InlineFragmentField = {
export declare type FragmentsMap = {
[onType: string]: string[];

@@ -36,4 +35,3 @@ };

protected _linksFields: LinkField[];
protected _fragmentSpreads: FragmentSpreadField[];
protected _inlineFragments: InlineFragmentField;
protected _fragments: FragmentsMap;
protected _queriedForTypename: boolean;

@@ -53,4 +51,3 @@ constructor(_scalars: ScalarsMap, _schema: GraphQLSchema, _convertName: ConvertNameFn<BaseVisitorConvertOptions>, _addTypename: boolean, _loadedFragments: LoadedFragment[], _parentSchemaType?: GraphQLNamedType, _selectionSet?: SelectionSetNode);

protected buildLinkFields(fields: LinkField[]): string | null;
protected buildInlineFragments(inlineFragments: InlineFragmentField): string | null;
protected buildFragmentSpread(fragmentsSpread: FragmentSpreadField[]): string | null;
protected buildFragments(fragments: FragmentsMap): string | null;
}

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

this._linksFields = [];
this._fragmentSpreads = [];
this._inlineFragments = {};
this._fragments = {};
this._queriedForTypename = false;

@@ -77,3 +76,7 @@ }

_collectFragmentSpread(node) {
this._fragmentSpreads.push(node.name.value);
const loadedFragment = this._loadedFragments.find(f => f.name === node.name.value);
if (!this._fragments[loadedFragment.onType]) {
this._fragments[loadedFragment.onType] = [];
}
this._fragments[loadedFragment.onType].push(this._convertName(node.name.value, { useTypesPrefix: true, suffix: 'Fragment' }));
}

@@ -83,7 +86,10 @@ _collectInlineFragment(node) {

const schemaType = this._schema.getType(onType);
if (!schemaType) {
throw new Error(`Inline fragment refernces a GraphQL type "${onType}" that does not exists in your schema!`);
}
const selectionSet = this.createNext(schemaType, node.selectionSet);
if (!this._inlineFragments[onType]) {
this._inlineFragments[onType] = [];
if (!this._fragments[onType]) {
this._fragments[onType] = [];
}
this._inlineFragments[onType].push(selectionSet.string);
this._fragments[onType].push(selectionSet.string);
}

@@ -115,5 +121,4 @@ get string() {

const linksFields = this.buildLinkFields(this._linksFields);
const inlineFragments = this.buildInlineFragments(this._inlineFragments);
const fragmentSpreads = this.buildFragmentSpread(this._fragmentSpreads);
const fieldsSet = [typeName, baseFields, aliasBaseFields, linksFields, fragmentSpreads, inlineFragments].filter(f => f && f !== '');
const fragments = this.buildFragments(this._fragments);
const fieldsSet = [typeName, baseFields, aliasBaseFields, linksFields, fragments].filter(f => f && f !== '');
return this.mergeAllFields(fieldsSet);

@@ -155,25 +160,39 @@ }

}
buildInlineFragments(inlineFragments) {
const allPossibleTypes = Object.keys(inlineFragments).map(typeName => inlineFragments[typeName].join(' & '));
return utils_1.quoteIfNeeded(allPossibleTypes, ' | ');
}
buildFragmentSpread(fragmentsSpread) {
if (fragmentsSpread.length === 0) {
return null;
buildFragments(fragments) {
const interfaces = {};
const types = {};
const onInterfaces = Object.keys(fragments).filter(typeName => graphql_1.isInterfaceType(this._schema.getType(typeName)));
const onNonInterfaces = Object.keys(fragments).filter(typeName => !graphql_1.isInterfaceType(this._schema.getType(typeName)));
for (const typeName of onInterfaces) {
const interfaceFragments = fragments[typeName];
interfaces[typeName] = {
fragments: interfaceFragments,
implementingFragments: [],
};
}
const typeToFragment = fragmentsSpread.reduce((prev, fragmentName) => {
const fragmentDef = this._loadedFragments.find(r => r.name === fragmentName);
if (!prev[fragmentDef.onType]) {
prev[fragmentDef.onType] = [];
for (const typeName of onNonInterfaces) {
const schemaType = this._schema.getType(typeName);
if (!schemaType) {
throw new Error(`Inline fragment refernces a GraphQL type "${typeName}" that does not exists in your schema!`);
}
prev[fragmentDef.onType].push(fragmentName);
return prev;
}, {});
const allPossibleTypes = Object.keys(typeToFragment).map(typeName => typeToFragment[typeName]
.map(fragmentName => this._convertName(fragmentName, {
suffix: 'Fragment',
useTypesPrefix: true,
}))
.join(' & '));
return utils_1.quoteIfNeeded(allPossibleTypes, ' | ');
const typeFragments = fragments[typeName];
const interfacesFragments = schemaType.getInterfaces().filter(gqlInterface => !!interfaces[gqlInterface.name]);
if (interfacesFragments.length > 0) {
for (const relevantInterface of interfacesFragments) {
interfaces[relevantInterface.name].implementingFragments.push(...typeFragments);
}
}
else {
types[typeName] = {
fragments: typeFragments,
implementingFragments: [],
};
}
}
const mergedResult = Object.assign({}, interfaces, types);
return utils_1.quoteIfNeeded(Object.keys(mergedResult).map(typeName => {
const baseFragments = utils_1.quoteIfNeeded(mergedResult[typeName].fragments, ' & ');
const implementingFragments = utils_1.quoteIfNeeded(mergedResult[typeName].implementingFragments, ' | ');
return utils_1.quoteIfNeeded([baseFragments, implementingFragments].filter(a => a), ' & ');
}), ' | ');
}

@@ -180,0 +199,0 @@ }

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

const possibleTypes = originalNode.types
.map(node => this.convertName(node))
.map(node => node.name.value)
.map(f => `'${f}'`)

@@ -196,0 +196,0 @@ .join(' | ');

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

.map(enumOption => {
const optionName = this.convertName(enumOption);
const optionName = this.convertName(enumOption, { useTypesPrefix: false });
const comment = transformComment(enumOption.description, 1);

@@ -147,0 +147,0 @@ let enumValue = enumOption.name;

@@ -104,2 +104,3 @@ import { BaseVisitor } from './index';

suffix: 'Document',
useTypesPrefix: false,
});

@@ -106,0 +107,0 @@ const documentString = `export const ${documentVariableName}${this.config.noGraphQLTag ? ': DocumentNode' : ''} = ${this._gql(node)};`;

@@ -16,4 +16,3 @@ import { SelectionSetNode, FieldNode, FragmentSpreadNode, InlineFragmentNode, GraphQLNamedType, GraphQLSchema } from 'graphql';

};
export declare type FragmentSpreadField = string;
export declare type InlineFragmentField = {
export declare type FragmentsMap = {
[onType: string]: string[];

@@ -36,4 +35,3 @@ };

protected _linksFields: LinkField[];
protected _fragmentSpreads: FragmentSpreadField[];
protected _inlineFragments: InlineFragmentField;
protected _fragments: FragmentsMap;
protected _queriedForTypename: boolean;

@@ -53,4 +51,3 @@ constructor(_scalars: ScalarsMap, _schema: GraphQLSchema, _convertName: ConvertNameFn<BaseVisitorConvertOptions>, _addTypename: boolean, _loadedFragments: LoadedFragment[], _parentSchemaType?: GraphQLNamedType, _selectionSet?: SelectionSetNode);

protected buildLinkFields(fields: LinkField[]): string | null;
protected buildInlineFragments(inlineFragments: InlineFragmentField): string | null;
protected buildFragmentSpread(fragmentsSpread: FragmentSpreadField[]): string | null;
protected buildFragments(fragments: FragmentsMap): string | null;
}

@@ -25,4 +25,3 @@ import { Kind, isObjectType, isUnionType, isInterfaceType, isEnumType, isEqualType, SchemaMetaFieldDef, TypeMetaFieldDef, isScalarType, } from 'graphql';

this._linksFields = [];
this._fragmentSpreads = [];
this._inlineFragments = {};
this._fragments = {};
this._queriedForTypename = false;

@@ -75,3 +74,7 @@ }

_collectFragmentSpread(node) {
this._fragmentSpreads.push(node.name.value);
const loadedFragment = this._loadedFragments.find(f => f.name === node.name.value);
if (!this._fragments[loadedFragment.onType]) {
this._fragments[loadedFragment.onType] = [];
}
this._fragments[loadedFragment.onType].push(this._convertName(node.name.value, { useTypesPrefix: true, suffix: 'Fragment' }));
}

@@ -81,7 +84,10 @@ _collectInlineFragment(node) {

const schemaType = this._schema.getType(onType);
if (!schemaType) {
throw new Error(`Inline fragment refernces a GraphQL type "${onType}" that does not exists in your schema!`);
}
const selectionSet = this.createNext(schemaType, node.selectionSet);
if (!this._inlineFragments[onType]) {
this._inlineFragments[onType] = [];
if (!this._fragments[onType]) {
this._fragments[onType] = [];
}
this._inlineFragments[onType].push(selectionSet.string);
this._fragments[onType].push(selectionSet.string);
}

@@ -113,5 +119,4 @@ get string() {

const linksFields = this.buildLinkFields(this._linksFields);
const inlineFragments = this.buildInlineFragments(this._inlineFragments);
const fragmentSpreads = this.buildFragmentSpread(this._fragmentSpreads);
const fieldsSet = [typeName, baseFields, aliasBaseFields, linksFields, fragmentSpreads, inlineFragments].filter(f => f && f !== '');
const fragments = this.buildFragments(this._fragments);
const fieldsSet = [typeName, baseFields, aliasBaseFields, linksFields, fragments].filter(f => f && f !== '');
return this.mergeAllFields(fieldsSet);

@@ -153,27 +158,41 @@ }

}
buildInlineFragments(inlineFragments) {
const allPossibleTypes = Object.keys(inlineFragments).map(typeName => inlineFragments[typeName].join(' & '));
return quoteIfNeeded(allPossibleTypes, ' | ');
}
buildFragmentSpread(fragmentsSpread) {
if (fragmentsSpread.length === 0) {
return null;
buildFragments(fragments) {
const interfaces = {};
const types = {};
const onInterfaces = Object.keys(fragments).filter(typeName => isInterfaceType(this._schema.getType(typeName)));
const onNonInterfaces = Object.keys(fragments).filter(typeName => !isInterfaceType(this._schema.getType(typeName)));
for (const typeName of onInterfaces) {
const interfaceFragments = fragments[typeName];
interfaces[typeName] = {
fragments: interfaceFragments,
implementingFragments: [],
};
}
const typeToFragment = fragmentsSpread.reduce((prev, fragmentName) => {
const fragmentDef = this._loadedFragments.find(r => r.name === fragmentName);
if (!prev[fragmentDef.onType]) {
prev[fragmentDef.onType] = [];
for (const typeName of onNonInterfaces) {
const schemaType = this._schema.getType(typeName);
if (!schemaType) {
throw new Error(`Inline fragment refernces a GraphQL type "${typeName}" that does not exists in your schema!`);
}
prev[fragmentDef.onType].push(fragmentName);
return prev;
}, {});
const allPossibleTypes = Object.keys(typeToFragment).map(typeName => typeToFragment[typeName]
.map(fragmentName => this._convertName(fragmentName, {
suffix: 'Fragment',
useTypesPrefix: true,
}))
.join(' & '));
return quoteIfNeeded(allPossibleTypes, ' | ');
const typeFragments = fragments[typeName];
const interfacesFragments = schemaType.getInterfaces().filter(gqlInterface => !!interfaces[gqlInterface.name]);
if (interfacesFragments.length > 0) {
for (const relevantInterface of interfacesFragments) {
interfaces[relevantInterface.name].implementingFragments.push(...typeFragments);
}
}
else {
types[typeName] = {
fragments: typeFragments,
implementingFragments: [],
};
}
}
const mergedResult = Object.assign({}, interfaces, types);
return quoteIfNeeded(Object.keys(mergedResult).map(typeName => {
const baseFragments = quoteIfNeeded(mergedResult[typeName].fragments, ' & ');
const implementingFragments = quoteIfNeeded(mergedResult[typeName].implementingFragments, ' | ');
return quoteIfNeeded([baseFragments, implementingFragments].filter(a => a), ' & ');
}), ' | ');
}
}
//# sourceMappingURL=selection-set-to-object.js.map
{
"name": "@graphql-codegen/visitor-plugin-common",
"version": "1.0.3",
"version": "1.0.4-alpha-105519d7.21+105519d7",
"license": "MIT",

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

"dependencies": {
"@graphql-codegen/plugin-helpers": "1.0.3",
"@graphql-codegen/plugin-helpers": "1.0.4-alpha-105519d7.21+105519d7",
"auto-bind": "2.0.0",

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

"devDependencies": {
"@graphql-codegen/testing": "1.0.3",
"@graphql-codegen/testing": "1.0.4-alpha-105519d7.21+105519d7",
"@types/graphql": "14.0.7",

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

},
"gitHead": "f444f37c6fc706bc182c0a39ce11025eb6b760c0"
"gitHead": "105519d7565cacd7c1225e6fd278dd8addc6d279"
}

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