Skip to content

Commit 3751705

Browse files
committed
Add extensions to result
1 parent 4fd5030 commit 3751705

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

types.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,23 @@ import (
66

77
// type Schema interface{}
88

9+
// Result has the response, errors and extensions from the resolved schema
910
type Result struct {
10-
Data interface{} `json:"data"`
11-
Errors []gqlerrors.FormattedError `json:"errors,omitempty"`
11+
Data interface{} `json:"data"`
12+
Errors []gqlerrors.FormattedError `json:"errors,omitempty"`
13+
Extensions map[string]interface{} `json:"extensions,omitempty"`
1214
}
1315

16+
// HasErrors just a simple function to help you decide if the result has errors or not
1417
func (r *Result) HasErrors() bool {
1518
return len(r.Errors) > 0
1619
}
20+
21+
func (r *Result) addExtensionResults(p *ExecuteParams) {
22+
r.Extensions = map[string]interface{}{}
23+
for _, ext := range p.Schema.extensions {
24+
if ext.HasResult() {
25+
r.Extensions[ext.Name()] = ext.GetResult(p.Context)
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)