| 604 | } |
| 605 | |
| 606 | func ToExportKvList(pk x.ParsedKey, pl *posting.List, in *pb.ExportRequest) (*bpb.KVList, error) { |
| 607 | e := &exporter{ |
| 608 | readTs: in.ReadTs, |
| 609 | uid: pk.Uid, |
| 610 | namespace: x.ParseNamespace(pk.Attr), |
| 611 | attr: x.ParseAttr(pk.Attr), |
| 612 | pl: pl, |
| 613 | } |
| 614 | |
| 615 | emptyList := &bpb.KVList{} |
| 616 | switch { |
| 617 | // These predicates are not required in the export data. |
| 618 | case e.attr == "dgraph.graphql.xid": |
| 619 | case e.attr == "dgraph.drop.op": |
| 620 | case e.attr == "dgraph.graphql.p_query": |
| 621 | |
| 622 | case pk.IsData() && e.attr == "dgraph.graphql.schema": |
| 623 | // Export the graphql schema. |
| 624 | vals, err := pl.AllValues(in.ReadTs) |
| 625 | if err != nil { |
| 626 | return emptyList, errors.Wrapf(err, "cannot read value of GraphQL schema") |
| 627 | } |
| 628 | // if the GraphQL schema node was deleted with S * * delete mutation, |
| 629 | // then the data key will be overwritten with nil value. |
| 630 | // So, just skip exporting it as there will be no value for this data key. |
| 631 | if len(vals) == 0 { |
| 632 | return emptyList, nil |
| 633 | } |
| 634 | // Give an error only if we find more than one value for the schema. |
| 635 | if len(vals) > 1 { |
| 636 | return emptyList, errors.Errorf("found multiple values for the GraphQL schema") |
| 637 | } |
| 638 | val, ok := vals[0].Value.([]byte) |
| 639 | if !ok { |
| 640 | return emptyList, errors.Errorf("cannot convert value of GraphQL schema to byte array") |
| 641 | } |
| 642 | |
| 643 | exported := x.ExportedGQLSchema{ |
| 644 | Namespace: e.namespace, |
| 645 | Schema: string(val), |
| 646 | } |
| 647 | if val, err = json.Marshal(exported); err != nil { |
| 648 | return emptyList, errors.Wrapf(err, "Error marshalling GraphQL schema to json") |
| 649 | } |
| 650 | kv := &bpb.KV{ |
| 651 | Value: val, |
| 652 | Version: 2, // GraphQL schema value |
| 653 | } |
| 654 | return listWrap(kv), nil |
| 655 | |
| 656 | // below predicates no longer exist internally starting v21.03 but leaving them here |
| 657 | // so that users with a binary with version >= 21.03 can export data from a version < 21.03 |
| 658 | // without this internal data showing up. |
| 659 | case e.attr == "dgraph.cors": |
| 660 | case e.attr == "dgraph.graphql.schema_created_at": |
| 661 | case e.attr == "dgraph.graphql.schema_history": |
| 662 | case e.attr == "dgraph.graphql.p_sha256hash": |
| 663 | |