Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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);
},
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
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))
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,
// },
const AppTodo = () => {
const isRehydrated = useRestore(environment);
if (!isRehydrated) {
console.log("loading");
return ;
}
console.log("renderer");
return (
{
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(() => {
Array.from({length: 10},(_,x) =>
fetchQuery(environment, graphql`
query appQuery($userId: String) {
user(id: $userId) {
...TodoApp_user
}
}</div>
}),
});
return response.json();
}
import RelayNetworkLogger from 'relay-runtime/lib/RelayNetworkLogger'
const network = Network.create(RelayNetworkLogger.wrapFetch(fetchQuery, () => ''));
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(
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;
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;