Giter VIP home page Giter VIP logo

apollo-cache-updater's People

Contributors

ecerroni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

apollo-cache-updater's Issues

Generally confused on how this package works

I currently have this in my code:

update: (store, { data: { deleteTracks } }) => {
  const updates = ApolloCacheUpdater({
    proxy: store,
    queriesToUpdate: [getTracksQuery],
    searchVariables: {
      // ??
    },
    mutationResult: deleteTracks,
  });
},

It just so happens that my delete mutation returns an array of IDs that were actually found and deleted, but the cache updater doesn't like this:

ApolloCacheUpdater Error: mutationResult cannot be an array | [mutation-result_no-array]

I'm also not totally sure I'm using searchVariables properly.

Bug: Cannot assign to read only property

Although queries in the cache should not be frozen, sometimes it still happens. I've not understood what is the exact reason of this.

The error message is:
TypeError: Cannot assign to read only property '__my_query_name__' of object '#<Object>'

Cache update does not rerender

Issue:

When adding a new Employee, ApolloCacheUpdater successfully updates the cache but does not trigger a re-render ( shown once the page is refreshed).

Info:

REMOVE is working as intended and triggers a re-render upon completion.

Client Options:

fetchPolicy: 'cache-and-network',
errorPolicy: 'all',
notifyOnNetworkStatusChange: true,
returnPartialData: true

Image

The following image shows:

  1. Console log: Created Employee & ApolloCacheUpdater ran successfully
  2. Apollo Extension: Shows the Employee in cache
  3. Table: Empty table
  4. employees object: data object from const { loading, data, refetch } = useQuery(GET_EMPLOYEES)

Image

Not working with @client directive

Hi! First of all thank you for this awesome helper.

I'm just having trouble making it work with @client directive. Below is my query

const TODO_MANY = gql`
  query {
    todoMany {
      _id
      title
      isOptimistic @client
    }
  }
`;

const ADD_TODO = gql`
  mutation TodoCreateOne($input: CreateOneTodoInput!) {
    todoCreateOne(record: $input) {
      record {
        _id
        title
      }
      recordId
    }
  }
`;

Here's my onClick callback

const onClick = useCallback(() => {
    const id = uuid();
    addTodo({
      variables: {
        input: {
          title: 'test12',
        },
      },
      optimisticResponse: {
        __typename: 'Mutation',
        todoCreateOne: {
          __typename: 'CreateOneTodoPayload',
          recordId: id,
          record: {
            __typename: 'Todo',
            title: 'test12',
            _id: id,
            isOptimistic: true,
          },
        },
      },
      update: (cache, { data: { todoCreateOne } }) => {
        const updates = ApolloCacheUpdater({
          proxy: cache,
          queriesToUpdate: [TODO_MANY],
          operation: {
            type: 'ADD',
            add: ({ query, type, data, variables }) => {
              console.log('Calling Add');
              const rec = todoCreateOne.record;
              return [rec, ...data];
            },
          },
          searchVariables: {},
          mutationResult: todoCreateOne,
          ID: 'recordId',
        });
        if (updates) console.log(`Success`);
      },
    });
  }, []);

It is working without @client. "Calling Add" is displaying in console
but when I add @client, add function is not executing.

Note : I also tried doing the cache update manually and it works.

        const queryData = cache.readQuery({ query: TODO_MANY });
        cache.writeQuery({
           query: TODO_MANY,
           data: {
             todoMany: [
               ...queryData.todoMany,
               {
                 ...todoCreateOne.record,
               },
             ],
          },
        });

Thank you.

Feat request: Typescript support

Hi! Just wanted to know the feasibility of adding declaration typescript files (since the project is solely built on javascript) This would be a great addition for pure Typescript projects.

Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.