Socket
Socket
Sign inDemoInstall

graphql

Package Overview
Dependencies
0
Maintainers
0
Versions
253
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 16.8.2 to 16.9.0

validation/rules/MaxIntrospectionDepthRule.d.ts

3

index.d.ts

@@ -57,2 +57,3 @@ /**

GraphQLSpecifiedByDirective,
GraphQLOneOfDirective,
TypeKind,

@@ -304,2 +305,3 @@ DEFAULT_DEPRECATION_REASON,

specifiedRules,
recommendedRules,
ExecutableDefinitionsRule,

@@ -331,2 +333,3 @@ FieldsOnCorrectTypeRule,

VariablesInAllowedPositionRule,
MaxIntrospectionDepthRule,
LoneSchemaDefinitionRule,

@@ -333,0 +336,0 @@ UniqueOperationTypesRule,

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

});
Object.defineProperty(exports, 'GraphQLOneOfDirective', {
enumerable: true,
get: function () {
return _index.GraphQLOneOfDirective;
},
});
Object.defineProperty(exports, 'GraphQLScalarType', {

@@ -241,2 +247,8 @@ enumerable: true,

});
Object.defineProperty(exports, 'MaxIntrospectionDepthRule', {
enumerable: true,
get: function () {
return _index4.MaxIntrospectionDepthRule;
},
});
Object.defineProperty(exports, 'NoDeprecatedCustomRule', {

@@ -1136,2 +1148,8 @@ enumerable: true,

});
Object.defineProperty(exports, 'recommendedRules', {
enumerable: true,
get: function () {
return _index4.recommendedRules;
},
});
Object.defineProperty(exports, 'resolveObjMapThunk', {

@@ -1138,0 +1156,0 @@ enumerable: true,

2

package.json
{
"name": "graphql",
"version": "16.8.2",
"version": "16.9.0",
"description": "A Query Language and Runtime which can target any service.",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -792,3 +792,3 @@ import type { Maybe } from '../jsutils/Maybe';

description?: Maybe<string>;
values: GraphQLEnumValueConfigMap;
values: ThunkObjMap<GraphQLEnumValueConfig>;
extensions?: Maybe<Readonly<GraphQLEnumTypeExtensions>>;

@@ -799,2 +799,3 @@ astNode?: Maybe<EnumTypeDefinitionNode>;

interface GraphQLEnumTypeNormalizedConfig extends GraphQLEnumTypeConfig {
values: ObjMap<GraphQLEnumValueConfig>;
extensions: Readonly<GraphQLEnumTypeExtensions>;

@@ -870,2 +871,3 @@ extensionASTNodes: ReadonlyArray<EnumTypeExtensionNode>;

extensionASTNodes: ReadonlyArray<InputObjectTypeExtensionNode>;
isOneOf: boolean;
private _fields;

@@ -886,2 +888,3 @@ constructor(config: Readonly<GraphQLInputObjectTypeConfig>);

extensionASTNodes?: Maybe<ReadonlyArray<InputObjectTypeExtensionNode>>;
isOneOf?: boolean;
}

@@ -888,0 +891,0 @@ interface GraphQLInputObjectTypeNormalizedConfig

@@ -1080,7 +1080,8 @@ 'use strict';

: [];
this._values = defineEnumValues(this.name, config.values);
this._valueLookup = new Map(
this._values.map((enumValue) => [enumValue.value, enumValue]),
);
this._nameLookup = (0, _keyMap.keyMap)(this._values, (value) => value.name);
this._values =
typeof config.values === 'function'
? config.values
: defineEnumValues(this.name, config.values);
this._valueLookup = null;
this._nameLookup = null;
}

@@ -1093,2 +1094,6 @@

getValues() {
if (typeof this._values === 'function') {
this._values = defineEnumValues(this.name, this._values());
}
return this._values;

@@ -1098,2 +1103,9 @@ }

getValue(name) {
if (this._nameLookup === null) {
this._nameLookup = (0, _keyMap.keyMap)(
this.getValues(),
(value) => value.name,
);
}
return this._nameLookup[name];

@@ -1103,2 +1115,8 @@ }

serialize(outputValue) {
if (this._valueLookup === null) {
this._valueLookup = new Map(
this.getValues().map((enumValue) => [enumValue.value, enumValue]),
);
}
const enumValue = this._valueLookup.get(outputValue);

@@ -1260,3 +1278,3 @@

constructor(config) {
var _config$extensionASTN6;
var _config$extensionASTN6, _config$isOneOf;

@@ -1272,2 +1290,6 @@ this.name = (0, _assertName.assertName)(config.name);

: [];
this.isOneOf =
(_config$isOneOf = config.isOneOf) !== null && _config$isOneOf !== void 0
? _config$isOneOf
: false;
this._fields = defineInputFieldMap.bind(undefined, config);

@@ -1304,2 +1326,3 @@ }

extensionASTNodes: this.extensionASTNodes,
isOneOf: this.isOneOf,
};

@@ -1306,0 +1329,0 @@ }

@@ -80,2 +80,6 @@ import type { Maybe } from '../jsutils/Maybe';

/**
* Used to indicate an Input Object is a OneOf Input Object.
*/
export declare const GraphQLOneOfDirective: GraphQLDirective;
/**
* The full list of specified directives.

@@ -82,0 +86,0 @@ */

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

exports.GraphQLSkipDirective =
exports.GraphQLOneOfDirective =
exports.GraphQLIncludeDirective =

@@ -211,6 +212,18 @@ exports.GraphQLDirective =

/**
* Used to indicate an Input Object is a OneOf Input Object.
*/
exports.GraphQLSpecifiedByDirective = GraphQLSpecifiedByDirective;
const GraphQLOneOfDirective = new GraphQLDirective({
name: 'oneOf',
description:
'Indicates exactly one field must be supplied and this field must not be `null`.',
locations: [_directiveLocation.DirectiveLocation.INPUT_OBJECT],
args: {},
});
/**
* The full list of specified directives.
*/
exports.GraphQLSpecifiedByDirective = GraphQLSpecifiedByDirective;
exports.GraphQLOneOfDirective = GraphQLOneOfDirective;
const specifiedDirectives = Object.freeze([

@@ -221,2 +234,3 @@ GraphQLIncludeDirective,

GraphQLSpecifiedByDirective,
GraphQLOneOfDirective,
]);

@@ -223,0 +237,0 @@ exports.specifiedDirectives = specifiedDirectives;

@@ -116,2 +116,3 @@ export type { Path as ResponsePath } from '../jsutils/Path';

GraphQLSpecifiedByDirective,
GraphQLOneOfDirective,
DEFAULT_DEPRECATION_REASON,

@@ -118,0 +119,0 @@ } from './directives';

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

});
Object.defineProperty(exports, 'GraphQLOneOfDirective', {
enumerable: true,
get: function () {
return _directives.GraphQLOneOfDirective;
},
});
Object.defineProperty(exports, 'GraphQLScalarType', {

@@ -104,0 +110,0 @@ enumerable: true,

@@ -376,2 +376,10 @@ 'use strict';

},
isOneOf: {
type: _scalars.GraphQLBoolean,
resolve: (type) => {
if ((0, _definition.isInputObjectType)(type)) {
return type.isOneOf;
}
},
},
}),

@@ -378,0 +386,0 @@ });

@@ -571,5 +571,29 @@ 'use strict';

}
if (inputObj.isOneOf) {
validateOneOfInputObjectField(inputObj, field, context);
}
}
}
function validateOneOfInputObjectField(type, field, context) {
if ((0, _definition.isNonNullType)(field.type)) {
var _field$astNode4;
context.reportError(
`OneOf input field ${type.name}.${field.name} must be nullable.`,
(_field$astNode4 = field.astNode) === null || _field$astNode4 === void 0
? void 0
: _field$astNode4.type,
);
}
if (field.defaultValue !== undefined) {
context.reportError(
`OneOf input field ${type.name}.${field.name} cannot have a default value.`,
field.astNode,
);
}
}
function createInputObjectCircularRefsValidator(context) {

@@ -576,0 +600,0 @@ // Modified copy of algorithm from 'src/validation/rules/NoFragmentCycles.js'.

@@ -282,2 +282,3 @@ 'use strict';

fields: () => buildInputValueDefMap(inputObjectIntrospection.inputFields),
isOneOf: inputObjectIntrospection.isOneOf,
});

@@ -284,0 +285,0 @@ }

@@ -142,2 +142,27 @@ 'use strict';

if (type.isOneOf) {
const keys = Object.keys(coercedValue);
if (keys.length !== 1) {
onError(
(0, _Path.pathToArray)(path),
inputValue,
new _GraphQLError.GraphQLError(
`Exactly one key must be specified for OneOf type "${type.name}".`,
),
);
}
const key = keys[0];
const value = coercedValue[key];
if (value === null) {
onError(
(0, _Path.pathToArray)(path).concat(key),
value,
new _GraphQLError.GraphQLError(`Field "${key}" must be non-null.`),
);
}
}
return coercedValue;

