improve error messages for metadata apply (close #1877) (#1895)

This commit is contained in:
Aravind Shankar 2019-04-03 12:27:59 +05:30 committed by Shahidh K Muhammed
parent 1e20026ea2
commit f147f6d6a6

View File

@ -3,6 +3,8 @@ package hasuradb
import (
"encoding/json"
"net/http"
"github.com/oliveagle/jsonpath"
)
func (h *HasuraDB) ExportMetadata() (interface{}, error) {
@ -118,6 +120,26 @@ func (h *HasuraDB) ApplyMetadata(data interface{}) error {
h.logger.Debug(err)
return err
}
if horror.Path != "" {
jsonData, err := json.Marshal(query)
if err != nil {
return err
}
var metadataQuery interface{}
err = json.Unmarshal(jsonData, &metadataQuery)
if err != nil {
return err
}
lookup, err := jsonpath.JsonPathLookup(metadataQuery, horror.Path)
if err == nil {
queryData, err := json.MarshalIndent(lookup, "", " ")
if err != nil {
return err
}
horror.migrationQuery = "offending object: \n\r\n\r" + string(queryData)
}
}
return horror.Error(h.config.isCMD)
}
return nil