@@ -219,6 +219,65 @@ func TestFallbackErrors(t *testing.T) {
219219 })
220220}
221221
222+ func TestAllowedExtensions (t * testing.T ) {
223+ t .Parallel ()
224+
225+ t .Run ("in wrapped mode, only allowed extensions should be included in the propagated error" , func (t * testing.T ) {
226+ testenv .Run (t , & testenv.Config {
227+ ModifySubgraphErrorPropagation : func (cfg * config.SubgraphErrorPropagationConfiguration ) {
228+ cfg .Enabled = true
229+ cfg .Mode = config .SubgraphErrorPropagationModeWrapped
230+ cfg .AllowedExtensionFields = []string {"allowed" }
231+ },
232+ Subgraphs : testenv.SubgraphsConfig {
233+ Employees : testenv.SubgraphConfig {
234+ Middleware : func (handler http.Handler ) http.Handler {
235+ return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
236+ w .Header ().Set ("Content-Type" , "application/json" )
237+ w .WriteHeader (http .StatusForbidden )
238+ _ , wErr := w .Write ([]byte (`{"errors":[{"message":"Unauthorized","extensions":{"allowed":"allowed","notAllowed":"notAllowed"}}]}` ))
239+ require .NoError (t , wErr )
240+ })
241+ },
242+ },
243+ },
244+ }, func (t * testing.T , xEnv * testenv.Environment ) {
245+ res := xEnv .MakeGraphQLRequestOK (testenv.GraphQLRequest {
246+ Query : `{ employees { id } }` ,
247+ })
248+ require .Equal (t , `{"errors":[{"message":"Failed to fetch from Subgraph 'employees'.","extensions":{"errors":[{"message":"Unauthorized","extensions":{"allowed":"allowed"}}],"statusCode":403}}],"data":{"employees":null}}` , res .Body )
249+ })
250+ })
251+
252+ t .Run ("in passthrough mode, all extensions should be included in the propagated error" , func (t * testing.T ) {
253+ testenv .Run (t , & testenv.Config {
254+ ModifySubgraphErrorPropagation : func (cfg * config.SubgraphErrorPropagationConfiguration ) {
255+ cfg .Enabled = true
256+ cfg .Mode = config .SubgraphErrorPropagationModePassthrough
257+ cfg .AllowedExtensionFields = []string {"allowed" }
258+ },
259+ Subgraphs : testenv.SubgraphsConfig {
260+ Employees : testenv.SubgraphConfig {
261+ Middleware : func (handler http.Handler ) http.Handler {
262+ return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
263+ w .Header ().Set ("Content-Type" , "application/json" )
264+ w .WriteHeader (http .StatusForbidden )
265+ _ , wErr := w .Write ([]byte (`{"errors":[{"message":"Unauthorized","extensions":{"allowed":"allowed","notAllowed":"notAllowed"}}]}` ))
266+ require .NoError (t , wErr )
267+ })
268+ },
269+ },
270+ },
271+ }, func (t * testing.T , xEnv * testenv.Environment ) {
272+ res := xEnv .MakeGraphQLRequestOK (testenv.GraphQLRequest {
273+ Query : `{ employees { id } }` ,
274+ })
275+ require .Equal (t , `{"errors":[{"message":"Unauthorized","extensions":{"allowed":"allowed","notAllowed":"notAllowed","statusCode":403}}],"data":{"employees":null}}` , res .Body )
276+ })
277+ })
278+
279+ }
280+
222281func TestErrorPropagation (t * testing.T ) {
223282 t .Parallel ()
224283
0 commit comments