New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

graphql-compose-modules

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-compose-modules - npm Package Compare versions

Comparing version 2.0.0-beta.1 to 2.0.0-beta.2

6

lib/astVisitor.d.ts

@@ -13,5 +13,5 @@ import { SchemaComposer } from 'graphql-compose';

export declare type VisitorEmptyResult = void | typeof VISITOR_REMOVE_NODE | typeof VISITOR_SKIP_CHILDREN;
export declare type VisitKindFn<NodeKind> = (
export declare type VisitKindFn<TNode extends AstDirNode | AstFileNode | AstRootTypeNode> = (
/** Info & helper functions from visitor during traversing AST tree */
info: VisitInfo) => VisitorEmptyResult | NodeKind;
info: VisitInfo<TNode>) => VisitorEmptyResult | TNode;
/**

@@ -38,4 +38,4 @@ * Functions for every type of AST nodes which will be called by visitor.

export declare function astVisitor(ast: AstRootNode, schemaComposer: SchemaComposer<any>, visitor: AstVisitor): void;
export declare function visitNode(info: VisitInfo, visitor: AstVisitor): void;
export declare function visitNode(info: VisitInfo<AstDirNode | AstFileNode | AstRootTypeNode>, visitor: AstVisitor): void;
export declare function forEachKey<V>(obj: Record<string, V>, callback: (value: V, key: string) => void): void;
//# sourceMappingURL=astVisitor.d.ts.map

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

// `null` - means remove node from Ast and do not traverse children
delete info.nodeParent.children[info.fieldName];
delete info.nodeParent.children[info.node.name];
return;

@@ -76,3 +76,3 @@ }

// replace node
info.nodeParent.children[info.fieldName] = result;
info.nodeParent.children[info.node.name] = result;
}

@@ -79,0 +79,0 @@ else {

import { ComposeNamedOutputType, ComposeOutputType, ObjectTypeComposer, SchemaComposer } from 'graphql-compose';
import { AstDirNode, AstFileNode, AstRootNode, AstRootTypeNode, RootTypeNames } from './directoryToAst';
import { FieldConfig } from './typeDefs';
interface VisitInfoData<TContext = any> {
node: AstDirNode | AstFileNode | AstRootTypeNode;
interface VisitInfoData<TNode extends AstDirNode | AstFileNode | AstRootTypeNode, TContext = any> {
node: TNode;
nodeParent: AstDirNode | AstRootTypeNode | AstRootNode;

@@ -12,4 +12,4 @@ operation: RootTypeNames;

}
export declare class VisitInfo<TContext = any> {
node: AstDirNode | AstFileNode | AstRootTypeNode;
export declare class VisitInfo<TNode extends AstDirNode | AstFileNode | AstRootTypeNode, TContext = any> {
node: TNode;
/** Parent AST node from directoryToAst */

@@ -25,3 +25,3 @@ nodeParent: AstDirNode | AstRootTypeNode | AstRootNode;

schemaComposer: SchemaComposer<TContext>;
constructor(data: VisitInfoData<TContext>);
constructor(data: VisitInfoData<TNode, TContext>);
/**

@@ -28,0 +28,0 @@ * Check that this entrypoint belongs to Query

@@ -7,8 +7,18 @@ "use strict";

function VisitInfo(data) {
var _a;
this.node = data.node;
this.operation = data.operation;
this.nodeParent = data.nodeParent;
this.fieldName = data.fieldName;
this.schemaComposer = data.schemaComposer;
this.fieldPath = data.fieldPath;
this.schemaComposer = data.schemaComposer;
if (data.fieldName.indexOf('.')) {
// if fieldName has dots, then split it
var parts = data.fieldName.split('.').filter(Boolean);
var fieldName = parts.pop();
this.fieldName = fieldName;
(_a = this.fieldPath).push.apply(_a, parts);
}
else {
this.fieldName = data.fieldName;
}
}

@@ -59,2 +69,3 @@ /**

}
// slice(1) - remove first element from array
return (opts === null || opts === void 0 ? void 0 : opts.includeOperation) ? res : res.slice(1);

@@ -85,9 +96,10 @@ };

var _a, _b, _c;
if (this.node.kind === 'file') {
return (_a = this.node.code) === null || _a === void 0 ? void 0 : _a.default;
var node = this.node;
if (node.kind === 'file') {
return (_a = node.code) === null || _a === void 0 ? void 0 : _a.default;
}
else if (this.node.kind === 'dir' || this.node.kind === 'rootType') {
return (_c = (_b = this.node.namespaceConfig) === null || _b === void 0 ? void 0 : _b.code) === null || _c === void 0 ? void 0 : _c.default;
else if (node.kind === 'dir' || this.node.kind === 'rootType') {
return (_c = (_b = node.namespaceConfig) === null || _b === void 0 ? void 0 : _b.code) === null || _c === void 0 ? void 0 : _c.default;
}
throw new Error("Cannot get fieldConfig. Node has some strange kind: " + this.node.kind);
throw new Error("Cannot get fieldConfig. Node has some strange kind: " + node.kind);
},

@@ -94,0 +106,0 @@ enumerable: false,

{
"name": "graphql-compose-modules",
"license": "MIT",
"version": "2.0.0-beta.1",
"version": "2.0.0-beta.2",
"description": "A toolkit for construction GraphQL Schema via file structure",

@@ -6,0 +6,0 @@ "repository": "https://github.com/graphql-compose/graphql-compose-modules",

@@ -188,6 +188,6 @@ # graphql-compose-modules

): void {
astVisitor(ast, {
astVisitor(ast, schemaComposer, {
// skip `query` & `subscriptions` root types
ROOT_TYPE: (node) => {
if (node.name !== 'mutation') {
ROOT_TYPE: (info) => {
if (!info.isMutation) {
return VISITOR_SKIP_CHILDREN;

@@ -198,15 +198,14 @@ }

// for every file in `mutation` folder try to add `query` field if it does not exists
FILE: (node, nodeInfo) => {
const fieldConfig = node.code.default || {};
FILE: (info) => {
// get FieldConfig from loaded file in `schema` folder
const fieldConfig = info.fieldConfig || {};
// if `resolve` method does not exist then skip this transformation
const next = fieldConfig.resolve;
if (!next) return;
const outputType = fieldConfig.type;
if (!outputType) return;
const outputTC = schemaComposer.typeMapper.convertOutputTypeDefinition(
outputType,
nodeInfo.name,
nodeInfo?.parent?.name
);
if (!(outputTC instanceof ObjectTypeComposer)) return;
// if output type isn't an object then skip this transformation
if (!info.isOutputTypeIsObject()) return;
const outputTC = info.getOutputUnwrappedOTC();
if (outputTC.hasField('query')) return;

@@ -232,4 +231,2 @@ outputTC.setField('query', {

For now here is provided basic overview of the available API methods. Then detailed information will be provided later.
### Main API method:

@@ -248,2 +245,2 @@

- `astMerge(...asts: Array<AstRootNode>): AstRootNode` – combines several ASTs to one AST (helps compose several graphql schemas which may be distributed via npm packages)
- `astVisitor(ast: AstRootNode, visitor: AstVisitor): void` – modify AST via visitor pattern. This method is used for construction of your AST transformers.
- `astVisitor(ast: AstRootNode, schemaComposer: SchemaComposer, visitor: AstVisitor): void` – modify AST via visitor pattern. This method is used for construction of your AST transformers.

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