dgraphapi

package
v25.0.0-split-vector3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultUser     = "groot"
	DefaultPassword = "password"
)

Variables

This section is empty.

Functions

func CompareJSON

func CompareJSON(want, got string) error

CompareJSON compares two JSON objects (passed as strings).

func DoReq

func DoReq(req *http.Request) ([]byte, error)

func GenerateRandomVector

func GenerateRandomVector(size int) []float32

func GenerateRandomVectors

func GenerateRandomVectors(lowerLimit, uppermLimit, vectorSize int, label string) (string, [][]float32)

func GetFullSchemaHTTPResponse

func GetFullSchemaHTTPResponse(opts SchemaOptions) string

GetFullSchemaHTTPResponse returns a string representation of the HTTP response returned by the full schema{} query. It uses the user provided predicates and types along with the initial internal schema to generate the string. Example response looks like:

{
	"data": {
		"schema": [ ... ],
		"types": [ ... ]
	}
}

func GetFullSchemaJSON

func GetFullSchemaJSON(opts SchemaOptions) string

GetFullSchemaJSON returns a string representation of the JSON object returned by the full schema{} query. It uses the user provided predicates and types along with the initial internal schema to generate the string. Example response looks like:

{
	"schema": [ ... ],
	"types": [ ... ]
}

func GetInternalPreds

func GetInternalPreds(excludeAclPreds bool) string

func GetInternalTypes

func GetInternalTypes(excludeAclTypes bool) string

func IsHigherVersion

func IsHigherVersion(higher, lower, repoDir string) (bool, error)

IsHigherVersion checks whether "higher" is the higher version compared to "lower"

func PollTillPassOrTimeout

func PollTillPassOrTimeout(gcli *GrpcClient, query, want string, timeout time.Duration) error

func UnmarshalVectorResp

func UnmarshalVectorResp(resp *api.Response) ([][]float32, error)

func WaitForRestore

func WaitForRestore(c Cluster) error

WaitForRestore waits for restore to complete on all alphas

Types

type AclGroup

type AclGroup struct {
	Name  string    `json:"name"`
	Rules []AclRule `json:"rules"`
}

type AclRule

type AclRule struct {
	Predicate  string `json:"predicate"`
	Permission int32  `json:"permission"`
}

type Cluster

type Cluster interface {
	Client() (*GrpcClient, func(), error)
	HTTPClient() (*HTTPClient, error)
	AlphasHealth() ([]string, error)
	AlphasLogs() ([]string, error)
	AssignUids(gc *dgo.Dgraph, num uint64) error
	GetVersion() string
	GetEncKeyPath() (string, error)
	GetRepoDir() (string, error)
}

type GraphQLParams

type GraphQLParams struct {
	Query      string                    `json:"query"`
	Variables  map[string]interface{}    `json:"variables"`
	Extensions *schema.RequestExtensions `json:"extensions,omitempty"`
}

GraphQLParams are used for making graphql requests to dgraph

type GraphQLResponse

type GraphQLResponse struct {
	Data       json.RawMessage        `json:"data,omitempty"`
	Errors     x.GqlErrorList         `json:"errors,omitempty"`
	Code       string                 `json:"code"`
	Extensions map[string]interface{} `json:"extensions,omitempty"`
}

type GrpcClient

type GrpcClient struct {
	*dgo.Dgraph
}

func (*GrpcClient) DropAll

func (gc *GrpcClient) DropAll() error

DropAll drops all the data in the db

func (*GrpcClient) DropPredicate

func (gc *GrpcClient) DropPredicate(pred string) error

DropPredicate drops the predicate from the data in the db

func (*GrpcClient) Mutate

func (gc *GrpcClient) Mutate(mu *api.Mutation) (*api.Response, error)

Mutate performs a given mutation in a txn

func (*GrpcClient) Query

func (gc *GrpcClient) Query(query string) (*api.Response, error)

Query performa a given query in a new txn

func (*GrpcClient) QueryMultipleVectorsUsingSimilarTo

func (gc *GrpcClient) QueryMultipleVectorsUsingSimilarTo(vector []float32, pred string, topK int) ([][]float32, error)

func (*GrpcClient) QuerySingleVectorsUsingUid

func (gc *GrpcClient) QuerySingleVectorsUsingUid(uid, pred string) ([][]float32, error)

func (*GrpcClient) SetupSchema

func (gc *GrpcClient) SetupSchema(dbSchema string) error

SetupSchema sets up DQL schema

func (*GrpcClient) Upsert

func (gc *GrpcClient) Upsert(query string, mu *api.Mutation) (*api.Response, error)

type HTTPClient

type HTTPClient struct {
	*HttpToken
	// contains filtered or unexported fields
}

HTTPClient allows doing operations on Dgraph over http

func GetHttpClient

func GetHttpClient(alphaUrl, zeroUrl string) (*HTTPClient, error)

func (*HTTPClient) AddNamespace

func (hc *HTTPClient) AddNamespace() (uint64, error)

func (*HTTPClient) AddRulesToGroup

func (hc *HTTPClient) AddRulesToGroup(group string, rules []AclRule, newGroup bool) error

