import { Variables , UploadableMap , CacheConfig } from 'relay-runtime' ; import { RequestNode } from 'relay-runtime' ; export const isMutation = ( request ) => request . operationKind === 'mutation' ; export const isQuery = ( request ) => request . operationKind === 'query' ; export const forceFetch = ( cacheConfig ) => ! ! ( cacheConfig && cacheConfig . force ) ; export const handleData = ( response ) => { const contentType = response . headers . get ( 'content-type' ) ; if ( contentType && contentType . indexOf ( 'application/json' ) !== - 1 ) { return response . json ( ) ; } return response . text ( ) ; } ; function getRequestBodyWithUploadables ( request , variables , uploadables ) { let formData = new FormData ( ) ; formData . append ( 'name' , request . name ) ; formData . append ( 'query' , request . text ) ; formData . append ( 'variables' , JSON . stringify ( variables ) ) ; Object . keys ( uploadables ) . forEach ( key => { if ( Object . prototype . hasOwnProperty . call ( uploadables , key ) ) { formData . append ( key , uploadables [ key ] ) ; } } ) ; return formData ; } function getRequestBodyWithoutUplodables ( request , variables ) { return JSON . stringify ( { name : request . name , query : request . text , variables , } ) ; } export function getRequestBody ( request , variables , uploadables ? ) { if ( uploadables ) { return getRequestBodyWithUploadables ( request , variables , uploadables ) ; } return getRequestBodyWithoutUplodables ( request , variables ) ; } export const getHeaders = ( uploadables ? ) => { if ( uploadables ) { return { Accept : '*/*' , } ; } return { Accept : 'application/json' , 'Content-type' : 'application/json' , } ; } ;