Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
fix: skip calling the policy agent if there are no fields that need t…
Browse files Browse the repository at this point in the history
…o be checked.
  • Loading branch information
chirino committed Jul 23, 2020
1 parent e7f8424 commit 59cc58b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/gateway/policyagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func initPolicyAgent(config Config, gateway *Gateway) error {
return err
}

fields := toPolicyCheckFields(gateway.Schema, doc, op)
if len(fields) == 0 {
return nil
}

r := getHttpRequest(request.Context)
checkRequest := &proto.CheckRequest{
Source: &proto.Source{
Expand All @@ -66,7 +71,7 @@ func initPolicyAgent(config Config, gateway *Gateway) error {
Headers: toPolicyCheckHeaders(r.Header),
},
Graphql: &proto.GraphQL{
Fields: toPolicyCheckFields(gateway.Schema, doc, op),
Fields: fields,
},
}

Expand All @@ -86,7 +91,6 @@ func initPolicyAgent(config Config, gateway *Gateway) error {
if len(checkResponse.Fields) > 0 {
request.Context = context.WithValue(request.GetContext(), checkResponseFieldsKey, checkResponse.Fields)
}

return nil
}
gateway.Validate = func(doc *schema.QueryDocument, maxDepth int) error {
Expand Down

0 comments on commit 59cc58b

Please sign in to comment.