Description
Intended outcome:
MockedProvider
should return data for nested nullable fields if response object has a different depth of fields.
Actual outcome:
MockedProvider
returns undefined if a nullable field is omitted.
How to reproduce the issue:
Link to error template replicating this issue
When querying for an object with nested nullable fields, if the nullable fields are not present across all mocks then the query throws a MissingFieldError
and returns undefined.
The following query should be able to return an array of edges of { id: number }
and { id: number, assets: { assetConnection: { edges : [ node: { id: 1 } ] } } }
:
export const AssetsDocument = gql`
query Assets($input: AssetsInput!) {
assets(input: $input) {
assetsConnection {
edges {
node {
id
assets {
assetsConnection {
edges {
node {
id
}
}
}
}
}
}
}
}
}
`;
However, if a mock specifies a return value where edges are not the same depth, undefined
is returned and the client raises a MissingFieldError
.
This means the following mocks would be valid:
{
assets: {
assetsConnection: {
edges: [
{
node: {
id: '3',
assets: {
assetsConnection: {
edges: [{
node: { id: '4' },
}]
}
}
}
},
{
node: {
id: '1',
assets: {
assetsConnection: {
edges: [{
node: { id: '4' },
}]
}
}
},
}
],
}
}
}
and
{
assets: {
assetsConnection: {
edges: [
{
node: {
id: '3',
}
},
{
node: {
id: '1',
},
}
],
}
}
}
while a mock using mixed depth would not work as expected:
{
assets: {
assetsConnection: {
edges: [
{
node: {
id: '7',
assets: {
assetsConnection: {
edges: [{
node: { id: '4' },
}]
}
}
}
},
{
node: {
id: '100',
},
}
],
}
}
}
Versions
System:
OS: Linux 4.19 Debian GNU/Linux 10 (buster) 10 (buster)
Binaries:
Node: 12.16.3 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.4 - /usr/local/bin/npm
Browsers:
Chrome: 87.0.4280.141
npmPackages:
@apollo/client: ^3.3.7 => 3.3.7
Activity