Skip to content

Commit 9f3d5dc

Browse files
authored
Rename v25 APIs to v2 APIs (#256)
1 parent b5a5134 commit 9f3d5dc

File tree

15 files changed

+502
-504
lines changed

15 files changed

+502
-504
lines changed

.trunk/trunk.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ lint:
2525
- linters: [ALL]
2626
paths:
2727
- protos/api/*.pb.go
28-
- protos/api.v25/*.pb.go
28+
- protos/api.v2/*.pb.go
2929
enabled:
3030
3131

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repository.**
1414
## Table of contents
1515

1616
- [Supported Versions](#supported-versions)
17-
- [v25 APIs](#v25-apis)
17+
- [v2 APIs](#v2-apis)
1818
- [Connection Strings](#connection-strings)
1919
- [Advanced Client Creation](#advanced-client-creation)
2020
- [Connecting To Dgraph Cloud](#connecting-to-dgraph-cloud)
@@ -59,7 +59,7 @@ version of this client and their corresponding import paths.
5959
| dgraph 25.X.Y | dgo 240.X.Y | "github.com/dgraph-io/dgo/v240" |
6060
| dgraph 25.X.Y | dgo 250.X.Y | "github.com/dgraph-io/dgo/v250" |
6161

62-
## v25 APIs
62+
## v2 APIs
6363

6464
These are _experimental_ APIs that we are still making changes to. If you have any feedback, please
6565
let us know either on Discord or GitHub.
@@ -276,7 +276,7 @@ queryDQL := `{
276276
age
277277
}
278278
}`
279-
resp, err = client.RunDQL(context.TODO(), dgo.RootNamespace, queryDQL, dgo.WithResponseFormat(api_v25.RespFormat_RDF))
279+
resp, err = client.RunDQL(context.TODO(), dgo.RootNamespace, queryDQL, dgo.WithResponseFormat(api_v2.RespFormat_RDF))
280280
// Handle error
281281
fmt.Printf("%s\n", resp.QueryResult)
282282
```

alter_v25.go renamed to alterv2.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,59 @@ package dgo
88
import (
99
"context"
1010

11-
apiv25 "github.com/dgraph-io/dgo/v250/protos/api.v25"
11+
apiv2 "github.com/dgraph-io/dgo/v250/protos/api.v2"
1212
)
1313

1414
func (d *Dgraph) DropAllNamespaces(ctx context.Context) error {
15-
req := &apiv25.AlterRequest{Op: apiv25.AlterOp_DROP_ALL}
15+
req := &apiv2.AlterRequest{Op: apiv2.AlterOp_DROP_ALL}
1616
return d.doAlter(ctx, req)
1717
}
1818

1919
func (d *Dgraph) DropAll(ctx context.Context, nsName string) error {
20-
req := &apiv25.AlterRequest{
21-
Op: apiv25.AlterOp_DROP_ALL_IN_NS,
20+
req := &apiv2.AlterRequest{
21+
Op: apiv2.AlterOp_DROP_ALL_IN_NS,
2222
NsName: nsName,
2323
}
2424
return d.doAlter(ctx, req)
2525
}
2626

2727
func (d *Dgraph) DropData(ctx context.Context, nsName string) error {
28-
req := &apiv25.AlterRequest{
29-
Op: apiv25.AlterOp_DROP_DATA_IN_NS,
28+
req := &apiv2.AlterRequest{
29+
Op: apiv2.AlterOp_DROP_DATA_IN_NS,
3030
NsName: nsName,
3131
}
3232
return d.doAlter(ctx, req)
3333
}
3434

3535
func (d *Dgraph) DropPredicate(ctx context.Context, nsName, predicate string) error {
36-
req := &apiv25.AlterRequest{
37-
Op: apiv25.AlterOp_DROP_PREDICATE_IN_NS,
36+
req := &apiv2.AlterRequest{
37+
Op: apiv2.AlterOp_DROP_PREDICATE_IN_NS,
3838
NsName: nsName,
3939
PredicateToDrop: predicate,
4040
}
4141
return d.doAlter(ctx, req)
4242
}
4343

4444
func (d *Dgraph) DropType(ctx context.Context, nsName, typeName string) error {
45-
req := &apiv25.AlterRequest{
46-
Op: apiv25.AlterOp_DROP_TYPE_IN_NS,
45+
req := &apiv2.AlterRequest{
46+
Op: apiv2.AlterOp_DROP_TYPE_IN_NS,
4747
NsName: nsName,
4848
TypeToDrop: typeName,
4949
}
5050
return d.doAlter(ctx, req)
5151
}
5252

5353
func (d *Dgraph) SetSchema(ctx context.Context, nsName string, schema string) error {
54-
req := &apiv25.AlterRequest{
55-
Op: apiv25.AlterOp_SCHEMA_IN_NS,
54+
req := &apiv2.AlterRequest{
55+
Op: apiv2.AlterOp_SCHEMA_IN_NS,
5656
NsName: nsName,
5757
Schema: schema,
5858
}
5959
return d.doAlter(ctx, req)
6060
}
6161

62-
func (d *Dgraph) doAlter(ctx context.Context, req *apiv25.AlterRequest) error {
63-
_, err := doWithRetryLogin(ctx, d, func(dc apiv25.DgraphClient) (*apiv25.AlterResponse, error) {
62+
func (d *Dgraph) doAlter(ctx context.Context, req *apiv2.AlterRequest) error {
63+
_, err := doWithRetryLogin(ctx, d, func(dc apiv2.DgraphClient) (*apiv2.AlterResponse, error) {
6464
return dc.Alter(d.getContext(ctx), req)
6565
})
6666
return err

client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"google.golang.org/protobuf/proto"
2424

2525
"github.com/dgraph-io/dgo/v250/protos/api"
26-
apiv25 "github.com/dgraph-io/dgo/v250/protos/api.v25"
26+
apiv2 "github.com/dgraph-io/dgo/v250/protos/api.v2"
2727
)
2828

2929
const (
@@ -40,7 +40,7 @@ type Dgraph struct {
4040

4141
conns []*grpc.ClientConn
4242
dc []api.DgraphClient
43-
dcv25 []apiv25.DgraphClient
43+
dcv2 []apiv2.DgraphClient
4444
}
4545

4646
type authCreds struct {
@@ -65,12 +65,12 @@ func (a *authCreds) RequireTransportSecurity() bool {
6565
//
6666
// Deprecated: Use dgo.NewClient or dgo.Open instead.
6767
func NewDgraphClient(clients ...api.DgraphClient) *Dgraph {
68-
dcv25 := make([]apiv25.DgraphClient, len(clients))
68+
dcv2 := make([]apiv2.DgraphClient, len(clients))
6969
for i, client := range clients {
70-
dcv25[i] = apiv25.NewDgraphClient(api.GetConn(client))
70+
dcv2[i] = apiv2.NewDgraphClient(api.GetConn(client))
7171
}
7272

73-
d := &Dgraph{useV1: true, dc: clients, dcv25: dcv25}
73+
d := &Dgraph{useV1: true, dc: clients, dcv2: dcv2}
7474

7575
// we ignore the error here, because there is not much we can do about
7676
// the error. We want to make best effort to figure out what API to use.

client_v25.go renamed to clientv2.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"google.golang.org/grpc/status"
2222

2323
"github.com/dgraph-io/dgo/v250/protos/api"
24-
apiv25 "github.com/dgraph-io/dgo/v250/protos/api.v25"
24+
apiv2 "github.com/dgraph-io/dgo/v250/protos/api.v2"
2525
)
2626

2727
const (
@@ -107,7 +107,7 @@ func WithACLCreds(username, password string) ClientOption {
107107

108108
// WithResponseFormat sets the response format for queries. By default, the
109109
// response format is JSON. We can also specify RDF format.
110-
func WithResponseFormat(respFormat apiv25.RespFormat) TxnOption {
110+
func WithResponseFormat(respFormat apiv2.RespFormat) TxnOption {
111111
return func(o *txnOptions) error {
112112
o.respFormat = respFormat
113113
return nil
@@ -219,18 +219,18 @@ func NewRoundRobinClient(endpoints []string, opts ...ClientOption) (*Dgraph, err
219219

220220
conns := make([]*grpc.ClientConn, len(endpoints))
221221
dc := make([]api.DgraphClient, len(endpoints))
222-
dcv25 := make([]apiv25.DgraphClient, len(endpoints))
222+
dcv2 := make([]apiv2.DgraphClient, len(endpoints))
223223
for i, endpoint := range endpoints {
224224
conn, err := grpc.NewClient(endpoint, co.gopts...)
225225
if err != nil {
226226
return nil, fmt.Errorf("failed to connect to endpoint [%s]: %w", endpoint, err)
227227
}
228228
conns[i] = conn
229229
dc[i] = api.NewDgraphClient(conn)
230-
dcv25[i] = apiv25.NewDgraphClient(conn)
230+
dcv2[i] = apiv2.NewDgraphClient(conn)
231231
}
232232

233-
d := &Dgraph{dc: dc, dcv25: dcv25}
233+
d := &Dgraph{dc: dc, dcv2: dcv2}
234234
if err := d.ping(); err != nil {
235235
d.Close()
236236
return nil, err
@@ -265,8 +265,8 @@ func (d *Dgraph) signInUser(ctx context.Context, username, password string) erro
265265
d.jwtMutex.Lock()
266266
defer d.jwtMutex.Unlock()
267267

268-
dc := d.anyClientv25()
269-
req := &apiv25.SignInUserRequest{UserId: username, Password: password}
268+
dc := d.anyClientv2()
269+
req := &apiv2.SignInUserRequest{UserId: username, Password: password}
270270
resp, err := dc.SignInUser(ctx, req)
271271
if err != nil {
272272
return err
@@ -284,7 +284,7 @@ func (d *Dgraph) ping() error {
284284
// By default, we assume the server is using v1 API
285285
d.useV1 = true
286286

287-
if _, err := d.dcv25[0].Ping(ctx, nil); err != nil {
287+
if _, err := d.dcv2[0].Ping(ctx, nil); err != nil {
288288
if status.Code(err) != codes.Unimplemented {
289289
return fmt.Errorf("error pinging the database: %v", err)
290290
}
File renamed without changes.

ns_v25.go renamed to nsv2.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"errors"
1111
"math/rand"
1212

13-
apiv25 "github.com/dgraph-io/dgo/v250/protos/api.v25"
13+
apiv2 "github.com/dgraph-io/dgo/v250/protos/api.v2"
1414
)
1515

1616
const (
@@ -24,7 +24,7 @@ var (
2424
type txnOptions struct {
2525
readOnly bool
2626
bestEffort bool
27-
respFormat apiv25.RespFormat
27+
respFormat apiv2.RespFormat
2828
}
2929

3030
// TxnOption is a function that modifies the txn options.
@@ -64,58 +64,58 @@ func buildTxnOptions(opts ...TxnOption) (*txnOptions, error) {
6464
// RunDQL runs a DQL query in the given namespace. A DQL query could be a mutation
6565
// or a query or an upsert which is a combination of mutations and queries.
6666
func (d *Dgraph) RunDQL(ctx context.Context, nsName string, q string, opts ...TxnOption) (
67-
*apiv25.RunDQLResponse, error) {
67+
*apiv2.RunDQLResponse, error) {
6868

6969
return d.RunDQLWithVars(ctx, nsName, q, nil, opts...)
7070
}
7171

7272
// RunDQLWithVars is like RunDQL with variables.
7373
func (d *Dgraph) RunDQLWithVars(ctx context.Context, nsName string, q string,
74-
vars map[string]string, opts ...TxnOption) (*apiv25.RunDQLResponse, error) {
74+
vars map[string]string, opts ...TxnOption) (*apiv2.RunDQLResponse, error) {
7575

7676
topts, err := buildTxnOptions(opts...)
7777
if err != nil {
7878
return nil, err
7979
}
8080

81-
req := &apiv25.RunDQLRequest{NsName: nsName, DqlQuery: q, Vars: vars,
81+
req := &apiv2.RunDQLRequest{NsName: nsName, DqlQuery: q, Vars: vars,
8282
ReadOnly: topts.readOnly, BestEffort: topts.bestEffort, RespFormat: topts.respFormat}
83-
return doWithRetryLogin(ctx, d, func(dc apiv25.DgraphClient) (*apiv25.RunDQLResponse, error) {
83+
return doWithRetryLogin(ctx, d, func(dc apiv2.DgraphClient) (*apiv2.RunDQLResponse, error) {
8484
return dc.RunDQL(d.getContext(ctx), req)
8585
})
8686
}
8787

8888
// CreateNamespace creates a new namespace with the given name and password for groot user.
8989
func (d *Dgraph) CreateNamespace(ctx context.Context, name string) error {
90-
req := &apiv25.CreateNamespaceRequest{NsName: name}
91-
_, err := doWithRetryLogin(ctx, d, func(dc apiv25.DgraphClient) (*apiv25.CreateNamespaceResponse, error) {
90+
req := &apiv2.CreateNamespaceRequest{NsName: name}
91+
_, err := doWithRetryLogin(ctx, d, func(dc apiv2.DgraphClient) (*apiv2.CreateNamespaceResponse, error) {
9292
return dc.CreateNamespace(d.getContext(ctx), req)
9393
})
9494
return err
9595
}
9696

9797
// DropNamespace deletes the namespace with the given name.
9898
func (d *Dgraph) DropNamespace(ctx context.Context, name string) error {
99-
req := &apiv25.DropNamespaceRequest{NsName: name}
100-
_, err := doWithRetryLogin(ctx, d, func(dc apiv25.DgraphClient) (*apiv25.DropNamespaceResponse, error) {
99+
req := &apiv2.DropNamespaceRequest{NsName: name}
100+
_, err := doWithRetryLogin(ctx, d, func(dc apiv2.DgraphClient) (*apiv2.DropNamespaceResponse, error) {
101101
return dc.DropNamespace(d.getContext(ctx), req)
102102
})
103103
return err
104104
}
105105

106106
// RenameNamespace renames the namespace from the given name to the new name.
107107
func (d *Dgraph) RenameNamespace(ctx context.Context, from string, to string) error {
108-
req := &apiv25.UpdateNamespaceRequest{NsName: from, RenameToNs: to}
109-
_, err := doWithRetryLogin(ctx, d, func(dc apiv25.DgraphClient) (*apiv25.UpdateNamespaceResponse, error) {
108+
req := &apiv2.UpdateNamespaceRequest{NsName: from, RenameToNs: to}
109+
_, err := doWithRetryLogin(ctx, d, func(dc apiv2.DgraphClient) (*apiv2.UpdateNamespaceResponse, error) {
110110
return dc.UpdateNamespace(d.getContext(ctx), req)
111111
})
112112
return err
113113
}
114114

115115
// ListNamespaces returns a map of namespace names to their details.
116-
func (d *Dgraph) ListNamespaces(ctx context.Context) (map[string]*apiv25.Namespace, error) {
117-
resp, err := doWithRetryLogin(ctx, d, func(dc apiv25.DgraphClient) (*apiv25.ListNamespacesResponse, error) {
118-
return dc.ListNamespaces(d.getContext(ctx), &apiv25.ListNamespacesRequest{})
116+
func (d *Dgraph) ListNamespaces(ctx context.Context) (map[string]*apiv2.Namespace, error) {
117+
resp, err := doWithRetryLogin(ctx, d, func(dc apiv2.DgraphClient) (*apiv2.ListNamespacesResponse, error) {
118+
return dc.ListNamespaces(d.getContext(ctx), &apiv2.ListNamespacesRequest{})
119119
})
120120
if err != nil {
121121
return nil, err
@@ -124,19 +124,19 @@ func (d *Dgraph) ListNamespaces(ctx context.Context) (map[string]*apiv25.Namespa
124124
return resp.NsList, nil
125125
}
126126

127-
func (d *Dgraph) anyClientv25() apiv25.DgraphClient {
127+
func (d *Dgraph) anyClientv2() apiv2.DgraphClient {
128128
//nolint:gosec
129-
return d.dcv25[rand.Intn(len(d.dcv25))]
129+
return d.dcv2[rand.Intn(len(d.dcv2))]
130130
}
131131

132132
func doWithRetryLogin[T any](ctx context.Context, d *Dgraph,
133-
f func(dc apiv25.DgraphClient) (*T, error)) (*T, error) {
133+
f func(dc apiv2.DgraphClient) (*T, error)) (*T, error) {
134134

135135
if d.useV1 {
136136
return nil, ErrUnsupportedAPI
137137
}
138138

139-
dc := d.anyClientv25()
139+
dc := d.anyClientv2()
140140
resp, err := f(dc)
141141
if isJwtExpired(err) {
142142
if err := d.retryLogin(ctx); err != nil {

protos/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ patchContent := "package api\n\nimport (\n\tgrpc \"google.golang.org/grpc\"\n)\n
88
.PHONY: clean
99
clean:
1010
@rm -rf api && mkdir -p api
11-
@rm -rf api.v25 && mkdir -p api.v25
11+
@rm -rf api.v2 && mkdir -p api.v2
1212

1313
.PHONY: check
1414
check:
@@ -19,6 +19,6 @@ check:
1919
.PHONY: regenerate
2020
regenerate: check clean
2121
@protoc --go_out=api --go-grpc_out=api --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative api.proto
22-
@protoc --go_out=api.v25 --go-grpc_out=api.v25 --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative api.v25.proto
22+
@protoc --go_out=api.v2 --go-grpc_out=api.v2 --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative api.v2.proto
2323
@echo $(patchContent) > api/cc.go
2424
@echo Done.

protos/api.v25.proto renamed to protos/api.v2.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
syntax = "proto3";
1212

13-
package api.v25;
13+
package api.v2;
1414

15-
option go_package = "github.com/dgraph-io/dgo/v250/protos/api.v25";
15+
option go_package = "github.com/dgraph-io/dgo/v250/protos/api.v2";
1616

17-
option java_package = "io.dgraph.v25";
17+
option java_package = "io.dgraph.v2";
1818
option java_outer_classname = "DgraphProto";
1919

2020
service Dgraph {

0 commit comments

Comments
 (0)