How to use react-relay-offline - 10 common examples

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 / relay / createRelayEnvironment.ts View on Github external
},
      onDiscard: (options: any) => {
        //optio
        const {id, offlinePayload, error} = options;
        console.log('onDiscard', options);
        return true;
      },
    };

    const recordSource = new RecordSource({
      mergeState: () => {
        return records;
      },
    });
    const store = new Store(recordSource);
    return new Environment(
      {
        network,
        store,
      },
      offlineOptions,
    );

    // new
    // const offlineOptions = {}
    // const store = new Store(new RecordSource(records))
    // return new Environment(
    //   {
    //     network,
    //     store,
    //   },
    //   offlineOptions
github morrys / offline-examples / relay / nextjs / relay / createRelayEnvironment.ts View on Github external
network: network, //optional
      onComplete: (options: any) => {
        //optional
        const {id, offlinePayload, snapshot} = options;
        console.log('onComplete', options);
        return true;
      },
      onDiscard: (options: any) => {
        //optio
        const {id, offlinePayload, error} = options;
        console.log('onDiscard', options);
        return true;
      },
    };

    const recordSource = new RecordSource({
      mergeState: () => {
        return records;
      },
    });
    const store = new Store(recordSource);
    return new Environment(
      {
        network,
        store,
      },
      offlineOptions,
    );

    // new
    // const offlineOptions = {}
    // const store = new Store(new RecordSource(records))
github morrys / offline-examples / relay / nextjs / relay / createRelayEnvironment.ts View on Github external
return true;
      },
      onDiscard: (options: any) => {
        //optio
        const {id, offlinePayload, error} = options;
        console.log('onDiscard', options);
        return true;
      },
    };

    const recordSource = new RecordSource({
      mergeState: () => {
        return records;
      },
    });
    const store = new Store(recordSource);
    return new Environment(
      {
        network,
        store,
      },
      offlineOptions,
    );

    // new
    // const offlineOptions = {}
    // const store = new Store(new RecordSource(records))
    // return new Environment(
    //   {
    //     network,
    //     store,
    //   },
github morrys / offline-examples / relay / react-native / todo-updater / src / App.tsx View on Github external
const AppTodo = () => {
  const isRehydrated = useRestore(environment);
  if (!isRehydrated) {
    console.log("loading");
    return ;
  }
  console.log("renderer");
  return (
    
       {
github morrys / offline-examples / relay / todo-updater / js / app.js View on Github external
const AppTodo = props => {
  const isRehydrated = useRestore(environment);
  if (!isRehydrated) {
    console.log('loading');
    return <div>;
  }
  console.log('renderer');
  // ***** added to verify useRestore and fetchQuery ***
  /*const [load, setLoad] = React.useState(false);

  React.useEffect(() =&gt; {
    Array.from({length: 10},(_,x) =&gt;
    fetchQuery(environment, graphql`
    query appQuery($userId: String) {
      user(id: $userId) {
        ...TodoApp_user
      }
    }</div>
github morrys / offline-examples / todo / js / app.js View on Github external
}),
  });

  return response.json();
}



import RelayNetworkLogger from 'relay-runtime/lib/RelayNetworkLogger'
const network = Network.create(RelayNetworkLogger.wrapFetch(fetchQuery, () =&gt; ''));
function callbackOffline(type, payload, error) {
  //console.log("callbackoffline", type)
  //console.log("callbackoffline", payload)
  //console.log("callbackoffline", error)
}
const modernEnvironment = EnvironmentIDB.create({ network }, callbackOffline);
const rootElement = document.getElementById('root');

if (rootElement) {
  ReactDOM.render(
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;