How to use the apollo-cache-inmemory.defaultDataIdFromObject function in apollo-cache-inmemory

To help you get started, we’ve selected a few apollo-cache-inmemory examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github taskcluster / taskcluster / ui / src / App / index.jsx View on Github external
dataIdFromObject: object => {
      switch (object.__typename) {
        case 'TaskStatus': {
          const taskId = object.taskId || null;

          return taskId
            ? `${object.taskId}-${object.__typename}`
            : defaultDataIdFromObject(object);
        }

        default: {
          // fall back to default handling
          return defaultDataIdFromObject(object);
        }
      }
    },
    /* eslint-enable no-underscore-dangle */
github mirumee / saleor-dashboard / src / index.tsx View on Github external
dataIdFromObject: (obj: any) => {
      // We need to set manually shop's ID, since it is singleton and
      // API does not return its ID
      if (obj.__typename === "Shop") {
        return "shop";
      }
      return defaultDataIdFromObject(obj);
    }
  }),
github gitlabhq / gitlabhq / spec / frontend / import_entities / import_groups / graphql / services / source_groups_manager_spec.js View on Github external
it('updates group by id with provided function', () => {
    const UPDATED_GROUP = {};
    const fn = jest.fn().mockReturnValue(UPDATED_GROUP);
    client.readFragment.mockReturnValue(getFakeGroup());
    manager.updateById(getFakeGroup().id, fn);

    expect(client.readFragment).toHaveBeenCalledWith({
      fragment: ImportSourceGroupFragment,
      id: defaultDataIdFromObject(getFakeGroup()),
    });

    expect(client.writeFragment).toHaveBeenCalledWith({
      fragment: ImportSourceGroupFragment,
      id: defaultDataIdFromObject(getFakeGroup()),
      data: UPDATED_GROUP,
    });
  });
github Urigo / WhatsApp-Clone-Client-React / src / components / ChatRoomScreen / MessageBox.tsx View on Github external
update: (client, { data: { addMessage } }) => {
        client.writeFragment({
          id: defaultDataIdFromObject(addMessage),
          fragment: fragments.message,
          data: addMessage,
        })

        let fullChat
        try {
          fullChat = client.readFragment({
            id: defaultDataIdFromObject(addMessage.chat),
            fragment: fragments.fullChat,
            fragmentName: 'FullChat',
          })
        } catch (e) {}

        if (fullChat && !fullChat.messages.some(message => message.id === addMessage.id)) {
          fullChat.messages.push(addMessage)
          fullChat.lastMessage = addMessage
github Urigo / WhatsApp-Clone-Client-React / src / services / cache.service.tsx View on Github external
let fullChat
      try {
        fullChat = client.readFragment({
          id: defaultDataIdFromObject(messageAdded.chat),
          fragment: fragments.fullChat,
          fragmentName: 'FullChat',
        })
      } catch (e) {}

      if (fullChat && !fullChat.messages.some(message => message.id === messageAdded.id)) {
        fullChat.messages.push(messageAdded)
        fullChat.lastMessage = messageAdded

        client.writeFragment({
          id: defaultDataIdFromObject(fullChat),
          fragment: fragments.fullChat,
          fragmentName: 'FullChat',
          data: fullChat,
        })
      }

      let chats
      try {
        chats = client.readQuery({
          query: queries.chats,
        }).chats
      } catch (e) {}

      if (chats) {
        const index = chats.findIndex(chat => chat.id === messageAdded.chat.id)
        const chat = chats[index]
github Urigo / WhatsApp-Clone-Client-React / src / services / cache.service.ts View on Github external
export const writeChat = (client: Client, chat: ChatFragment) => {
  const chatId = defaultDataIdFromObject(chat);
  if (chatId === null) {
    return;
  }

  client.writeFragment({
    id: chatId,
    fragment: fragments.chat,
    fragmentName: 'Chat',
    data: chat,
  });

  let data;
  try {
    data = client.readQuery({
      query: queries.chats,
    });
github adrivelasco / graphql-pwa-workshop / client / core / createCache.js View on Github external
function dataIdFromObject(obj) {
  switch (obj.__typename) {
    case 'NewsItem':
      return obj.link ? `NewsItem:${obj.link}` : defaultDataIdFromObject(obj);
    default:
      return defaultDataIdFromObject(obj);
  }
}
github netlify / netlify-cms / packages / netlify-cms-backend-github / src / GraphQLAPI.js View on Github external
      update: store => store.data.delete(defaultDataIdFromObject(branch)),
    });