@@ -112,14 +112,14 @@ wrappedReadPlan :: QualifiedIdentifier -> AppConfig -> SchemaCache -> ApiRequest
112
112
wrappedReadPlan identifier conf sCache apiRequest = do
113
113
rPlan <- readPlan identifier conf sCache apiRequest
114
114
binField <- mapLeft ApiRequestError $ binaryField conf (iAcceptMediaType apiRequest) Nothing rPlan
115
- return $ WrappedReadPlan rPlan SQL. Read $ mediaToAggregate (iAcceptMediaType apiRequest) binField Nothing
115
+ return $ WrappedReadPlan rPlan SQL. Read $ mediaToAggregate (iAcceptMediaType apiRequest) binField apiRequest
116
116
117
117
mutateReadPlan :: Mutation -> ApiRequest -> QualifiedIdentifier -> AppConfig -> SchemaCache -> Either Error MutateReadPlan
118
- mutateReadPlan mutation apiRequest@ ApiRequest {iPreferences = Preferences {preferRepresentation}} identifier conf sCache = do
118
+ mutateReadPlan mutation apiRequest identifier conf sCache = do
119
119
rPlan <- readPlan identifier conf sCache apiRequest
120
120
binField <- mapLeft ApiRequestError $ binaryField conf (iAcceptMediaType apiRequest) Nothing rPlan
121
121
mPlan <- mutatePlan mutation identifier apiRequest sCache rPlan
122
- return $ MutateReadPlan rPlan mPlan SQL. Write $ mediaToAggregate (iAcceptMediaType apiRequest) binField ( Just preferRepresentation)
122
+ return $ MutateReadPlan rPlan mPlan SQL. Write $ mediaToAggregate (iAcceptMediaType apiRequest) binField apiRequest
123
123
124
124
callReadPlan :: QualifiedIdentifier -> AppConfig -> SchemaCache -> ApiRequest -> InvokeMethod -> Either Error CallReadPlan
125
125
callReadPlan identifier conf sCache apiRequest invMethod = do
@@ -144,7 +144,7 @@ callReadPlan identifier conf sCache apiRequest invMethod = do
144
144
(InvPost , Routine. Volatile ) -> SQL. Write
145
145
cPlan = callPlan proc apiRequest paramKeys args rPlan
146
146
binField <- mapLeft ApiRequestError $ binaryField conf (iAcceptMediaType apiRequest) (Just proc ) rPlan
147
- return $ CallReadPlan rPlan cPlan txMode proc $ mediaToAggregate (iAcceptMediaType apiRequest) binField Nothing
147
+ return $ CallReadPlan rPlan cPlan txMode proc $ mediaToAggregate (iAcceptMediaType apiRequest) binField apiRequest
148
148
where
149
149
Preferences {.. } = iPreferences apiRequest
150
150
qsParams' = QueryParams. qsParams (iQueryParams apiRequest)
@@ -839,10 +839,10 @@ binaryField AppConfig{configRawMediaTypes} acceptMediaType proc rpTree
839
839
fstFieldName (Node ReadPlan {select= [(CoercibleField {cfName= fld, cfJsonPath= [] }, _, _)]} [] ) = Just fld
840
840
fstFieldName _ = Nothing
841
841
842
- mediaToAggregate :: MediaType -> Maybe FieldName -> Maybe PreferRepresentation -> ResultAggregate
843
- mediaToAggregate mt binField rep =
844
- if rep == Just HeadersOnly || rep == Just None
845
- then NoAgg
842
+
843
+ mediaToAggregate :: MediaType -> Maybe FieldName -> ApiRequest -> ResultAggregate
844
+ mediaToAggregate mt binField apiReq @ ApiRequest {iAction = act, iPreferences = Preferences {preferRepresentation = rep}} =
845
+ if noAgg then NoAgg
846
846
else case mt of
847
847
MTApplicationJSON -> BuiltinAggJson
848
848
MTSingularJSON -> BuiltinAggSingleJson
@@ -861,4 +861,10 @@ mediaToAggregate mt binField rep =
861
861
-- Doing `Accept: application/vnd.pgrst.plan; for="application/vnd.pgrst.plan"` doesn't make sense, so we just empty the body.
862
862
-- TODO: fail instead to be more strict
863
863
MTPlan (MTPlan {}) _ _ -> NoAgg
864
- MTPlan media _ _ -> mediaToAggregate media binField rep
864
+ MTPlan media _ _ -> mediaToAggregate media binField apiReq
865
+ where
866
+ noAgg = case act of
867
+ ActionMutate _ -> rep == HeadersOnly || rep == None
868
+ ActionRead _isHead -> _isHead -- no need for an aggregate on HEAD https://github.com/PostgREST/postgrest/issues/2849
869
+ ActionInvoke invMethod -> invMethod == InvHead
870
+ _ -> False
0 commit comments