From 3e069f5c5ac66295ad881e0b83c391f115a2bd48 Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Wed, 9 Nov 2016 13:08:45 -0800 Subject: [PATCH] Add path to formatError While path was added to the serializable error, it was not yet added to the default formatError function. Adding this is technically breaking since it begins to expose new information from your API. --- src/error/__tests__/GraphQLError-test.js | 18 ++++- src/error/formatError.js | 6 +- src/execution/__tests__/executor-test.js | 33 ++++++--- src/execution/__tests__/lists-test.js | 57 ++++++++++----- .../__tests__/ArgumentsOfCorrectType-test.js | 1 + .../DefaultValuesOfCorrectType-test.js | 2 + .../__tests__/FieldsOnCorrectType-test.js | 1 + .../FragmentsOnCompositeTypes-test.js | 4 +- .../__tests__/KnownArgumentNames-test.js | 2 + .../__tests__/KnownDirectives-test.js | 6 +- .../__tests__/KnownFragmentNames-test.js | 3 +- .../__tests__/KnownTypeNames-test.js | 1 + .../__tests__/LoneAnonymousOperation-test.js | 1 + .../__tests__/NoFragmentCycles-test.js | 45 ++++++++---- .../__tests__/NoUndefinedVariables-test.js | 1 + .../__tests__/NoUnusedFragments-test.js | 1 + .../__tests__/NoUnusedVariables-test.js | 1 + .../OverlappingFieldsCanBeMerged-test.js | 72 ++++++++++++------- .../__tests__/PossibleFragmentSpreads-test.js | 2 + .../ProvidedNonNullArguments-test.js | 2 + src/validation/__tests__/ScalarLeafs-test.js | 2 + .../__tests__/UniqueArgumentNames-test.js | 1 + .../UniqueDirectivesPerLocation-test.js | 1 + .../__tests__/UniqueFragmentNames-test.js | 1 + .../__tests__/UniqueInputFieldNames-test.js | 1 + .../__tests__/UniqueOperationNames-test.js | 1 + .../__tests__/UniqueVariableNames-test.js | 1 + .../__tests__/VariablesAreInputTypes-test.js | 9 ++- .../VariablesInAllowedPosition-test.js | 21 ++++-- 29 files changed, 211 insertions(+), 86 deletions(-) diff --git a/src/error/__tests__/GraphQLError-test.js b/src/error/__tests__/GraphQLError-test.js index 4ccd166fee..c9acb6cdf3 100644 --- a/src/error/__tests__/GraphQLError-test.js +++ b/src/error/__tests__/GraphQLError-test.js @@ -10,7 +10,7 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; -import { parse, Source, GraphQLError } from '../../'; +import { parse, Source, GraphQLError, formatError } from '../../'; describe('GraphQLError', () => { @@ -123,4 +123,20 @@ describe('GraphQLError', () => { ); }); + it('default error formatter includes path', () => { + const e = new GraphQLError( + 'msg', + null, + null, + null, + [ 'path', 3, 'to', 'field' ] + ); + + expect(formatError(e)).to.deep.equal({ + message: 'msg', + locations: undefined, + path: [ 'path', 3, 'to', 'field' ] + }); + }); + }); diff --git a/src/error/formatError.js b/src/error/formatError.js index 320afcf60f..e776075bd6 100644 --- a/src/error/formatError.js +++ b/src/error/formatError.js @@ -20,13 +20,15 @@ export function formatError(error: GraphQLError): GraphQLFormattedError { invariant(error, 'Received null or undefined error.'); return { message: error.message, - locations: error.locations + locations: error.locations, + path: error.path }; } export type GraphQLFormattedError = { message: string, - locations: ?Array + locations: ?Array, + path: ?Array }; export type GraphQLErrorLocation = { diff --git a/src/execution/__tests__/executor-test.js b/src/execution/__tests__/executor-test.js index 797a4f3e8b..176360b83b 100644 --- a/src/execution/__tests__/executor-test.js +++ b/src/execution/__tests__/executor-test.js @@ -403,27 +403,38 @@ describe('Execute: Handles basic execution tasks', () => { expect(result.errors && result.errors.map(formatError)).to.deep.equal([ { message: 'Error getting syncError', - locations: [ { line: 3, column: 7 } ] }, + locations: [ { line: 3, column: 7 } ], + path: [ 'syncError' ] }, { message: 'Error getting syncRawError', - locations: [ { line: 4, column: 7 } ] }, + locations: [ { line: 4, column: 7 } ], + path: [ 'syncRawError' ] }, { message: 'Error getting syncReturnError', - locations: [ { line: 5, column: 7 } ] }, + locations: [ { line: 5, column: 7 } ], + path: [ 'syncReturnError' ] }, { message: 'Error getting syncReturnErrorList1', - locations: [ { line: 6, column: 7 } ] }, + locations: [ { line: 6, column: 7 } ], + path: [ 'syncReturnErrorList', 1 ] }, { message: 'Error getting syncReturnErrorList3', - locations: [ { line: 6, column: 7 } ] }, + locations: [ { line: 6, column: 7 } ], + path: [ 'syncReturnErrorList', 3 ] }, { message: 'Error getting asyncReject', - locations: [ { line: 8, column: 7 } ] }, + locations: [ { line: 8, column: 7 } ], + path: [ 'asyncReject' ] }, { message: 'Error getting asyncRawReject', - locations: [ { line: 9, column: 7 } ] }, + locations: [ { line: 9, column: 7 } ], + path: [ 'asyncRawReject' ] }, { message: 'An unknown error occurred.', - locations: [ { line: 10, column: 7 } ] }, + locations: [ { line: 10, column: 7 } ], + path: [ 'asyncEmptyReject' ] }, { message: 'Error getting asyncError', - locations: [ { line: 11, column: 7 } ] }, + locations: [ { line: 11, column: 7 } ], + path: [ 'asyncError' ] }, { message: 'Error getting asyncRawError', - locations: [ { line: 12, column: 7 } ] }, + locations: [ { line: 12, column: 7 } ], + path: [ 'asyncRawError' ] }, { message: 'Error getting asyncReturnError', - locations: [ { line: 13, column: 7 } ] }, + locations: [ { line: 13, column: 7 } ], + path: [ 'asyncReturnError' ] }, ]); }); diff --git a/src/execution/__tests__/lists-test.js b/src/execution/__tests__/lists-test.js index 60f8762879..6985015f94 100644 --- a/src/execution/__tests__/lists-test.js +++ b/src/execution/__tests__/lists-test.js @@ -104,7 +104,8 @@ describe('Execute: Accepts any iterable as list value', () => { { data: { nest: { test: null } }, errors: [ { message: 'Expected Iterable, but did not find one for field DataType.test.', - locations: [ { line: 1, column: 10 } ] + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test' ] } ] } )); @@ -157,7 +158,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: { test: null } }, errors: [ { message: 'bad', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test' ] } ] } )); @@ -180,7 +182,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: { test: [ 1, null, 2 ] } }, errors: [ { message: 'bad', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test', 1 ] } ] } )); @@ -208,7 +211,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: null }, errors: [ { message: 'Cannot return null for non-nullable field DataType.test.', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test' ] } ] } )); @@ -231,7 +235,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: null }, errors: [ { message: 'Cannot return null for non-nullable field DataType.test.', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test' ] } ] } )); @@ -240,7 +245,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: null }, errors: [ { message: 'bad', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test' ] } ] } )); @@ -263,7 +269,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: { test: [ 1, null, 2 ] } }, errors: [ { message: 'bad', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test', 1 ] } ] } )); @@ -286,7 +293,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: { test: null } }, errors: [ { message: 'Cannot return null for non-nullable field DataType.test.', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test', 1 ] } ] } )); @@ -309,7 +317,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: { test: null } }, errors: [ { message: 'Cannot return null for non-nullable field DataType.test.', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test', 1 ] } ] } )); @@ -323,7 +332,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: { test: null } }, errors: [ { message: 'bad', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test' ] } ] } )); @@ -341,7 +351,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: { test: null } }, errors: [ { message: 'Cannot return null for non-nullable field DataType.test.', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test', 1 ] } ] } )); @@ -350,7 +361,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: { test: null } }, errors: [ { message: 'bad', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test', 1 ] } ] } )); @@ -375,7 +387,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: null }, errors: [ { message: 'Cannot return null for non-nullable field DataType.test.', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test', 1 ] } ] } )); @@ -384,7 +397,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: null }, errors: [ { message: 'Cannot return null for non-nullable field DataType.test.', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test' ] } ] } )); @@ -402,7 +416,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: null }, errors: [ { message: 'Cannot return null for non-nullable field DataType.test.', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test', 1 ] } ] } )); @@ -411,7 +426,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: null }, errors: [ { message: 'Cannot return null for non-nullable field DataType.test.', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test' ] } ] } )); @@ -420,7 +436,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: null }, errors: [ { message: 'bad', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test' ] } ] } )); @@ -438,7 +455,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: null }, errors: [ { message: 'Cannot return null for non-nullable field DataType.test.', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test', 1 ] } ] } )); @@ -447,7 +465,8 @@ describe('Execute: Handles list nullability', () => { { data: { nest: null }, errors: [ { message: 'bad', - locations: [ { line: 1, column: 10 } ] } + locations: [ { line: 1, column: 10 } ], + path: [ 'nest', 'test', 1 ] } ] } )); diff --git a/src/validation/__tests__/ArgumentsOfCorrectType-test.js b/src/validation/__tests__/ArgumentsOfCorrectType-test.js index 3636c63683..18e7086607 100644 --- a/src/validation/__tests__/ArgumentsOfCorrectType-test.js +++ b/src/validation/__tests__/ArgumentsOfCorrectType-test.js @@ -27,6 +27,7 @@ function badValue(argName, typeName, value, line, column, errors) { return { message: badValueMessage(argName, typeName, value, realErrors), locations: [ { line, column } ], + path: undefined, }; } diff --git a/src/validation/__tests__/DefaultValuesOfCorrectType-test.js b/src/validation/__tests__/DefaultValuesOfCorrectType-test.js index e9872d172d..7b0f166f15 100644 --- a/src/validation/__tests__/DefaultValuesOfCorrectType-test.js +++ b/src/validation/__tests__/DefaultValuesOfCorrectType-test.js @@ -20,6 +20,7 @@ function defaultForNonNullArg(varName, typeName, guessTypeName, line, column) { return { message: defaultForNonNullArgMessage(varName, typeName, guessTypeName), locations: [ { line, column } ], + path: undefined, }; } @@ -35,6 +36,7 @@ function badValue(varName, typeName, val, line, column, errors) { return { message: badValueForDefaultArgMessage(varName, typeName, val, realErrors), locations: [ { line, column } ], + path: undefined, }; } diff --git a/src/validation/__tests__/FieldsOnCorrectType-test.js b/src/validation/__tests__/FieldsOnCorrectType-test.js index 6769caa267..1a52a57885 100644 --- a/src/validation/__tests__/FieldsOnCorrectType-test.js +++ b/src/validation/__tests__/FieldsOnCorrectType-test.js @@ -32,6 +32,7 @@ function undefinedField( suggestedFields ), locations: [ { line, column } ], + path: undefined, }; } diff --git a/src/validation/__tests__/FragmentsOnCompositeTypes-test.js b/src/validation/__tests__/FragmentsOnCompositeTypes-test.js index 05e894d74a..2498de0166 100644 --- a/src/validation/__tests__/FragmentsOnCompositeTypes-test.js +++ b/src/validation/__tests__/FragmentsOnCompositeTypes-test.js @@ -19,6 +19,7 @@ function error(fragName, typeName, line, column) { return { message: fragmentOnNonCompositeErrorMessage(fragName, typeName), locations: [ { line, column } ], + path: undefined, }; } @@ -101,7 +102,8 @@ describe('Validate: Fragments on composite types', () => { } `, [ { message: inlineFragmentOnNonCompositeErrorMessage('String'), - locations: [ { line: 3, column: 16 } ] } + locations: [ { line: 3, column: 16 } ], + path: undefined } ]); }); diff --git a/src/validation/__tests__/KnownArgumentNames-test.js b/src/validation/__tests__/KnownArgumentNames-test.js index eeae9cef1f..0b5a082911 100644 --- a/src/validation/__tests__/KnownArgumentNames-test.js +++ b/src/validation/__tests__/KnownArgumentNames-test.js @@ -20,6 +20,7 @@ function unknownArg(argName, fieldName, typeName, suggestedArgs, line, column) { return { message: unknownArgMessage(argName, fieldName, typeName, suggestedArgs), locations: [ { line, column } ], + path: undefined, }; } @@ -33,6 +34,7 @@ function unknownDirectiveArg( return { message: unknownDirectiveArgMessage(argName, directiveName, suggestedArgs), locations: [ { line, column } ], + path: undefined, }; } diff --git a/src/validation/__tests__/KnownDirectives-test.js b/src/validation/__tests__/KnownDirectives-test.js index 179bf4dc29..992760632d 100644 --- a/src/validation/__tests__/KnownDirectives-test.js +++ b/src/validation/__tests__/KnownDirectives-test.js @@ -22,14 +22,16 @@ import { function unknownDirective(directiveName, line, column) { return { message: unknownDirectiveMessage(directiveName), - locations: [ { line, column } ] + locations: [ { line, column } ], + path: undefined, }; } function misplacedDirective(directiveName, placement, line, column) { return { message: misplacedDirectiveMessage(directiveName, placement), - locations: [ { line, column } ] + locations: [ { line, column } ], + path: undefined, }; } diff --git a/src/validation/__tests__/KnownFragmentNames-test.js b/src/validation/__tests__/KnownFragmentNames-test.js index a05016f64f..f823827466 100644 --- a/src/validation/__tests__/KnownFragmentNames-test.js +++ b/src/validation/__tests__/KnownFragmentNames-test.js @@ -18,7 +18,8 @@ import { function undefFrag(fragName, line, column) { return { message: unknownFragmentMessage(fragName), - locations: [ { line, column } ] + locations: [ { line, column } ], + path: undefined, }; } diff --git a/src/validation/__tests__/KnownTypeNames-test.js b/src/validation/__tests__/KnownTypeNames-test.js index eca4a0424c..d10ba6d50c 100644 --- a/src/validation/__tests__/KnownTypeNames-test.js +++ b/src/validation/__tests__/KnownTypeNames-test.js @@ -19,6 +19,7 @@ function unknownType(typeName, suggestedTypes, line, column) { return { message: unknownTypeMessage(typeName, suggestedTypes), locations: [ { line, column } ], + path: undefined, }; } diff --git a/src/validation/__tests__/LoneAnonymousOperation-test.js b/src/validation/__tests__/LoneAnonymousOperation-test.js index 9f66c721f0..7d740a31d1 100644 --- a/src/validation/__tests__/LoneAnonymousOperation-test.js +++ b/src/validation/__tests__/LoneAnonymousOperation-test.js @@ -19,6 +19,7 @@ function anonNotAlone(line, column) { return { message: anonOperationNotAloneMessage(), locations: [ { line, column } ], + path: undefined, }; } diff --git a/src/validation/__tests__/NoFragmentCycles-test.js b/src/validation/__tests__/NoFragmentCycles-test.js index 13e80615d2..ce12a82c2a 100644 --- a/src/validation/__tests__/NoFragmentCycles-test.js +++ b/src/validation/__tests__/NoFragmentCycles-test.js @@ -63,7 +63,8 @@ describe('Validate: No circular fragment spreads', () => { fragment fragA on Human { relatives { ...fragA } }, `, [ { message: cycleErrorMessage('fragA', []), - locations: [ { line: 2, column: 45 } ] } + locations: [ { line: 2, column: 45 } ], + path: undefined } ]); }); @@ -72,7 +73,8 @@ describe('Validate: No circular fragment spreads', () => { fragment fragA on Dog { ...fragA } `, [ { message: cycleErrorMessage('fragA', []), - locations: [ { line: 2, column: 31 } ] } + locations: [ { line: 2, column: 31 } ], + path: undefined } ]); }); @@ -85,7 +87,8 @@ describe('Validate: No circular fragment spreads', () => { } `, [ { message: cycleErrorMessage('fragA', []), - locations: [ { line: 4, column: 11 } ] } + locations: [ { line: 4, column: 11 } ], + path: undefined } ]); }); @@ -95,7 +98,8 @@ describe('Validate: No circular fragment spreads', () => { fragment fragB on Dog { ...fragA } `, [ { message: cycleErrorMessage('fragA', [ 'fragB' ]), - locations: [ { line: 2, column: 31 }, { line: 3, column: 31 } ] } + locations: [ { line: 2, column: 31 }, { line: 3, column: 31 } ], + path: undefined } ]); }); @@ -105,7 +109,8 @@ describe('Validate: No circular fragment spreads', () => { fragment fragA on Dog { ...fragB } `, [ { message: cycleErrorMessage('fragB', [ 'fragA' ]), - locations: [ { line: 2, column: 31 }, { line: 3, column: 31 } ] } + locations: [ { line: 2, column: 31 }, { line: 3, column: 31 } ], + path: undefined } ]); }); @@ -124,7 +129,8 @@ describe('Validate: No circular fragment spreads', () => { } `, [ { message: cycleErrorMessage('fragA', [ 'fragB' ]), - locations: [ { line: 4, column: 11 }, { line: 9, column: 11 } ] } + locations: [ { line: 4, column: 11 }, { line: 9, column: 11 } ], + path: undefined } ]); }); @@ -146,7 +152,8 @@ describe('Validate: No circular fragment spreads', () => { { line: 3, column: 31 }, { line: 4, column: 31 }, { line: 8, column: 31 }, - { line: 9, column: 31 } ] }, + { line: 9, column: 31 } ], + path: undefined }, { message: cycleErrorMessage('fragO', [ 'fragP', 'fragX', 'fragY', 'fragZ' ]), locations: [ @@ -154,7 +161,8 @@ describe('Validate: No circular fragment spreads', () => { { line: 9, column: 41 }, { line: 5, column: 31 }, { line: 6, column: 31 }, - { line: 7, column: 31 } ] } + { line: 7, column: 31 } ], + path: undefined } ]); }); @@ -165,9 +173,11 @@ describe('Validate: No circular fragment spreads', () => { fragment fragC on Dog { ...fragA } `, [ { message: cycleErrorMessage('fragA', [ 'fragB' ]), - locations: [ { line: 2, column: 31 }, { line: 3, column: 31 } ] }, + locations: [ { line: 2, column: 31 }, { line: 3, column: 31 } ], + path: undefined }, { message: cycleErrorMessage('fragA', [ 'fragC' ]), - locations: [ { line: 2, column: 41 }, { line: 4, column: 31 } ] } + locations: [ { line: 2, column: 41 }, { line: 4, column: 31 } ], + path: undefined } ]); }); @@ -178,9 +188,11 @@ describe('Validate: No circular fragment spreads', () => { fragment fragC on Dog { ...fragA, ...fragB } `, [ { message: cycleErrorMessage('fragA', [ 'fragC' ]), - locations: [ { line: 2, column: 31 }, { line: 4, column: 31 } ] }, + locations: [ { line: 2, column: 31 }, { line: 4, column: 31 } ], + path: undefined }, { message: cycleErrorMessage('fragC', [ 'fragB' ]), - locations: [ { line: 4, column: 41 }, { line: 3, column: 31 } ] } + locations: [ { line: 4, column: 41 }, { line: 3, column: 31 } ], + path: undefined } ]); }); @@ -191,14 +203,17 @@ describe('Validate: No circular fragment spreads', () => { fragment fragC on Dog { ...fragA, ...fragB } `, [ { message: cycleErrorMessage('fragB', []), - locations: [ { line: 3, column: 31 } ] }, + locations: [ { line: 3, column: 31 } ], + path: undefined }, { message: cycleErrorMessage('fragA', [ 'fragB', 'fragC' ]), locations: [ { line: 2, column: 31 }, { line: 3, column: 41 }, - { line: 4, column: 31 } ] }, + { line: 4, column: 31 } ], + path: undefined }, { message: cycleErrorMessage('fragB', [ 'fragC' ]), - locations: [ { line: 3, column: 41 }, { line: 4, column: 41 } ] } + locations: [ { line: 3, column: 41 }, { line: 4, column: 41 } ], + path: undefined } ]); }); diff --git a/src/validation/__tests__/NoUndefinedVariables-test.js b/src/validation/__tests__/NoUndefinedVariables-test.js index 9ebf5a0594..dae6982823 100644 --- a/src/validation/__tests__/NoUndefinedVariables-test.js +++ b/src/validation/__tests__/NoUndefinedVariables-test.js @@ -19,6 +19,7 @@ function undefVar(varName, l1, c1, opName, l2, c2) { return { message: undefinedVarMessage(varName, opName), locations: [ { line: l1, column: c1 }, { line: l2, column: c2 } ], + path: undefined, }; } diff --git a/src/validation/__tests__/NoUnusedFragments-test.js b/src/validation/__tests__/NoUnusedFragments-test.js index 6e3717623a..4b932871d6 100644 --- a/src/validation/__tests__/NoUnusedFragments-test.js +++ b/src/validation/__tests__/NoUnusedFragments-test.js @@ -19,6 +19,7 @@ function unusedFrag(fragName, line, column) { return { message: unusedFragMessage(fragName), locations: [ { line, column } ], + path: undefined, }; } diff --git a/src/validation/__tests__/NoUnusedVariables-test.js b/src/validation/__tests__/NoUnusedVariables-test.js index 424f3bfec5..1a959887f8 100644 --- a/src/validation/__tests__/NoUnusedVariables-test.js +++ b/src/validation/__tests__/NoUnusedVariables-test.js @@ -19,6 +19,7 @@ function unusedVar(varName, opName, line, column) { return { message: unusedVariableMessage(varName, opName), locations: [ { line, column } ], + path: undefined, }; } diff --git a/src/validation/__tests__/OverlappingFieldsCanBeMerged-test.js b/src/validation/__tests__/OverlappingFieldsCanBeMerged-test.js index 3da107a50d..ecbb3f9a1d 100644 --- a/src/validation/__tests__/OverlappingFieldsCanBeMerged-test.js +++ b/src/validation/__tests__/OverlappingFieldsCanBeMerged-test.js @@ -109,7 +109,8 @@ describe('Validate: Overlapping fields can be merged', () => { 'fido', 'name and nickname are different fields' ), - locations: [ { line: 3, column: 9 }, { line: 4, column: 9 } ] }, + locations: [ { line: 3, column: 9 }, { line: 4, column: 9 } ], + path: undefined } ]); }); @@ -139,7 +140,8 @@ describe('Validate: Overlapping fields can be merged', () => { 'name', 'nickname and name are different fields' ), - locations: [ { line: 3, column: 9 }, { line: 4, column: 9 } ] }, + locations: [ { line: 3, column: 9 }, { line: 4, column: 9 } ], + path: undefined } ]); }); @@ -154,7 +156,8 @@ describe('Validate: Overlapping fields can be merged', () => { 'doesKnowCommand', 'they have differing arguments' ), - locations: [ { line: 3, column: 9 }, { line: 4, column: 9 } ] } + locations: [ { line: 3, column: 9 }, { line: 4, column: 9 } ], + path: undefined } ]); }); @@ -169,7 +172,8 @@ describe('Validate: Overlapping fields can be merged', () => { 'doesKnowCommand', 'they have differing arguments' ), - locations: [ { line: 3, column: 9 }, { line: 4, column: 9 } ] } + locations: [ { line: 3, column: 9 }, { line: 4, column: 9 } ], + path: undefined } ]); }); @@ -184,7 +188,8 @@ describe('Validate: Overlapping fields can be merged', () => { 'doesKnowCommand', 'they have differing arguments' ), - locations: [ { line: 3, column: 9 }, { line: 4, column: 9 } ] } + locations: [ { line: 3, column: 9 }, { line: 4, column: 9 } ], + path: undefined } ]); }); @@ -217,7 +222,8 @@ describe('Validate: Overlapping fields can be merged', () => { } `, [ { message: fieldsConflictMessage('x', 'a and b are different fields'), - locations: [ { line: 7, column: 9 }, { line: 10, column: 9 } ] } + locations: [ { line: 7, column: 9 }, { line: 10, column: 9 } ], + path: undefined } ]); }); @@ -246,11 +252,14 @@ describe('Validate: Overlapping fields can be merged', () => { } `, [ { message: fieldsConflictMessage('x', 'a and b are different fields'), - locations: [ { line: 18, column: 9 }, { line: 21, column: 9 } ] }, + locations: [ { line: 18, column: 9 }, { line: 21, column: 9 } ], + path: undefined }, { message: fieldsConflictMessage('x', 'c and a are different fields'), - locations: [ { line: 14, column: 11 }, { line: 18, column: 9 } ] }, + locations: [ { line: 14, column: 11 }, { line: 18, column: 9 } ], + path: undefined }, { message: fieldsConflictMessage('x', 'c and b are different fields'), - locations: [ { line: 14, column: 11 }, { line: 21, column: 9 } ] } + locations: [ { line: 14, column: 11 }, { line: 21, column: 9 } ], + path: undefined } ]); }); @@ -272,7 +281,8 @@ describe('Validate: Overlapping fields can be merged', () => { { line: 3, column: 9 }, { line: 4, column: 11 }, { line: 6, column: 9 }, - { line: 7, column: 11 } ] }, + { line: 7, column: 11 } ], + path: undefined }, ]); }); @@ -301,7 +311,8 @@ describe('Validate: Overlapping fields can be merged', () => { { line: 5, column: 11 }, { line: 7, column: 9 }, { line: 8, column: 11 }, - { line: 9, column: 11 } ] }, + { line: 9, column: 11 } ], + path: undefined }, ]); }); @@ -330,7 +341,8 @@ describe('Validate: Overlapping fields can be merged', () => { { line: 5, column: 13 }, { line: 8, column: 9 }, { line: 9, column: 11 }, - { line: 10, column: 13 } ] }, + { line: 10, column: 13 } ], + path: undefined }, ]); }); @@ -359,7 +371,8 @@ describe('Validate: Overlapping fields can be merged', () => { { line: 4, column: 11 }, { line: 5, column: 13 }, { line: 7, column: 11 }, - { line: 8, column: 13 } ] }, + { line: 8, column: 13 } ], + path: undefined }, ]); }); @@ -396,7 +409,8 @@ describe('Validate: Overlapping fields can be merged', () => { { line: 12, column: 11 }, { line: 13, column: 13 }, { line: 15, column: 11 }, - { line: 16, column: 13 } ] }, + { line: 16, column: 13 } ], + path: undefined }, ]); }); @@ -435,7 +449,8 @@ describe('Validate: Overlapping fields can be merged', () => { { line: 15, column: 9 }, { line: 6, column: 9 }, { line: 22, column: 9 }, - { line: 18, column: 9 } ] }, + { line: 18, column: 9 } ], + path: undefined }, ]); }); @@ -581,7 +596,8 @@ describe('Validate: Overlapping fields can be merged', () => { 'scalar', 'they return conflicting types Int and String!' ), - locations: [ { line: 5, column: 15 }, { line: 8, column: 15 } ] } + locations: [ { line: 5, column: 15 }, { line: 8, column: 15 } ], + path: undefined } ]); }); @@ -624,7 +640,8 @@ describe('Validate: Overlapping fields can be merged', () => { 'scalar', 'they return conflicting types Int and String' ), - locations: [ { line: 5, column: 15 }, { line: 8, column: 15 } ] } + locations: [ { line: 5, column: 15 }, { line: 8, column: 15 } ], + path: undefined } ]); }); @@ -682,7 +699,8 @@ describe('Validate: Overlapping fields can be merged', () => { { line: 39, column: 11 }, { line: 34, column: 11 }, { line: 42, column: 11 }, - ] } + ], + path: undefined } ]); }); @@ -703,7 +721,8 @@ describe('Validate: Overlapping fields can be merged', () => { 'scalar', 'they return conflicting types String! and String' ), - locations: [ { line: 5, column: 15 }, { line: 8, column: 15 } ] } + locations: [ { line: 5, column: 15 }, { line: 8, column: 15 } ], + path: undefined } ]); }); @@ -728,7 +747,8 @@ describe('Validate: Overlapping fields can be merged', () => { 'box', 'they return conflicting types [StringBox] and StringBox' ), - locations: [ { line: 5, column: 15 }, { line: 10, column: 15 } ] } + locations: [ { line: 5, column: 15 }, { line: 10, column: 15 } ], + path: undefined } ]); expectFailsRuleWithSchema(schema, OverlappingFieldsCanBeMerged, ` @@ -751,7 +771,8 @@ describe('Validate: Overlapping fields can be merged', () => { 'box', 'they return conflicting types StringBox and [StringBox]' ), - locations: [ { line: 5, column: 15 }, { line: 10, column: 15 } ] } + locations: [ { line: 5, column: 15 }, { line: 10, column: 15 } ], + path: undefined } ]); }); @@ -777,7 +798,8 @@ describe('Validate: Overlapping fields can be merged', () => { 'val', 'scalar and unrelatedField are different fields' ), - locations: [ { line: 6, column: 17 }, { line: 7, column: 17 } ] } + locations: [ { line: 6, column: 17 }, { line: 7, column: 17 } ], + path: undefined } ]); }); @@ -806,7 +828,8 @@ describe('Validate: Overlapping fields can be merged', () => { { line: 5, column: 15 }, { line: 6, column: 17 }, { line: 10, column: 15 }, - { line: 11, column: 17 } ] } + { line: 11, column: 17 } ], + path: undefined } ]); }); @@ -883,7 +906,8 @@ describe('Validate: Overlapping fields can be merged', () => { { line: 14, column: 11 }, { line: 15, column: 13 }, { line: 16, column: 15 }, - ] } + ], + path: undefined } ]); }); diff --git a/src/validation/__tests__/PossibleFragmentSpreads-test.js b/src/validation/__tests__/PossibleFragmentSpreads-test.js index 2ae10608c1..00c0f2f25c 100644 --- a/src/validation/__tests__/PossibleFragmentSpreads-test.js +++ b/src/validation/__tests__/PossibleFragmentSpreads-test.js @@ -20,6 +20,7 @@ function error(fragName, parentType, fragType, line, column) { return { message: typeIncompatibleSpreadMessage(fragName, parentType, fragType), locations: [ { line, column } ], + path: undefined, }; } @@ -27,6 +28,7 @@ function errorAnon(parentType, fragType, line, column) { return { message: typeIncompatibleAnonSpreadMessage(parentType, fragType), locations: [ { line, column } ], + path: undefined, }; } diff --git a/src/validation/__tests__/ProvidedNonNullArguments-test.js b/src/validation/__tests__/ProvidedNonNullArguments-test.js index 8c4ed83f3b..7fa432d3f4 100644 --- a/src/validation/__tests__/ProvidedNonNullArguments-test.js +++ b/src/validation/__tests__/ProvidedNonNullArguments-test.js @@ -20,6 +20,7 @@ function missingFieldArg(fieldName, argName, typeName, line, column) { return { message: missingFieldArgMessage(fieldName, argName, typeName), locations: [ { line, column } ], + path: undefined, }; } @@ -27,6 +28,7 @@ function missingDirectiveArg(directiveName, argName, typeName, line, column) { return { message: missingDirectiveArgMessage(directiveName, argName, typeName), locations: [ { line, column } ], + path: undefined, }; } diff --git a/src/validation/__tests__/ScalarLeafs-test.js b/src/validation/__tests__/ScalarLeafs-test.js index e3fe768f75..cfa0c19417 100644 --- a/src/validation/__tests__/ScalarLeafs-test.js +++ b/src/validation/__tests__/ScalarLeafs-test.js @@ -20,6 +20,7 @@ function noScalarSubselection(field, type, line, column) { return { message: noSubselectionAllowedMessage(field, type), locations: [ { line, column } ], + path: undefined, }; } @@ -27,6 +28,7 @@ function missingObjSubselection(field, type, line, column) { return { message: requiredSubselectionMessage(field, type), locations: [ { line, column } ], + path: undefined, }; } diff --git a/src/validation/__tests__/UniqueArgumentNames-test.js b/src/validation/__tests__/UniqueArgumentNames-test.js index 1fb7e9a9f3..e95d4db4af 100644 --- a/src/validation/__tests__/UniqueArgumentNames-test.js +++ b/src/validation/__tests__/UniqueArgumentNames-test.js @@ -19,6 +19,7 @@ function duplicateArg(argName, l1, c1, l2, c2) { return { message: duplicateArgMessage(argName), locations: [ { line: l1, column: c1 }, { line: l2, column: c2 } ], + path: undefined, }; } diff --git a/src/validation/__tests__/UniqueDirectivesPerLocation-test.js b/src/validation/__tests__/UniqueDirectivesPerLocation-test.js index dc1311d250..375e88c4fb 100644 --- a/src/validation/__tests__/UniqueDirectivesPerLocation-test.js +++ b/src/validation/__tests__/UniqueDirectivesPerLocation-test.js @@ -19,6 +19,7 @@ function duplicateDirective(directiveName, l1, c1, l2, c2) { return { message: duplicateDirectiveMessage(directiveName), locations: [ { line: l1, column: c1 }, { line: l2, column: c2 } ], + path: undefined, }; } diff --git a/src/validation/__tests__/UniqueFragmentNames-test.js b/src/validation/__tests__/UniqueFragmentNames-test.js index bb22472b6c..14a5e547c2 100644 --- a/src/validation/__tests__/UniqueFragmentNames-test.js +++ b/src/validation/__tests__/UniqueFragmentNames-test.js @@ -19,6 +19,7 @@ function duplicateFrag(fragName, l1, c1, l2, c2) { return { message: duplicateFragmentNameMessage(fragName), locations: [ { line: l1, column: c1 }, { line: l2, column: c2 } ], + path: undefined, }; } diff --git a/src/validation/__tests__/UniqueInputFieldNames-test.js b/src/validation/__tests__/UniqueInputFieldNames-test.js index 6ed4f535c0..7ab74b7052 100644 --- a/src/validation/__tests__/UniqueInputFieldNames-test.js +++ b/src/validation/__tests__/UniqueInputFieldNames-test.js @@ -19,6 +19,7 @@ function duplicateField(name, l1, c1, l2, c2) { return { message: duplicateInputFieldMessage(name), locations: [ { line: l1, column: c1 }, { line: l2, column: c2 } ], + path: undefined, }; } diff --git a/src/validation/__tests__/UniqueOperationNames-test.js b/src/validation/__tests__/UniqueOperationNames-test.js index 6a9a1a1c9f..2628d51b80 100644 --- a/src/validation/__tests__/UniqueOperationNames-test.js +++ b/src/validation/__tests__/UniqueOperationNames-test.js @@ -19,6 +19,7 @@ function duplicateOp(opName, l1, c1, l2, c2) { return { message: duplicateOperationNameMessage(opName), locations: [ { line: l1, column: c1 }, { line: l2, column: c2 } ], + path: undefined, }; } diff --git a/src/validation/__tests__/UniqueVariableNames-test.js b/src/validation/__tests__/UniqueVariableNames-test.js index f5b170b6c4..74e95fc4d7 100644 --- a/src/validation/__tests__/UniqueVariableNames-test.js +++ b/src/validation/__tests__/UniqueVariableNames-test.js @@ -19,6 +19,7 @@ function duplicateVariable(name, l1, c1, l2, c2) { return { message: duplicateVariableMessage(name), locations: [ { line: l1, column: c1 }, { line: l2, column: c2 } ], + path: undefined, }; } diff --git a/src/validation/__tests__/VariablesAreInputTypes-test.js b/src/validation/__tests__/VariablesAreInputTypes-test.js index a9acc99449..4f573b26d7 100644 --- a/src/validation/__tests__/VariablesAreInputTypes-test.js +++ b/src/validation/__tests__/VariablesAreInputTypes-test.js @@ -32,11 +32,14 @@ describe('Validate: Variables are input types', () => { } `, [ { locations: [ { line: 2, column: 21 } ], - message: nonInputTypeOnVarMessage('a', 'Dog') }, + message: nonInputTypeOnVarMessage('a', 'Dog'), + path: undefined }, { locations: [ { line: 2, column: 30 } ], - message: nonInputTypeOnVarMessage('b', '[[CatOrDog!]]!') }, + message: nonInputTypeOnVarMessage('b', '[[CatOrDog!]]!'), + path: undefined }, { locations: [ { line: 2, column: 50 } ], - message: nonInputTypeOnVarMessage('c', 'Pet') }, + message: nonInputTypeOnVarMessage('c', 'Pet'), + path: undefined }, ]); }); diff --git a/src/validation/__tests__/VariablesInAllowedPosition-test.js b/src/validation/__tests__/VariablesInAllowedPosition-test.js index d69047742d..bfd12ee2b2 100644 --- a/src/validation/__tests__/VariablesInAllowedPosition-test.js +++ b/src/validation/__tests__/VariablesInAllowedPosition-test.js @@ -184,7 +184,8 @@ describe('Validate: Variables are in allowed positions', () => { } `, [ { message: badVarPosMessage('intArg', 'Int', 'Int!'), - locations: [ { line: 2, column: 19 }, { line: 4, column: 45 } ] }, + locations: [ { line: 2, column: 19 }, { line: 4, column: 45 } ], + path: undefined } ]); }); @@ -201,7 +202,8 @@ describe('Validate: Variables are in allowed positions', () => { } `, [ { message: badVarPosMessage('intArg', 'Int', 'Int!'), - locations: [ { line: 6, column: 19 }, { line: 3, column: 43 } ] } + locations: [ { line: 6, column: 19 }, { line: 3, column: 43 } ], + path: undefined } ]); }); @@ -222,7 +224,8 @@ describe('Validate: Variables are in allowed positions', () => { } `, [ { message: badVarPosMessage('intArg', 'Int', 'Int!'), - locations: [ { line: 10, column: 19 }, { line: 7, column: 43 } ] } + locations: [ { line: 10, column: 19 }, { line: 7, column: 43 } ], + path: undefined } ]); }); @@ -235,7 +238,8 @@ describe('Validate: Variables are in allowed positions', () => { } `, [ { message: badVarPosMessage('stringVar', 'String', 'Boolean'), - locations: [ { line: 2, column: 19 }, { line: 4, column: 39 } ] } + locations: [ { line: 2, column: 19 }, { line: 4, column: 39 } ], + path: undefined } ]); }); @@ -248,7 +252,8 @@ describe('Validate: Variables are in allowed positions', () => { } `, [ { message: badVarPosMessage('stringVar', 'String', '[String]'), - locations: [ { line: 2, column: 19 }, { line: 4, column: 45 } ] } + locations: [ { line: 2, column: 19 }, { line: 4, column: 45 } ], + path: undefined } ]); }); @@ -259,7 +264,8 @@ describe('Validate: Variables are in allowed positions', () => { } `, [ { message: badVarPosMessage('boolVar', 'Boolean', 'Boolean!'), - locations: [ { line: 2, column: 19 }, { line: 3, column: 26 } ] } + locations: [ { line: 2, column: 19 }, { line: 3, column: 26 } ], + path: undefined } ]); }); @@ -270,7 +276,8 @@ describe('Validate: Variables are in allowed positions', () => { } `, [ { message: badVarPosMessage('stringVar', 'String', 'Boolean!'), - locations: [ { line: 2, column: 19 }, { line: 3, column: 26 } ] } + locations: [ { line: 2, column: 19 }, { line: 3, column: 26 } ], + path: undefined } ]); });