@@ -144,0 +169,0 @@ }

@@ -760,2 +760,3 @@ 'use strict';

extensionASTNodes,
isOneOf: isOneOf(astNode),
});

@@ -800,1 +801,10 @@ }

}
/**
* Given an input object node, returns if the node should be OneOf.
*/
function isOneOf(node) {
return Boolean(
(0, _values.getDirectiveValues)(_directives.GraphQLOneOfDirective, node),
);
}

@@ -29,2 +29,7 @@ import type { Maybe } from '../jsutils/Maybe';

inputValueDeprecation?: boolean;
/**
* Whether target GraphQL server supports `@oneOf` input objects.
* Default: false
*/
oneOf?: boolean;
}

@@ -116,2 +121,3 @@ /**

readonly inputFields: ReadonlyArray<IntrospectionInputValue>;
readonly isOneOf: boolean;
}

@@ -118,0 +124,0 @@ export interface IntrospectionListTypeRef<

@@ -19,2 +19,3 @@ 'use strict';

inputValueDeprecation: false,
oneOf: false,
...options,

@@ -37,2 +38,3 @@ };

const oneOf = optionsWithDefault.oneOf ? 'isOneOf' : '';
return `

@@ -65,2 +67,3 @@ query IntrospectionQuery {

${specifiedByUrl}
${oneOf}
fields(includeDeprecated: true) {

@@ -67,0 +70,0 @@ name

@@ -31,2 +31,3 @@ 'use strict';

inputValueDeprecation: true,
oneOf: true,
...options,

@@ -33,0 +34,0 @@ };

@@ -217,3 +217,8 @@ 'use strict';

);
return printDescription(type) + `input ${type.name}` + printBlock(fields);
return (
printDescription(type) +
`input ${type.name}` +
(type.isOneOf ? ' @oneOf' : '') +
printBlock(fields)
);
}

@@ -220,0 +225,0 @@

@@ -148,2 +148,14 @@ 'use strict';

if (type.isOneOf) {
const keys = Object.keys(coercedObj);
if (keys.length !== 1) {
return; // Invalid: not exactly one key, intentionally return no value.
}
if (coercedObj[keys[0]] === null) {
return; // Invalid: value not non-null, intentionally return no value.
}
}
return coercedObj;

@@ -150,0 +162,0 @@ }

export { validate } from './validate';
export { ValidationContext } from './ValidationContext';
export type { ValidationRule } from './ValidationContext';
export { specifiedRules } from './specifiedRules';
export { specifiedRules, recommendedRules } from './specifiedRules';
export { ExecutableDefinitionsRule } from './rules/ExecutableDefinitionsRule';

@@ -31,2 +31,3 @@ export { FieldsOnCorrectTypeRule } from './rules/FieldsOnCorrectTypeRule';

export { VariablesInAllowedPositionRule } from './rules/VariablesInAllowedPositionRule';
export { MaxIntrospectionDepthRule } from './rules/MaxIntrospectionDepthRule';
export { LoneSchemaDefinitionRule } from './rules/LoneSchemaDefinitionRule';

@@ -33,0 +34,0 @@ export { UniqueOperationTypesRule } from './rules/UniqueOperationTypesRule';

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

});
Object.defineProperty(exports, 'MaxIntrospectionDepthRule', {
enumerable: true,
get: function () {
return _MaxIntrospectionDepthRule.MaxIntrospectionDepthRule;
},
});
Object.defineProperty(exports, 'NoDeprecatedCustomRule', {

@@ -229,2 +235,8 @@ enumerable: true,

});
Object.defineProperty(exports, 'recommendedRules', {
enumerable: true,
get: function () {
return _specifiedRules.recommendedRules;
},
});
Object.defineProperty(exports, 'specifiedRules', {

@@ -301,2 +313,4 @@ enumerable: true,

var _MaxIntrospectionDepthRule = require('./rules/MaxIntrospectionDepthRule.js');
var _LoneSchemaDefinitionRule = require('./rules/LoneSchemaDefinitionRule.js');

@@ -303,0 +317,0 @@

@@ -18,2 +18,4 @@ 'use strict';

var _kinds = require('../../language/kinds.js');
var _printer = require('../../language/printer.js');

@@ -32,3 +34,14 @@

function ValuesOfCorrectTypeRule(context) {
let variableDefinitions = {};
return {
OperationDefinition: {
enter() {
variableDefinitions = {};
},
},
VariableDefinition(definition) {
variableDefinitions[definition.variable.name.value] = definition;
},
ListValue(node) {

@@ -75,2 +88,12 @@ // Note: TypeInfo will traverse into a list's item type, so look to the

}
if (type.isOneOf) {
validateOneOfInputObject(
context,
node,
type,
fieldNodeMap,
variableDefinitions,
);
}
},

@@ -196,1 +219,66 @@

}
function validateOneOfInputObject(
context,
node,
type,
fieldNodeMap,
variableDefinitions,
) {
var _fieldNodeMap$keys$;
const keys = Object.keys(fieldNodeMap);
const isNotExactlyOneField = keys.length !== 1;
if (isNotExactlyOneField) {
context.reportError(
new _GraphQLError.GraphQLError(
`OneOf Input Object "${type.name}" must specify exactly one key.`,
{
nodes: [node],
},
),
);
return;
}
const value =
(_fieldNodeMap$keys$ = fieldNodeMap[keys[0]]) === null ||
_fieldNodeMap$keys$ === void 0
? void 0
: _fieldNodeMap$keys$.value;
const isNullLiteral = !value || value.kind === _kinds.Kind.NULL;
const isVariable =
(value === null || value === void 0 ? void 0 : value.kind) ===
_kinds.Kind.VARIABLE;
if (isNullLiteral) {
context.reportError(
new _GraphQLError.GraphQLError(
`Field "${type.name}.${keys[0]}" must be non-null.`,
{
nodes: [node],
},
),
);
return;
}
if (isVariable) {
const variableName = value.name.value;
const definition = variableDefinitions[variableName];
const isNullableVariable =
definition.type.kind !== _kinds.Kind.NON_NULL_TYPE;
if (isNullableVariable) {
context.reportError(
new _GraphQLError.GraphQLError(
`Variable "${variableName}" must be non-nullable to be used for OneOf Input Object "${type.name}".`,
{
nodes: [node],
},
),
);
}
}
}

@@ -0,3 +1,9 @@

import { MaxIntrospectionDepthRule } from './rules/MaxIntrospectionDepthRule';
import type { SDLValidationRule, ValidationRule } from './ValidationContext';
/**
* Technically these aren't part of the spec but they are strongly encouraged
* validation rules.
*/
export declare const recommendedRules: readonly typeof MaxIntrospectionDepthRule[];
/**
* This set includes all validation rules defined by the GraphQL spec.

@@ -4,0 +10,0 @@ *

@@ -6,3 +6,6 @@ 'use strict';

});
exports.specifiedSDLRules = exports.specifiedRules = void 0;
exports.specifiedSDLRules =
exports.specifiedRules =
exports.recommendedRules =
void 0;

@@ -27,2 +30,4 @@ var _ExecutableDefinitionsRule = require('./rules/ExecutableDefinitionsRule.js');

var _MaxIntrospectionDepthRule = require('./rules/MaxIntrospectionDepthRule.js');
var _NoFragmentCyclesRule = require('./rules/NoFragmentCyclesRule.js');

@@ -87,2 +92,3 @@

// SDL-specific validation rules
// TODO: Spec Section
// Spec Section: "Fragments must not form cycles"

@@ -108,2 +114,9 @@ // Spec Section: "All Variable Used Defined"

/**
* Technically these aren't part of the spec but they are strongly encouraged
* validation rules.
*/
const recommendedRules = Object.freeze([
_MaxIntrospectionDepthRule.MaxIntrospectionDepthRule,
]);
/**
* This set includes all validation rules defined by the GraphQL spec.

@@ -114,2 +127,4 @@ *

*/
exports.recommendedRules = recommendedRules;
const specifiedRules = Object.freeze([

@@ -142,2 +157,3 @@ _ExecutableDefinitionsRule.ExecutableDefinitionsRule,

_UniqueInputFieldNamesRule.UniqueInputFieldNamesRule,
...recommendedRules,
]);

@@ -144,0 +160,0 @@ /**

@@ -13,3 +13,3 @@ 'use strict';

*/
const version = '16.8.2';
const version = '16.9.0';
/**

@@ -22,6 +22,6 @@ * An object containing the components of the GraphQL.js version string

major: 16,
minor: 8,
patch: 2,
minor: 9,
patch: 0,
preReleaseTag: null,
});
exports.versionInfo = versionInfo;

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

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc