Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could you make error messages more informative? #431

Open
antonvialibri1 opened this issue Mar 25, 2024 · 1 comment
Open

Could you make error messages more informative? #431

antonvialibri1 opened this issue Mar 25, 2024 · 1 comment
Labels
📕 cache Feature requests related to the cache

Comments

@antonvialibri1
Copy link

Hello,

Thank you for this project! I have one request about error messages.

When an error occurs, for example when a custom merge fails because it uses mergeObjects and either one of incoming or existing isn't an array (because perhaps there's a bug on the developer's end), this is the error we get:

Cannot automatically merge arrays
import { ApolloClient, InMemoryCache } from '@apollo/client';

const simpleMerge = {
  merge(existing, incoming, { mergeObjects }) {
    return mergeObjects(existing, incoming); // This may fail if either `existing` or `incoming` isn't an array.
  }
};

const cacheOptions = {
  typePolicies: {
    SomeType: {
      fields: {
        someTypeItems: simpleMerge,
      }
    },
};

const cache = new InMemoryCache(cacheOptions);

It would be useful to at least have the name of the field involved, e.g.:

Cannot automatically merge arrays for `someTypeItems` field. Either one of `existing` or `incoming` is not an array. Check your merge function or the field's value.

Something like this would save a lot of hassle and time spent in debugging trying to understand what's going on.

@jerelmiller
Copy link
Member

Hey @antonvialibri1 👋

Thanks for the suggestion! This seems like a reasonable request! Feel free to submit a PR if you're interested in getting this in soon!

@jerelmiller jerelmiller added the 📕 cache Feature requests related to the cache label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📕 cache Feature requests related to the cache
Projects
None yet
Development

No branches or pull requests

2 participants