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

@envelop/extended-validation

Package Overview
Dependencies
Maintainers
1
Versions
1304
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@envelop/extended-validation - npm Package Compare versions

Comparing version 1.4.1-alpha-e859732.0 to 1.4.1

6

common.d.ts

@@ -1,7 +0,5 @@

import { TypedExecutionArgs } from '@envelop/core';
import { ASTVisitor, DirectiveNode, GraphQLNamedType, GraphQLType, ValidationContext } from 'graphql';
export declare type ExtendedValidationRule<ContextType> = (context: ValidationContext, executionArgs: TypedExecutionArgs<ContextType>) => ASTVisitor;
import { ASTVisitor, DirectiveNode, ExecutionArgs, ValidationContext } from 'graphql';
export declare type ExtendedValidationRule = (context: ValidationContext, executionArgs: ExecutionArgs) => ASTVisitor;
export declare function getDirectiveFromAstNode(astNode: {
directives?: ReadonlyArray<DirectiveNode>;
}, names: string | string[]): null | DirectiveNode;
export declare function unwrapType(type: GraphQLType): GraphQLNamedType;

@@ -81,8 +81,2 @@ 'use strict';

}
function unwrapType(type) {
if (graphql.isNonNullType(type) || graphql.isListType(type)) {
return unwrapType(type.ofType);
}
return type;
}

@@ -102,8 +96,6 @@ const ONE_OF_DIRECTIVE_SDL = /* GraphQL */ `

const values = utils.getArgumentValues(fieldType, node, executionArgs.variableValues || undefined);
if (fieldType) {
const isOneOfFieldType = ((_b = fieldType.extensions) === null || _b === void 0 ? void 0 : _b.oneOf) || (fieldType.astNode && getDirectiveFromAstNode(fieldType.astNode, 'oneOf'));
if (isOneOfFieldType) {
if (Object.keys(values).length !== 1) {
validationContext.reportError(new graphql.GraphQLError(`Exactly one key must be specified for input for field "${fieldType.type.toString()}.${node.name.value}"`, [node]));
}
const isOneOfFieldType = ((_b = fieldType.extensions) === null || _b === void 0 ? void 0 : _b.oneOf) || (fieldType.astNode && getDirectiveFromAstNode(fieldType.astNode, 'oneOf'));
if (isOneOfFieldType) {
if (Object.keys(values).length !== 1) {
validationContext.reportError(new graphql.GraphQLError(`Exactly one key must be specified for input for field "${fieldType.type.toString()}.${node.name.value}"`, [node]));
}

@@ -121,2 +113,8 @@ }

};
function getNonNullType(ttype) {
if (ttype instanceof graphql.GraphQLNonNull) {
return ttype.ofType;
}
return ttype;
}
function traverseVariables(validationContext, arg, graphqlType, currentValue) {

@@ -129,3 +127,4 @@ var _a;

}
if (graphql.isListType(graphqlType)) {
const unwrappedType = getNonNullType(graphqlType);
if (graphql.isListType(unwrappedType)) {
if (!Array.isArray(currentValue)) {

@@ -136,3 +135,3 @@ // because of graphql type coercion a single object should be treated as an array of one object

currentValue.forEach(value => {
traverseVariables(validationContext, arg, graphqlType.ofType, value);
traverseVariables(validationContext, arg, unwrappedType.ofType, value);
});

@@ -145,3 +144,3 @@ return;

}
const inputType = unwrapType(graphqlType);
const inputType = graphql.getNamedType(graphqlType);
const isOneOfInputType = ((_a = inputType.extensions) === null || _a === void 0 ? void 0 : _a.oneOf) || (inputType.astNode && getDirectiveFromAstNode(inputType.astNode, 'oneOf'));

@@ -163,3 +162,2 @@ if (isOneOfInputType) {

exports.getDirectiveFromAstNode = getDirectiveFromAstNode;
exports.unwrapType = unwrapType;
exports.useExtendedValidation = useExtendedValidation;
{
"name": "@envelop/extended-validation",
"version": "1.4.1-alpha-e859732.0",
"version": "1.4.1",
"sideEffects": false,
"peerDependencies": {
"@envelop/core": "2.1.1-alpha-e859732.0",
"@envelop/core": "^2.1.0",
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"

@@ -8,0 +8,0 @@ },

import { Plugin } from '@envelop/core';
import { ExecutionArgs, ExecutionResult } from 'graphql';
import { ExtendedValidationRule } from './common';
declare const symbolExtendedValidationRules: unique symbol;
declare type ExtendedValidationContext<ContextType> = {
rules: Array<ExtendedValidationRule<ContextType>>;
didRun: boolean;
};
declare type OnValidationFailedCallback = (params: {

@@ -14,12 +9,9 @@ args: ExecutionArgs;

}) => void;
declare type PluginContext<TContextValue> = {
[symbolExtendedValidationRules]: ExtendedValidationContext<TContextValue>;
};
export declare const useExtendedValidation: <TContextValue = unknown>(options: {
rules: ExtendedValidationRule<TContextValue>[];
export declare const useExtendedValidation: (options: {
rules: Array<ExtendedValidationRule>;
/**
* Callback that is invoked if the extended validation yields any errors.
*/
onValidationFailed?: OnValidationFailedCallback | undefined;
}) => Plugin<PluginContext<TContextValue>, PluginContext<TContextValue>>;
onValidationFailed?: OnValidationFailedCallback;
}) => Plugin;
export {};
import { ExtendedValidationRule } from '../common';
export declare const ONE_OF_DIRECTIVE_SDL = "\n directive @oneOf on INPUT_OBJECT | FIELD_DEFINITION\n";
export declare const OneOfInputObjectsRule: ExtendedValidationRule<unknown>;
export declare const OneOfInputObjectsRule: ExtendedValidationRule;

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