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

graphql-codegen-core

Package Overview
Dependencies
Maintainers
1
Versions
1651
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-codegen-core - npm Package Compare versions

Comparing version 0.6.0-alpha.548c19d9 to 0.6.0-alpha.624c8437

41

dist/operations/build-selection-set.js
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var types_1 = require("../types");
var graphql_1 = require("graphql");

@@ -7,2 +16,15 @@ var kinds_1 = require("graphql/language/kinds");

var resolve_type_1 = require("../schema/resolve-type");
function separateSelectionSet(selectionSet) {
var fields = selectionSet.filter(function (n) { return types_1.isFieldNode(n); });
var fragmentsSpread = selectionSet.filter(function (n) { return types_1.isFragmentSpreadNode(n); });
var inlineFragments = selectionSet.filter(function (n) { return types_1.isInlineFragmentNode(n); });
return {
fragmentsSpread: fragmentsSpread,
fields: fields,
inlineFragments: inlineFragments,
hasFragmentsSpread: fragmentsSpread.length > 0,
hasFields: fields.length > 0,
hasInlineFragments: inlineFragments.length > 0,
};
}
function buildSelectionSet(schema, rootObject, node) {

@@ -14,9 +36,4 @@ return (node && node.selections ? node.selections : []).map(function (selectionNode) {

var resolvedType = resolve_type_1.resolveType(field.type);
return {
name: fieldNode.alias && fieldNode.alias.value ? fieldNode.alias.value : fieldNode.name.value,
selectionSet: buildSelectionSet(schema, graphql_1.getNamedType(field.type), fieldNode.selectionSet),
type: resolvedType.name,
isRequired: resolvedType.isRequired,
isArray: resolvedType.isArray,
};
var childSelectionSet = buildSelectionSet(schema, graphql_1.getNamedType(field.type), fieldNode.selectionSet);
return __assign({ isField: true, isFragmentSpread: false, isInlineFragment: false, isLeaf: childSelectionSet.length === 0, name: fieldNode.alias && fieldNode.alias.value ? fieldNode.alias.value : fieldNode.name.value, selectionSet: childSelectionSet }, separateSelectionSet(childSelectionSet), { type: resolvedType.name, isRequired: resolvedType.isRequired, isArray: resolvedType.isArray });
}

@@ -26,2 +43,6 @@ else if (selectionNode.kind === kinds_1.FRAGMENT_SPREAD) {

return {
isField: false,
isFragmentSpread: true,
isInlineFragment: false,
isLeaf: true,
fragmentName: fieldNode.name.value,

@@ -33,6 +54,4 @@ };

var nextRoot = graphql_1.typeFromAST(schema, fieldNode.typeCondition);
return {
selectionSet: buildSelectionSet(schema, nextRoot, fieldNode.selectionSet),
onType: fieldNode.typeCondition.name.value,
};
var childSelectionSet = buildSelectionSet(schema, nextRoot, fieldNode.selectionSet);
return __assign({ isField: false, isFragmentSpread: false, isInlineFragment: true, isLeaf: childSelectionSet.length === 0, selectionSet: childSelectionSet }, separateSelectionSet(childSelectionSet), { onType: fieldNode.typeCondition.name.value });
}

@@ -39,0 +58,0 @@ else {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var graphql_1 = require("graphql");
var object_map_to_array_1 = require("../utils/object-map-to-array");

@@ -11,2 +12,4 @@ var resolve_type_1 = require("./resolve-type");

var resolvedArguments = resolve_arguments_1.resolveArguments(item.value.args || []);
var namedType = graphql_1.getNamedType(item.value.type);
var isEnum = namedType['getValues'] !== undefined;
return {

@@ -20,2 +23,8 @@ name: item.value.name,

hasArguments: resolvedArguments.length > 0,
isType: namedType['getFields'] !== undefined && namedType['getInterfaces'] !== undefined,
isScalar: graphql_1.isLeafType(namedType) && !isEnum,
isInterface: namedType['resolveType'] !== undefined && namedType['getFields'] !== undefined,
isUnion: namedType['resolveType'] !== undefined && namedType['getTypes'] !== undefined,
isInputType: namedType['getFields'] !== undefined && namedType['getInterfaces'] === undefined,
isEnum: isEnum,
};

@@ -22,0 +31,0 @@ });

@@ -16,2 +16,8 @@ export interface Argument {

hasArguments: boolean;
isType: boolean;
isScalar: boolean;
isInterface: boolean;
isUnion: boolean;
isInputType: boolean;
isEnum: boolean;
}

@@ -67,2 +73,6 @@ export interface Type {

export interface SelectionSetItem {
isFragmentSpread: boolean;
isInlineFragment: boolean;
isField: boolean;
isLeaf: boolean;
}

@@ -72,2 +82,8 @@ export interface SelectionSetInlineFragment extends SelectionSetItem {

onType: string;
fields: SelectionSetFieldNode[];
fragmentsSpread: SelectionSetFragmentSpread[];
inlineFragments: SelectionSetInlineFragment[];
hasFragmentsSpread: boolean;
hasInlineFragments: boolean;
hasFields: boolean;
}

@@ -78,7 +94,13 @@ export interface SelectionSetFragmentSpread extends SelectionSetItem {

export interface SelectionSetFieldNode extends SelectionSetItem {
selectionSet: SelectionSetItem[];
name: string;
selectionSet: SelectionSetItem[];
type: string;
isRequired: boolean;
isArray: boolean;
fields: SelectionSetFieldNode[];
fragmentsSpread: SelectionSetFragmentSpread[];
inlineFragments: SelectionSetInlineFragment[];
hasFragmentsSpread: boolean;
hasInlineFragments: boolean;
hasFields: boolean;
}

@@ -85,0 +107,0 @@ export declare function isFieldNode(node: SelectionSetItem): node is SelectionSetFieldNode;

{
"name": "graphql-codegen-core",
"version": "0.6.0-alpha.548c19d9",
"version": "0.6.0-alpha.624c8437",
"description": "GraphQL types and code generator based on schema",

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

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