-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
6/n - Add tests for errorResponseFields
Reviewed By: tyao1 Differential Revision: D51944691 fbshipit-source-id: 61b3fcfd50ac7927514a9913d53ceb8fb486cf7c
- Loading branch information
1 parent
27a0623
commit 399bf92
Showing
8 changed files
with
872 additions
and
0 deletions.
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
packages/relay-runtime/store/__tests__/RelayReader-RelayErrorHandling-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @oncall relay | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const {graphql} = require('../../query/GraphQLTag'); | ||
const RelayFeatureFlags = require('../../util/RelayFeatureFlags'); | ||
const { | ||
createOperationDescriptor, | ||
} = require('../RelayModernOperationDescriptor'); | ||
const {read} = require('../RelayReader'); | ||
const RelayRecordSource = require('../RelayRecordSource'); | ||
|
||
describe('RelayReader error fields', () => { | ||
describe('when field error handling is enabled', () => { | ||
beforeAll(() => { | ||
RelayFeatureFlags.ENABLE_FIELD_ERROR_HANDLING = true; | ||
}); | ||
|
||
const wasFieldErrorHandlingEnabled = | ||
RelayFeatureFlags.ENABLE_FIELD_ERROR_HANDLING; | ||
|
||
it('adds the errors to errorResponseFields', () => { | ||
const source = RelayRecordSource.create({ | ||
'client:root': { | ||
__id: 'client:root', | ||
__typename: '__Root', | ||
me: {__ref: '1'}, | ||
}, | ||
'1': { | ||
__id: '1', | ||
id: '1', | ||
__typename: 'User', | ||
lastName: null, | ||
__errors: { | ||
lastName: [ | ||
{ | ||
message: 'There was an error!', | ||
path: ['me', 'lastName'], | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
|
||
const FooQuery = graphql` | ||
query RelayReaderRelayErrorHandlingTest1Query { | ||
me { | ||
lastName | ||
} | ||
} | ||
`; | ||
const operation = createOperationDescriptor(FooQuery, {id: '1'}); | ||
const {data, errorResponseFields} = read(source, operation.fragment); | ||
expect(data).toEqual({me: {lastName: null}}); | ||
expect(errorResponseFields).toEqual([ | ||
{ | ||
owner: 'RelayReaderRelayErrorHandlingTest1Query', | ||
path: 'me.lastName', | ||
error: {message: 'There was an error!', path: ['me', 'lastName']}, | ||
}, | ||
]); | ||
}); | ||
|
||
afterAll(() => { | ||
RelayFeatureFlags.ENABLE_FIELD_ERROR_HANDLING = | ||
wasFieldErrorHandlingEnabled; | ||
}); | ||
}); | ||
|
||
describe('when field error handling is disabled', () => { | ||
beforeAll(() => { | ||
RelayFeatureFlags.ENABLE_FIELD_ERROR_HANDLING = false; | ||
}); | ||
|
||
const wasFieldErrorHandlingEnabled = | ||
RelayFeatureFlags.ENABLE_FIELD_ERROR_HANDLING; | ||
|
||
it('errorResponseFields is null', () => { | ||
const source = RelayRecordSource.create({ | ||
'client:root': { | ||
__id: 'client:root', | ||
__typename: '__Root', | ||
me: {__ref: '1'}, | ||
}, | ||
'1': { | ||
__id: '1', | ||
id: '1', | ||
__typename: 'User', | ||
lastName: null, | ||
__errors: { | ||
lastName: [ | ||
{ | ||
message: 'There was an error!', | ||
path: ['me', 'lastName'], | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
|
||
const FooQuery = graphql` | ||
query RelayReaderRelayErrorHandlingTest2Query { | ||
me { | ||
lastName | ||
} | ||
} | ||
`; | ||
const operation = createOperationDescriptor(FooQuery, {id: '1'}); | ||
const {data, errorResponseFields} = read(source, operation.fragment); | ||
expect(data).toEqual({me: {lastName: null}}); | ||
expect(errorResponseFields).toEqual(null); | ||
}); | ||
|
||
afterAll(() => { | ||
RelayFeatureFlags.ENABLE_FIELD_ERROR_HANDLING = | ||
wasFieldErrorHandlingEnabled; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
..._generated__/RelayModernFragmentSpecResolverRelayErrorHandlingTestUserFragment.graphql.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.