func (*HTTPClient) AddUserToGroup

func (hc *HTTPClient) AddUserToGroup(userName, group string) error

func (*HTTPClient) Backup

func (hc *HTTPClient) Backup(c Cluster, forceFull bool, backupPath string) error

Backup creates a backup of dgraph at a given path

func (*HTTPClient) CreateGroup

func (hc *HTTPClient) CreateGroup(name string) (string, error)

func (*HTTPClient) CreateGroupWithRules

func (hc *HTTPClient) CreateGroupWithRules(name string, rules []AclRule) (*AclGroup, error)

func (*HTTPClient) CreateUser

func (hc *HTTPClient) CreateUser(username, password string) (string, error)

func (*HTTPClient) DeleteGroup

func (hc *HTTPClient) DeleteGroup(name string) error

func (*HTTPClient) DeleteNamespace

func (hc *HTTPClient) DeleteNamespace(nsID uint64) (uint64, error)

func (*HTTPClient) DeleteUser

func (hc *HTTPClient) DeleteUser(username string) error

func (*HTTPClient) Export

func (hc *HTTPClient) Export(dest, format string, namespace int) error

func (*HTTPClient) GetAlphaState

func (hc *HTTPClient) GetAlphaState() ([]byte, error)

func (*HTTPClient) GetCurrentSnapshotTs

func (hc *HTTPClient) GetCurrentSnapshotTs(group uint64) (uint64, error)

func (*HTTPClient) GetCurrentUser

func (hc *HTTPClient) GetCurrentUser() (string, error)

func (*HTTPClient) GetZeroState

func (hc *HTTPClient) GetZeroState() (*LicenseResponse, error)

func (*HTTPClient) HealthForInstance

func (hc *HTTPClient) HealthForInstance() ([]byte, error)

func (*HTTPClient) ListNamespaces

func (hc *HTTPClient) ListNamespaces() ([]uint64, error)

func (*HTTPClient) LoginIntoNamespace

func (hc *HTTPClient) LoginIntoNamespace(user, password string, ns uint64) error

func (*HTTPClient) LoginIntoNamespaceV20

func (hc *HTTPClient) LoginIntoNamespaceV20(user, password string) error

func (*HTTPClient) LoginUsingToken

func (hc *HTTPClient) LoginUsingToken(ns uint64) error

func (*HTTPClient) Mutate

func (hc *HTTPClient) Mutate(mutation string, commitNow bool) ([]byte, error)

func (*HTTPClient) PostDqlQuery

func (hc *HTTPClient) PostDqlQuery(query string) ([]byte, error)

func (*HTTPClient) PostPersistentQuery

func (hc *HTTPClient) PostPersistentQuery(query, sha string) ([]byte, error)

PostPersistentQuery stores a persisted query

func (*HTTPClient) RemovePredicateFromGroup

func (hc *HTTPClient) RemovePredicateFromGroup(group, predicate string) error

func (*HTTPClient) RemoveUserFromGroup

func (hc *HTTPClient) RemoveUserFromGroup(userName, groupName string) error

func (*HTTPClient) ResetPassword

func (hc *HTTPClient) ResetPassword(userID, newPass string, nsID uint64) (string, error)

func (*HTTPClient) Restore

func (hc *HTTPClient) Restore(c Cluster, backupPath string,
	backupId string, incrFrom, backupNum int) error

Restore performs restore on Dgraph cluster from the given path to backup

func (*HTTPClient) RestoreTenant

func (hc *HTTPClient) RestoreTenant(c Cluster, backupPath string, backupId string,
	incrFrom, backupNum int, fromNamespace uint64) error

RestoreTenant restore specific namespace

func (*HTTPClient) RunGraphqlQuery

func (hc *HTTPClient) RunGraphqlQuery(params GraphQLParams, admin bool) ([]byte, error)

RunGraphqlQuery makes a query to graphql (or admin) endpoint

func (*HTTPClient) UpdateGQLSchema

func (hc *HTTPClient) UpdateGQLSchema(sch string) error

UpdateGQLSchema updates graphql schema for a given HTTP client

func (*HTTPClient) UpdateGroup

func (hc *HTTPClient) UpdateGroup(name string, setRules []AclRule, removeRules []string) (*AclGroup, error)

func (*HTTPClient) WaitForSnapshot

func (hc *HTTPClient) WaitForSnapshot(group, prevSnapshotTs uint64) (uint64, error)

func (*HTTPClient) WaitForTask

func (hc *HTTPClient) WaitForTask(taskId string) error

WaitForTask waits for the task to finish

type HttpToken

type HttpToken struct {
	UserId       string
	Password     string
	AccessJwt    string
	RefreshToken string
}

HttpToken stores credentials for making HTTP request

type LicenseResponse

type LicenseResponse struct {
	Data       json.RawMessage        `json:"data,omitempty"`
	Errors     x.GqlErrorList         `json:"errors,omitempty"`
	Code       string                 `json:"code"`
	Extensions map[string]interface{} `json:"license,omitempty"`
}

type SchemaOptions

type SchemaOptions struct {
	UserPreds        string
	UserTypes        string
	ExcludeAclSchema bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL