Skip to content

Commit

Permalink
fix formatting and flow typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chrskrchr committed May 11, 2022
1 parent 651fc3f commit b9dc10c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 43 deletions.
41 changes: 4 additions & 37 deletions src/__testUtils__/expectJSON.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,18 @@
import { expect } from 'chai';

import isObjectLike from '../jsutils/isObjectLike';
import mapValue from '../jsutils/mapValue';
import toJSONDeep from '../language/__tests__/toJSONDeep';

/**
* Deeply transforms an arbitrary value to a JSON-safe value by calling toJSON
* on any nested value which defines it.
*/
function toJSONDeep(value) {
if (!isObjectLike(value)) {
return value;
}

if (typeof value.toJSON === 'function') {
return value.toJSON();
}

if (Array.isArray(value)) {
return value.map(toJSONDeep);
}

return mapValue(value, toJSONDeep);
}

export default function expectJSON(actual) {
export default function expectJSON(actual: mixed) {
const actualJSON = toJSONDeep(actual);

return {
toDeepEqual(expected) {
toDeepEqual(expected: mixed) {
const expectedJSON = toJSONDeep(expected);
expect(actualJSON).to.deep.equal(expectedJSON);
},
toDeepNestedProperty(path, expected) {
toDeepNestedProperty(path: string, expected: mixed) {
const expectedJSON = toJSONDeep(expected);
expect(actualJSON).to.deep.nested.property(path, expectedJSON);
},
};
}

export function expectToThrowJSON(fn) {
function mapException() {
try {
return fn();
} catch (error) {
throw toJSONDeep(error);
}
}

return expect(mapException).to.throw();
}
2 changes: 1 addition & 1 deletion src/execution/__tests__/executor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ describe('Execute: Handles basic execution tasks', () => {
errors: [
{
message:
'Cannot return null for non-nullable field Query.syncNullError.',
'Cannot return null for non-nullable field Query.syncNullError.',
locations: [{ line: 4, column: 9 }],
path: ['syncNullError'],
},
Expand Down
10 changes: 5 additions & 5 deletions src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,11 @@ function executeFields(
const fieldNodes = fields[responseName];
const fieldPath = addPath(path, responseName, parentType.name);
const result = resolveField(
exeContext,
parentType,
sourceValue,
fieldNodes,
fieldPath,
exeContext,
parentType,
sourceValue,
fieldNodes,
fieldPath,
);

if (result !== undefined) {
Expand Down

0 comments on commit b9dc10c

Please sign in to comment.