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

graphql-validate-fixtures

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-validate-fixtures - npm Package Compare versions

Comparing version 0.5.2 to 0.6.0

25

lib/validate.js

@@ -33,13 +33,22 @@ "use strict";

function objectTypeHasFieldWithName(type, name) {
return type.getFields().hasOwnProperty(name);
return type.getFields()[name] != null;
}
function normalizeOperationName(operationName) {
return operationName.replace(/(Query|Mutation|Subscription)$/i, '');
}
function validateFixtureAgainstAST(fixture, ast) {
const fixtureDirectoryName = path_1.basename(path_1.dirname(fixture.path));
const operationName = fixture.content[OPERATION_MARKER] || fixtureDirectoryName;
const operation = ast.operations[operationName];
const operationMarkerName = fixture.content[OPERATION_MARKER];
const operationName = operationMarkerName || fixtureDirectoryName;
const operation = ast.operations[normalizeOperationName(operationName)] || ast.operations[operationName];
if (operation == null) {
let lookedFor = `'${fixtureDirectoryName}' based on the fixture’s directory name`;
if (fixture.content[OPERATION_MARKER]) {
lookedFor += `, and '${fixture.content[OPERATION_MARKER]}' based on the '${OPERATION_MARKER}' key`;
let lookedFor = '';
if (operationMarkerName) {
const normalizedOperationMarkerName = normalizeOperationName(operationMarkerName);
lookedFor = `'${operationMarkerName}'${operationMarkerName === normalizedOperationMarkerName ? '' : ` and '${normalizedOperationMarkerName}'`} based on the '${OPERATION_MARKER}' key`;
}
else {
const normalizedDirectoryName = normalizeOperationName(fixtureDirectoryName);
lookedFor = `'${fixtureDirectoryName}'${fixtureDirectoryName === normalizedDirectoryName ? '' : ` and '${normalizedDirectoryName}'`} based on the fixture’s directory name`;
}
throw new Error([

@@ -58,3 +67,3 @@ `Could not find a matching operation (looked for ${lookedFor}).`,

operationType,
operationPath: filePath,
operationPath: filePath === 'GraphQL request' ? undefined : filePath,
validationErrors: fields.reduce((allErrors, field) => {

@@ -150,3 +159,3 @@ return allErrors.concat(validateValueAgainstFieldDescription(value[field.responseName], field, '', ast));

const fieldKeyPath = updateKeyPath(keyPath, key);
if (fields.hasOwnProperty(key)) {
if (fields[key] != null) {
return fieldErrors.concat(validateValueAgainstType(value[key], fields[key].type, fieldKeyPath, options));

@@ -153,0 +162,0 @@ }

{
"name": "graphql-validate-fixtures",
"description": "Validates JSON fixtures for GraphQL responses against the associated operations and schema",
"version": "0.5.2",
"version": "0.6.0",
"main": "lib/index.js",

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

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