import client from 'part:@sanity/base/client'

function uploadAsset(assetType, asset) {
  return client.observable.assets.upload(assetType, asset.file)
    .map(event => {
      if (event.type === 'response') {
        // rewrite to a 'complete' event
        return {
          type: 'complete',
          id: event.body.document._id,
          asset: event.body.document
        }
      }
      return event
    })
}

export const uploadImage = imageAsset => uploadAsset('image', imageAsset)
export const uploadFile = fileAsset => uploadAsset('file', fileAsset)

export function materializeReference(id) {
  return client.observable
    .fetch('*[_id == $id] {_id, _type, url}', {id: id})
    .map(results => results[0])
}

@@ -637,89 +637,22 @@
    .
-fetch('*%5B_id == $id%5D %7B_id, _type, url%7D', %7Bid: id%7D)%0A    .map(results =%3E results%5B0%5D
+getDocument(id
 )%0A%7D%0A

Use .getDocument to fetch image record to avoid sync issues