/**
 * This file provided by Facebook is for non-commercial testing and evaluation
 * purposes only.  Facebook reserves all rights not expressly granted.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */ import { commitMutation , graphql } from 'relay-hooks' ; import { Disposable } from 'relay-runtime' ; import { getUser } from './ReadInlineUser' ; const mutation = graphql `
    mutation MarkAllTodosMutation($input: MarkAllTodosInput!) {
        markAllTodos(input: $input) {
            changedTodos {
                id
                complete
            }
            user {
                id
                completedCount
            }
        }
    }
` ; function getOptimisticResponse ( complete , todos , user ) { const validNodes = todos . edges ? todos . edges . filter ( Boolean ) . map ( ( edge ) : any => edge . node ) . filter ( Boolean ) : [ ] ; const changedTodos = validNodes . filter ( ( node ) : boolean => node . complete !== complete ) . map ( ( node ) : any => ( { complete : complete , id : node . id , } ) ) ; return { markAllTodos : { changedTodos , user : { id : user . id , completedCount : complete ? user . totalCount : 0 , } , } , } ; } export function commit ( environment , complete , todos , userRef ) { const user = getUser ( userRef ) ; const input = { complete , userId : user . userId , } ; return commitMutation ( environment , { mutation , variables : { input , } , optimisticResponse : getOptimisticResponse ( complete , todos , user ) , } ) ; } export const MarkAllTodosMutation = { commit , } ;