Skip to content

MockedProvider throwing MissingFieldError for mocks that have different levels of nullable field nesting #7728

Open
@andyGallagher

Description

@andyGallagher

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions