Fix dataloaders not loading in js plugins (#3014)

* Include dataloaders in js plugin gql calls
* Handle gql errors correctly in js plugins
This commit is contained in:
WithoutPants 2022-10-18 11:09:54 +11:00 committed by GitHub
parent bd44571a91
commit 4c286d7ab5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -122,7 +122,9 @@ func Start() error {
// register GQL handler with plugin cache // register GQL handler with plugin cache
// chain the visited plugin handler // chain the visited plugin handler
manager.GetInstance().PluginCache.RegisterGQLHandler(visitedPluginHandler(http.HandlerFunc(gqlHandlerFunc))) // also requires the dataloader middleware
gqlHandler := visitedPluginHandler(dataloaders.Middleware(http.HandlerFunc(gqlHandlerFunc)))
manager.GetInstance().PluginCache.RegisterGQLHandler(gqlHandler)
r.HandleFunc("/graphql", gqlHandlerFunc) r.HandleFunc("/graphql", gqlHandlerFunc)
r.HandleFunc("/playground", gqlPlayground.Handler("GraphQL playground", "/graphql")) r.HandleFunc("/playground", gqlPlayground.Handler("GraphQL playground", "/graphql"))

View File

@ -89,10 +89,11 @@ func gqlRequestFunc(ctx context.Context, vm *otto.Otto, cookie *http.Cookie, gql
throw(vm, fmt.Sprintf("could not unmarshal object %s: %s", output, err.Error())) throw(vm, fmt.Sprintf("could not unmarshal object %s: %s", output, err.Error()))
} }
retErr, hasErr := obj["error"] retErr, hasErr := obj["errors"]
if hasErr { if hasErr {
throw(vm, fmt.Sprintf("graphql error: %v", retErr)) errOut, _ := json.Marshal(retErr)
throw(vm, fmt.Sprintf("graphql error: %s", string(errOut)))
} }
v, err := vm.ToValue(obj["data"]) v, err := vm.ToValue(obj["data"])