GetTypes processes the type requests and retrieves the desired types.
(ctx context.Context, req *pb.SchemaRequest)
| 236 | |
| 237 | // GetTypes processes the type requests and retrieves the desired types. |
| 238 | func GetTypes(ctx context.Context, req *pb.SchemaRequest) ([]*pb.TypeUpdate, error) { |
| 239 | if len(req.Types) == 0 && len(req.Predicates) > 0 { |
| 240 | return nil, nil |
| 241 | } |
| 242 | |
| 243 | var typeNames []string |
| 244 | var out []*pb.TypeUpdate |
| 245 | |
| 246 | if len(req.Types) == 0 { |
| 247 | typeNames = schema.State().Types() |
| 248 | } else { |
| 249 | typeNames = req.Types |
| 250 | } |
| 251 | |
| 252 | for _, name := range typeNames { |
| 253 | typeUpdate, found := schema.State().GetType(name) |
| 254 | if !found { |
| 255 | continue |
| 256 | } |
| 257 | out = append(out, proto.Clone(&typeUpdate).(*pb.TypeUpdate)) |
| 258 | } |
| 259 | |
| 260 | return out, nil |
| 261 | } |