question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validate that the data matches the shape of a query before writing it back into the store

See original GitHub issue

This issue combines the problem described in #973 #1123 #1273 #1293 #1588 #1605

Intended outcome: Apollo should throw an error or a warning when the returned data from updateQueries or reducer does not match the shape of the query that is intended to be updated.

Actual outcome: Apollo flushes the data without any warning.

An insight into this problem is here.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
cesarsolorzanocommented, Apr 27, 2017

I think it would be great to explain this explicitly in the docs. It can be a way to prevent this error from being made in the first place (unconsciously or thinking that if you don’t want to provide a value, you should omit it —instead of providing a null-like value).

Although it is briefly explained here, I do think it should be documented as well in Updating the Store and Optimistic UI.

@jakelacey2012 would you like to do a PR in react-docs to provide better information in these pages or somewhere else that you think might be useful?

1reaction
bknifflercommented, May 3, 2017

I don’t get this. Lets say I have a type:

type File {
        id: String
        format: String
        version: Int
        resourceType: String
        type: String
        createdAt: String
        height: Int
        width: Int
        bytes: Int
        tags: [String]
        url: String
        caption: String
        source: String
        colors: [String]
      }

Then I query a list of this type

const queryFiles = graphql(gql`
  query fileList {
    items: fileList {
      id, url, tags
    }
  }
`);

And then I call a mutation like

const mutation = graphql(gql`
  mutation file($id: String, $token: String) {
    file(id: $id, token: $token) {
      id, url, tags, colors, width, height, createdAt, caption, source, format, bytes
    }
  }
`, {
  props({ ownProps, mutate }) {
    return {
      save: (id) => {
        return mutate({
          variables: { id },
          updateQueries: {
            fileList: (prev, { mutationResult }) => {
              const newData = mutationResult.data.file;
              return {
                ...prev,
                items: [newData, ...prev.items],
              };
            },
          },
        });
      },
    };
  },
});

Is it expected, that items will now be undefined? I’ve had a very similar scenario where this was the case. The example above does not match it 100%, but it was extremely similar as where I’ve been querying/mutating the same type, but the query would only have a subset of the mutation fields.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading and writing data to the cache - Apollo GraphQL Docs
The writeQuery method enables you to write data to your cache in a shape that matches a GraphQL query. It resembles readQuery ,...
Read more >
20 SQL for Pattern Matching - Oracle Help Center
Pattern matching can let you identify price patterns, such as V-shapes and W-shapes illustrated in Figure 20-1, along with performing many types of...
Read more >
Shapes Constraint Language (SHACL) - W3C
Abstract. This document defines the SHACL Shapes Constraint Language, a language for validating RDF graphs against a set of conditions.
Read more >
Chapter 3. Data, Tables, and Database Design - O'Reilly
THE FIX: Normalizing basically means organizing data to reduce redundancy. As the esteemed Webopedia ( http://www.pcwebopedia.com ) pithily puts it, it involves ...
Read more >
Set Validation Rules for Your Schema — MongoDB Compass
Schema validation ensures that all documents in a collection follow a defined set of rules, such as conforming to a specific shape or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found