How to use the react-relay-offline.RecordSource 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 / 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 / react-native / todo-updater / src / relay / index.ts View on Github external
onDiscard: async (options: any) => {
    //optio
    const { id, offlinePayload, error } = options;
    console.log("onDiscard", options);
    return true;
  }
};

/**
 * Store
 */
const options: any = {
  errorHandling: (cache: any, error: any) => console.log("error storage", error)
};

export const recourdSource = new RecordSource(options);

export const store = new Store(recourdSource, options);

/**
 * Environment
 */
export const environment = new Environment({ network, store });
environment.setOfflineOptions(offlineOptions);
github morrys / offline-examples / relay / todo-updater / js / relay / index.js View on Github external
},
    body: JSON.stringify({
      query: operation.text,
      variables,
    }),
  });

  return response.json();
}

const network = Network.create(fetchQuery);
export const manualExecution = false;

//const environment = EnvironmentIDB.create({network}, offlineOptions); //, {ttl: 60 * 1000}

const recordSource = new RecordSource();
const store = new Store(recordSource);
store._cache.set('provainit', 'prova');
const environment = new Environment({network, store});
environment.setOfflineOptions({
  manualExecution, //optional
  network: network, //optional
  start: async mutations => {
    //optional
    console.log('start offline', mutations);
    return mutations;
  },
  finish: async (mutations, error) => {
    //optional
    console.log('finish offline', error, mutations);
  },
  onExecute: async mutation => {