How to use the react-relay-offline.commitMutation function in react-relay-offline

To help you get started, we’ve selected a few react-relay-offline 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 morrys / offline-examples / relay / react-native / todo-updater / src / mutations / RemoveCompletedTodosMutation.ts View on Github external
function commit(
  environment: Environment,
  todos: any,
  user: any,
) {
  const input: any = {
    userId: user.userId,
  };

  commitMutation(environment, {
    mutation,
    variables: {
      input,
    },
    updater: (store: any) => {
      const payload = store.getRootField('removeCompletedTodos');
      const deletedIds = payload.getValue('deletedTodoIds');

      // $FlowFixMe `payload.getValue` returns mixed, not sure how to check refinement to $ReadOnlyArray
      sharedUpdater(store, user, deletedIds);
    },
    optimisticUpdater: (store: any) => {
      // Relay returns Maybe types a lot of times in a connection that we need to cater for
      const completedNodeIds: ReadonlyArray = todos.edges
        ? todos.edges
            .filter(Boolean)
github morrys / offline-examples / relay / todo-updater / js / mutations / AddTodoMutation.js View on Github external
totalCount: totalCount
        }
      }
    },
    configs: [{
      type: 'RANGE_ADD',
      parentID: user.id,
      connectionInfo: [{
        key: 'TodoList_todos',
        rangeBehavior: 'append',
      }],
      edgeName: 'todoEdge',
    }],
  });*/

  return commitMutation(environment, {
    mutation,
    variables: {
      input,
    },
    onCompleted: data => {
      console.log('onCompleted', data);
    },
    updater: store => {
      // Get the payload returned from the server
      const payload = store.getRootField('addTodo');

      // Get the edge of the newly created Todo record
      const newEdge = payload.getLinkedRecord('todoEdge');

      // Add it to the user's todo list
      sharedUpdater(store, user, newEdge);
github morrys / offline-examples / relay / nextjs / mutations / AddTodoMutation.ts View on Github external
totalCount: totalCount
        }
      }
    },
    configs: [{
      type: 'RANGE_ADD',
      parentID: user.id,
      connectionInfo: [{
        key: 'TodoList_todos',
        rangeBehavior: 'append',
      }],
      edgeName: 'todoEdge',
    }],
  });*/

  commitMutation(environment, {
    mutation,
    variables: {
      input,
    },
    updater: (store: any) => {
      // Get the payload returned from the server
      const payload = store.getRootField('addTodo');

      // Get the edge of the newly created Todo record
      const newEdge = payload.getLinkedRecord('todoEdge');

      // Add it to the user's todo list
      sharedUpdater(store, user, newEdge);
    },
    optimisticUpdater: (store: any) => {
      const id = idTodo;
github morrys / offline-examples / relay / react-native / todo-updater / src / mutations / AddTodoMutation.ts View on Github external
totalCount: totalCount
        }
      }
    },
    configs: [{
      type: 'RANGE_ADD',
      parentID: user.id,
      connectionInfo: [{
        key: 'TodoList_todos',
        rangeBehavior: 'append',
      }],
      edgeName: 'todoEdge',
    }],
  });*/

  commitMutation(environment, {
    mutation,
    variables: {
      input
    },
    updater: (store: any) => {
      // Get the payload returned from the server
      const payload = store.getRootField("addTodo");

      // Get the edge of the newly created Todo record
      const newEdge = payload.getLinkedRecord("todoEdge");

      // Add it to the user's todo list
      sharedUpdater(store, user, newEdge);
    },
    optimisticUpdater: (store: any) => {
      const id = idTodo;
github morrys / offline-examples / relay / todo-updater / js / mutations / ChangeTodoStatusMutation.js View on Github external
function commit(
  environment: Environment,
  complete: boolean,
  todo: Todo_todo,
  user: Todo_user,
): Disposable {
  const input: ChangeTodoStatusInput = {
    complete,
    userId: user.userId,
    id: todo.id,
  };
  return commitMutation(environment, {
    mutation,
    variables: {
      input,
    },
    optimisticResponse: getOptimisticResponse(complete, todo, user),
  });
}
github morrys / offline-examples / relay / react-native / todo-updater / src / mutations / ChangeTodoStatusMutation.ts View on Github external
function commit(
  environment: Environment,
  complete: boolean,
  todo: any,
  user: any,
) {
  const input: any = {
    complete,
    userId: user.userId,
    id: todo.id,
  };
  commitMutation(environment, {
    mutation,
    variables: {
      input,
    },
    optimisticResponse: getOptimisticResponse(complete, todo, user),
  });
}
github morrys / offline-examples / todo / js / mutations / AddTodoMutation.js View on Github external
function commit(
  environment: Environment,
  text: string,
  user: TodoApp_user,
): Disposable {
  const idTodo = uuid();
  const input: AddTodoInput = {
    id: idTodo,
    text,
    userId: user.userId,
    clientMutationId: idTodo,
  };

  const totalCount = user.totalCount + 1;
  const idTot = totalCount+user.completedCount;
  return commitMutation(environment, {
    mutation,
    variables: {
      input,
    },
    optimisticResponse: {
      addTodo: {
        todoEdge: {
          node: {
            id: idTodo, 
            text: text,
            complete: false
          },
          cursor: null,
          __typename: "TodoEdge"
        },
        user: {
github morrys / offline-examples / relay / nextjs / mutations / ChangeTodoStatusMutation.ts View on Github external
function commit(environment: any, complete: boolean, todo: any, user: any) {
  const input: any = {
    complete,
    userId: user.userId,
    id: todo.id,
  };
  commitMutation(environment, {
    mutation,
    variables: {
      input,
    },
    optimisticResponse: getOptimisticResponse(complete, todo, user),
  });
}
github morrys / offline-examples / relay / react-native / todo-updater / src / mutations / RemoveTodoMutation.ts View on Github external
function commit(
  environment: any,
  todo: any,
  user: any,
): any {
  const input: any = {
    id: todo.id,
    userId: user.userId,
  };
  return commitMutation(environment, {
    mutation,
    variables: {
      input,
    },
    configs: [{
      type: 'NODE_DELETE',
      deletedIDFieldName: 'deletedTodoId',
    },
     ],
    optimisticResponse: {
      removeTodo: {
        deletedTodoId: todo.id,
        user: {
          id: user.id,
          completedCount: user.completedCount - (todo.complete ? 1 : 0),
          totalCount: (user.totalCount-1)
github morrys / offline-examples / relay / todo-updater / js / mutations / RenameTodoMutation.js View on Github external
function commit(
  environment: Environment,
  text: string,
  todo: Todo_todo,
): Disposable {
  const input: RenameTodoInput = {
    text,
    id: todo.id,
  };

  return commitMutation(environment, {
    mutation,
    variables: {
      input,
    },
    optimisticResponse: getOptimisticResponse(text, todo),
  });
}