MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / resolveExport

Function resolveExport

graphql/admin/export.go:32–98  ·  view source on GitHub ↗
(ctx context.Context, m schema.Mutation)

Source from the content-addressed store, hash-verified

30}
31
32func resolveExport(ctx context.Context, m schema.Mutation) (*resolve.Resolved, bool) {
33 glog.Info("Got export request through GraphQL admin API")
34
35 input, err := getExportInput(m)
36 if err != nil {
37 return resolve.EmptyResult(m, err), false
38 }
39
40 format := worker.DefaultExportFormat
41 if input.Format != "" {
42 format = worker.NormalizeExportFormat(input.Format)
43 if format == "" {
44 return resolve.EmptyResult(m, errors.Errorf("invalid export format: %v", input.Format)), false
45 }
46 }
47
48 validateAndGetNs := func(inputNs int64) (uint64, error) {
49 ns, err := x.ExtractNamespace(ctx)
50 if err != nil {
51 return 0, err
52 }
53 if input.Namespace == notSet {
54 // If namespace parameter is not set, use the namespace from the context.
55 return ns, nil
56 }
57 switch ns {
58 case x.RootNamespace:
59 if input.Namespace < 0 { // export all namespaces.
60 return math.MaxUint64, nil
61 }
62 return uint64(inputNs), nil
63 default:
64 if input.Namespace != notSet && uint64(input.Namespace) != ns {
65 return 0, errors.Errorf("not allowed to export namespace %#x", input.Namespace)
66 }
67 }
68 return ns, nil
69 }
70
71 var exportNs uint64
72 if exportNs, err = validateAndGetNs(input.Namespace); err != nil {
73 return resolve.EmptyResult(m, err), false
74 }
75
76 req := &pb.ExportRequest{
77 Format: format,
78 Namespace: exportNs,
79 Destination: input.Destination,
80 AccessKey: input.AccessKey,
81 SecretKey: input.SecretKey,
82 SessionToken: input.SessionToken,
83 Anonymous: input.Anonymous,
84 }
85 taskId, err := worker.Tasks.Enqueue(req)
86 if err != nil {
87 return resolve.EmptyResult(m, err), false
88 }
89

Callers

nothing calls this directly

Calls 10

EmptyResultFunction · 0.92
NormalizeExportFormatFunction · 0.92
ExtractNamespaceFunction · 0.92
DataResultFunction · 0.92
getExportInputFunction · 0.85
responseFunction · 0.85
InfoMethod · 0.80
EnqueueMethod · 0.80
NameMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected