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.4-alpha-18a320e1.0 to 1.0.4-alpha-4643617a.11

6

dist/commonjs/client-side-base-visitor.js

@@ -104,6 +104,10 @@ "use strict";

}
const documentName = this.convertName(node, {
suffix: 'Document',
useTypesPrefix: false,
});
const documentVariableName = this.convertName(node, {
suffix: 'Document',
});
const documentString = `export const ${documentVariableName}${this.config.noGraphQLTag ? ': DocumentNode' : ''} = ${this._gql(node)};`;
const documentString = `export const ${documentName}${this.config.noGraphQLTag ? ': DocumentNode' : ''} = ${this._gql(node)};`;
const operationType = plugin_helpers_1.toPascalCase(node.operation);

@@ -110,0 +114,0 @@ const operationResultType = this.convertName(node, {

9

dist/commonjs/selection-set-to-object.d.ts

@@ -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 @@ }

@@ -102,6 +102,10 @@ import { BaseVisitor } from './index';

}
const documentName = this.convertName(node, {
suffix: 'Document',
useTypesPrefix: false,
});
const documentVariableName = this.convertName(node, {
suffix: 'Document',
});
const documentString = `export const ${documentVariableName}${this.config.noGraphQLTag ? ': DocumentNode' : ''} = ${this._gql(node)};`;
const documentString = `export const ${documentName}${this.config.noGraphQLTag ? ': DocumentNode' : ''} = ${this._gql(node)};`;
const operationType = toPascalCase(node.operation);

@@ -108,0 +112,0 @@ const operationResultType = this.convertName(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.4-alpha-18a320e1.0+18a320e1",
"version": "1.0.4-alpha-4643617a.11+4643617a",
"license": "MIT",

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

"dependencies": {
"@graphql-codegen/plugin-helpers": "1.0.4-alpha-18a320e1.0+18a320e1",
"@graphql-codegen/plugin-helpers": "1.0.4-alpha-4643617a.11+4643617a",
"auto-bind": "2.0.0",

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

"devDependencies": {
"@graphql-codegen/testing": "1.0.4-alpha-18a320e1.0+18a320e1",
"@graphql-codegen/testing": "1.0.4-alpha-4643617a.11+4643617a",
"@types/graphql": "14.0.7",

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

},
"gitHead": "18a320e14bf2c0b029adaf8ef91f9de97853604e"
"gitHead": "4643617a5aaf56a6e59519c3677924f587b3b250"
}

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