(ctx context.Context, req ManagedQueryRequest)
| 118 | } |
| 119 | |
| 120 | func (m *managedQueryMux) ExecuteManagedQuery(ctx context.Context, req ManagedQueryRequest) (json.RawMessage, error) { |
| 121 | grouped := make(map[ManagedQueryHandler][]ManagedQueryRoot) |
| 122 | for _, root := range req.Roots { |
| 123 | handler := m.byTable[strings.ToLower(root.Table)] |
| 124 | if handler == nil { |
| 125 | return nil, fmt.Errorf("managed query table %q has no handler", root.Table) |
| 126 | } |
| 127 | grouped[handler] = append(grouped[handler], root) |
| 128 | } |
| 129 | |
| 130 | out := make(map[string]json.RawMessage, len(req.Roots)) |
| 131 | for _, handler := range m.handlers { |
| 132 | roots := grouped[handler] |
| 133 | if len(roots) == 0 { |
| 134 | continue |
| 135 | } |
| 136 | data, err := handler.ExecuteManagedQuery(ctx, ManagedQueryRequest{ |
| 137 | Database: req.Database, |
| 138 | Roots: roots, |
| 139 | }) |
| 140 | if err != nil { |
| 141 | return nil, err |
| 142 | } |
| 143 | var partial map[string]json.RawMessage |
| 144 | if err := json.Unmarshal(data, &partial); err != nil { |
| 145 | return nil, fmt.Errorf("managed query handler returned invalid JSON object: %w", err) |
| 146 | } |
| 147 | for key, value := range partial { |
| 148 | out[key] = value |
| 149 | } |
| 150 | } |
| 151 | return json.Marshal(out) |
| 152 | } |
| 153 | |
| 154 | func (m *managedMutationMux) ExecuteManagedMutation(ctx context.Context, req ManagedMutationRequest) (json.RawMessage, error) { |
| 155 | grouped := make(map[ManagedMutationHandler][]ManagedMutationRoot) |
nothing calls this directly
no test coverage detected