Apollo-client: AC3: Missing Field Silently Prevents Entire Query From Updating

Created on 25 Feb 2020  ·  10Comments  ·  Source: apollographql/apollo-client

Expected outcome:
If a field is missing from a child object of query results, I expect:

  • The query to continue to update and return the objects with complete/expected fields
  • Some kind of error/warning to be available to indicate the missing fields

Actual outcome:
If a field is missing from a child object of a query:

  • The entire query silently fails (seems to stop updating)
  • No error or warning seems to be available indicating the missing fields

How to reproduce the issue:
See this [react apollo error template] for a working recreation of the issue, with embedded notes

Notes
I am a big fan of Apollo Client 3. Debugging Queries that are not working due to to missing fields is the single most frequent (and time-consuming) issue I run into with AC3. The difficulty of troubleshooting these issues increases a great deal with complex and deep graphs.

The @apollo-client source already looks to have missing field tracking capabilities. For some reason this does not seem to bubble up (and I am not familiar enough with the source to figure out why)

Currently, the only way I have found to reveal the underlying missing field messages is to manually add console logging to the line 160 of the readFromStore.js file in the @apollo-client package, which is not a great user experience. (Maybe I am missing some obvious way to reveal these messages?)

Anything that can make this experience better would be a big help.

Versions
System:
OS: macOS 10.15.3
Binaries:
Node: 13.7.0 - /usr/local/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.13.6 - /usr/local/bin/npm
Browsers:
Chrome: 79.0.3945.130
Safari: 13.0.5
npmPackages:
@apollo/client: 3.0.0-beta.37 => 3.0.0-beta.37

has-reproduction ✔ confirmed 🐞 bug 🛬 fixed-in-prerelease

Most helpful comment

@benjamn, @hwillson - I have verified that the issue I originally opened this ticket for is now solved. The query no longer silently fails, but instead produces a useful error message.

Others on this thread seem to have questions, so I am not sure what the protocol on closing the ticket or leaving open is. I shall leave to you.

Thanks for taking care of the core issue. This will be a massive productivity boost when working with AC3

All 10 comments

We hear you, and we are working on this currently. Thanks for the reproduction!

Ah, I suspect this issue might be the root cause of https://github.com/apollographql/apollo-client/issues/5963 as well

I believe this will be solved by #6221. Have a look if you're curious, and thanks for your patience!

@benjamn - that looks like a lot of work, and some good improvements! The fetchPolicy switch statement is definitely a big help in making the codebase more understandable. Pseudocode-style-coding is great for readability. Thanks for persisting.

I'm facing the same issue, but in beta-44 i've got a warning that field is missing.

To fix this I query the same fields set in both queries.

Example (note the title field):

query list {
  list {
    name
    image {
      title
      url
    }
  }
}
query image {
  image 
      # title <- title was missed in in second query
      url
  }
}

And I don't know if this is important, but the socond query is resolved though fieldsPolicy AKA cacheRedirects.

@ElForastero if these are your actual queries, isn’t the warning rather because your objects don’t have ids ?

I'm having a similar issue...

I'm building a kanban board so it has several columns (this query is called once for each column, or stage)

I have this query

import gql from 'graphql-tag';
import projectFragment from 'ApolloClient/Fragments/projectFragment';

export default gql`
  query projectsByStage($pipelineId: ID!, $stage: Int!) {
    projectsByStage(pipelineId: $pipelineId, stage: $stage) {
      ...projectFragment
    }
  }
  ${projectFragment}
`;

//// another file
import gql from 'graphql-tag';

export default gql`
  fragment projectFragment on Project {
    id
    __typename
    title
    description
    projectType
    pipeline
    stage
  }
`;

cache looks like this before an update

Screen Shot 2020-05-03 at 8 30 58 AM

Note I have 7 projectsByStage queries, because in this case I have 7 kanban columns

and like this after an update

Screen Shot 2020-05-03 at 8 30 37 AM

The single project is successfully moved from one query result (or column) to another using writeQuery. I've also checked this by running readQuery after I do the writeQuery.

But, my query is not rerendering the component...

  • I quadruple checked all the variables match up (and from the snapshot of the store, you can see there are no differently named queries that it may be mixing up).
  • I have typenames and an ID for each object/project that comes back
  • the query is using defaults (which I think should be cache first)
  • the data is correctly updating on the backend as well

I'm not sure what I'm overlooking...

    "apollo-cache-inmemory": "^1.6.5",
    "apollo-client": "^2.6.8",
    "apollo-link": "^1.2.11",
    "apollo-link-error": "^1.1.10",
    "apollo-link-http": "^1.5.14",
    "apollo-link-logger": "^1.2.3",
    "apollo-link-retry": "^2.2.13",
    "apollo-link-timeout": "^1.2.1",
    "apollo-upload-client": "^13.0.0",

@mobiware I've simplified the examples. I have identifiers in entities and the warning was exactly about missed title field in the cache.

@benjamn, @hwillson - I have verified that the issue I originally opened this ticket for is now solved. The query no longer silently fails, but instead produces a useful error message.

Others on this thread seem to have questions, so I am not sure what the protocol on closing the ticket or leaving open is. I shall leave to you.

Thanks for taking care of the core issue. This will be a massive productivity boost when working with AC3

Was this page helpful?
0 / 5 - 0 ratings