graphql-validate-fixtures
Advanced tools
Comparing version 0.5.2 to 0.6.0
@@ -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", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45729
406