Documentation
¶
Index ¶
- type ComputedPropertiesHandler
- type ComputedProperty
- type Dogma
- type IdentityProvider
- type IdentityProviderRequest
- type Model
- type ModelHandler
- type MutationVerifier
- type QueryFn
- type QueryHardener
- type QueryMiddleware
- type QueryRequest
- type QueryResponse
- type QueryVerifier
- type ResourceFilter
- type ResourceFilterProvider
- type Unauthorized
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ComputedPropertiesHandler ¶
type ComputedPropertiesHandler interface {
Prepare([]gql.GraphQuery) []gql.GraphQuery
Compute(context.Context, []gql.GraphQuery, map[string]interface{}) (resp map[string]interface{}, err error)
}
type ComputedProperty ¶
type Dogma ¶
type Dogma interface {
// NewTxn opens a new dgraph transaction and returns a new
// Dogma instance. If the Dogma instance didn't opena a
// transaction, everything is immediately commited.
NewTxn(ctx context.Context) Dogma
// Commit commits the dgraph transaction
Commit(ctx context.Context) error
// Discard discards the dgraph transaction
Discard(ctx context.Context)
// Query queries for the requested resources and stores them
// into the value pointed to by `in`. Therefore `in` needs to
// be a pointer. Also, the query response needs to match the
// inserted type, (such that the json result can be
// unmarshalled into `in`). The root query alias, or query
// name is ignored and the output is directly copied to the
// value pointed to by `in`. Nodes that have an edge to a
// `deletedAt` field are automatically filtered.
Query(ctx context.Context, queries []gql.GraphQuery, in interface{}) error
// QueryMultipleResults behaves similar to Dogma.Query and is useful
// when you expect multiple result objects, which is the case
// if you have multiple non-var queries, such as
//
// query {
// person (func: uid(0x01)) {
// uid
// name
// }
// office (func: uid(0x02)) {
// uid
// address
// }
// }
//
// as a result you could then use the following type:
//
// var input struct {
// Person struct {
// ID string `json:"uid"`
// Name string `json:"name"`
// } `json:"person"`
// Office struct {
// ID string `json:"uid"`
// Address string `json:"address"`
// } `json:'office"`
// }
QueryMultipleResults(ctx context.Context, queries []gql.GraphQuery, in interface{}) error
// Select allows for simple querying of entities and stores
// them into the value pointed to by `in`. Therefore `in`
// needs to be a pointer.
Select(ctx context.Context, ids []uint64, in interface{}, attributes ...gql.GraphQuery) error
// SelectSingle behaves the same as Select, but fetches only a single item
SelectSingle(ctx context.Context, id uint64, in interface{}, attributes ...gql.GraphQuery) error
// Update updates the value pointed to by `in`. Therefore `in`
// needs to be a pointer. Similar to a mutation in a GraphQL
// Environment you can query for the updated data using query
// provided by the `query` argument. If the type of `in` has
// dgx.Model as a promoted field, the ModifiedAt
// property is automatically updated.
Update(ctx context.Context, in interface{}, attributes ...gql.GraphQuery) error
// UpdateSingle behaves like Update but operators on a single entity
UpdateSingle(ctx context.Context, in interface{}, attributes ...gql.GraphQuery) error
// Create inserts the value pointed to by `in`. Therefore `in`
// needs to be a pointer. Similar to a mutation in a GraphQL
// Environment you can query for the inserted data using query
// provided by the `query` argument. If the type of `in` has
// dgx.Model as a promoted field, the CreatedAt and
// ModifedAt properties are automatically set.
Create(ctx context.Context, in interface{}, attributes ...gql.GraphQuery) error
// CreateSingle behaves like Create but operates on a single entity
CreateSingle(ctx context.Context, in interface{}, attributes ...gql.GraphQuery) error
// Delete requires the type of `in` to have dgx.Model
// as a promoted field. It sets the DeletedAt property to
// time.Now(), updates the value and exists. It does not
// delete the record from Dgraph.
Delete(ctx context.Context, in interface{}) error
// DeleteSingle behaves like Delete but operates on a single entity
DeleteSingle(ctx context.Context, in interface{}) error
}
Dogma (Dgraph Object Graph Mapping Architecture)
type IdentityProvider ¶
type Model ¶
type Model struct {
ID uint64 `json:"uid,omitempty" yaml:"uid"`
CreatedAt *time.Time `json:"createdAt,omitempty" yaml:"createdAt"`
DeletedAt *time.Time `json:"deletedAt,omitempty" yaml:"deletedAt"`
ModifiedAt *time.Time `json:"modifiedAt,omitempty" yaml:"modifiedAt"`
}
Model should be used as a promoted field in any business model entity
type ModelHandler ¶
type ModelHandler interface {
// UpdateModel sets the ModifiedAt and CreatedAt fields
// according to the state of the entity. If the ID field is
// not set, the entity is considered new and CreatedAt,
// ModifiedAt is set. If the ID is not set and all other
// fields are empty the entity is ignored. If any fields in
// addition to the ID field are set the ModifiedAt field is
// updated. The update is applied recursively.
UpdateModel(time.Time, interface{})
// SetDeletedAt sets the deleted field of any type that
// hosts `Model` as a promoted field.
SetDeletedAt(time.Time, interface{})
// FilterDeleted applies a filter to every node of the
// provided queries that automatically filters for any node
// that has the deletedAt field set.
FilterDeleted([]gql.GraphQuery) []gql.GraphQuery
}
ModelHandler provides functionality based on any type that includes `Model` as a promoted field. For internal usages only.
type MutationVerifier ¶
type MutationVerifier interface {
Verify(context.Context, QueryHardener, interface{}) (bool, error)
}
type QueryFn ¶
QueryFn is the function querying the dgraph database
type QueryHardener ¶
type QueryHardener interface {
Harden(ctx context.Context, identity uint64, queries []gql.GraphQuery) ([]gql.GraphQuery, error)
}
type QueryMiddleware ¶
QueryMiddleware allows modifying either the response or the queries when quering the dgraph database
type QueryRequest ¶
type QueryRequest struct {
Identity int `json:"identity"`
Queries []gql.GraphQuery `json:"queries"`
Alias string `json:"alias"`
Variables map[string]string `json:"variables"`
Proof map[int]gql.GraphQuery `json:"proof"`
Languages []string `json:"languages"`
}
func (QueryRequest) ProvideIdentity ¶
func (u QueryRequest) ProvideIdentity() uint64
func (QueryRequest) ProvideLanguages ¶
func (q QueryRequest) ProvideLanguages() []string
type QueryVerifier ¶
type QueryVerifier interface {
QueryAllowed(ctx context.Context, queries []gql.GraphQuery, userID int, proofs map[int]gql.GraphQuery) (bool, error)
}
type ResourceFilter ¶
type ResourceFilter struct {
Dependencies []ResourceFilter
Filter []gql.GraphQuery
}
type ResourceFilterProvider ¶
type Unauthorized ¶
type Unauthorized struct{}
func (Unauthorized) Error ¶
func (Unauthorized) Error() string
Source Files
¶
- dogma.go
- tools.go
Click to show internal directories.
Click to hide internal directories.
