MCPcopy
hub / github.com/dgraph-io/dgraph / getSchema

Function getSchema

worker/schema.go:33–69  ·  view source on GitHub ↗

getSchema iterates over all predicates and populates the asked fields, if list of predicates is not specified, then all the predicates belonging to the group are returned

(ctx context.Context, s *pb.SchemaRequest)

Source from the content-addressed store, hash-verified

31// predicates is not specified, then all the predicates belonging to the group
32// are returned
33func getSchema(ctx context.Context, s *pb.SchemaRequest) (*pb.SchemaResult, error) {
34 _, span := otel.Tracer("").Start(ctx, "worker.getSchema")
35 defer span.End()
36
37 var result pb.SchemaResult
38 var predicates []string
39 var fields []string
40 if len(s.Predicates) > 0 {
41 predicates = s.Predicates
42 } else {
43 predicates = schema.State().Predicates()
44 }
45 if len(s.Fields) > 0 {
46 fields = s.Fields
47 } else {
48 fields = []string{"type", "index", "tokenizer", "reverse", "count", "list", "upsert", "unique",
49 "lang", "noconflict", "vector_specs"}
50 }
51
52 myGid := groups().groupId()
53 for _, attr := range predicates {
54 // This can happen after a predicate is moved. We don't delete predicate from schema state
55 // immediately. So lets ignore this predicate.
56 gid, err := groups().BelongsToReadOnly(attr, 0)
57 if err != nil {
58 return nil, err
59 }
60 if myGid != gid {
61 continue
62 }
63
64 if schemaNode := populateSchema(attr, fields); schemaNode != nil {
65 result.Schema = append(result.Schema, schemaNode)
66 }
67 }
68 return &result, nil
69}
70
71// populateSchema returns the information of asked fields for given attribute
72func populateSchema(attr string, fields []string) *pb.SchemaNode {

Callers 2

getSchemaOverNetworkFunction · 0.70
SchemaMethod · 0.70

Calls 7

StateFunction · 0.92
groupsFunction · 0.85
populateSchemaFunction · 0.85
PredicatesMethod · 0.80
groupIdMethod · 0.80
BelongsToReadOnlyMethod · 0.80
StartMethod · 0.65

Tested by

no test coverage detected