mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Improve client-side graphql scalar types (#4511)
* Add types to graphql scalars * Upgrade dependencies * Override UI config type * Remove all IUIConfig casts * Add tableColumns to IUIConfig * Add BoolMap type, set strictScalars * Add PluginConfigMap * Replace any with unknown * Add SavedObjectFilter and SavedUIOptions * Remove unused items from CriterionType
This commit is contained in:
37
internal/api/plugin_map.go
Normal file
37
internal/api/plugin_map.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/99designs/gqlgen/graphql"
|
||||
)
|
||||
|
||||
func MarshalPluginConfigMap(val map[string]map[string]interface{}) graphql.Marshaler {
|
||||
return graphql.WriterFunc(func(w io.Writer) {
|
||||
err := json.NewEncoder(w).Encode(val)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func UnmarshalPluginConfigMap(v interface{}) (map[string]map[string]interface{}, error) {
|
||||
m, ok := v.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%T is not a plugin config map", v)
|
||||
}
|
||||
|
||||
result := make(map[string]map[string]interface{})
|
||||
for k, v := range m {
|
||||
val, ok := v.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("key %s (%T) is not a map", k, v)
|
||||
}
|
||||
|
||||
result[k] = val
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user