Skip to content

Commit

Permalink
add index examples
Browse files Browse the repository at this point in the history
  • Loading branch information
autom8ter committed Dec 20, 2020
1 parent eaf68a3 commit 553c603
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.9.3
current_version = 0.10.0
commit = False
tag = False

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version := "0.9.3"
version := "0.10.0"

.DEFAULT_GOAL := help

Expand Down
79 changes: 75 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

git clone git@github.com:graphikDB/graphik.git

` docker pull graphikdb/graphik:v0.9.3`
` docker pull graphikdb/graphik:v0.10.0`

Graphik is a Backend as a Service implemented as an identity-aware, permissioned, persistant document/graph database & pubsub server written in Go.

Expand Down Expand Up @@ -180,8 +180,12 @@ message Connection {
- registered root users(see flags) bypass these authorizers
- authorizers are completely optional but highly recommended

#### Authorizers Examples
please note:

- setAuthorizers method overwrites all authorizers in the database
- authorizers may be listed with the getSchema method

#### Authorizers Examples

1) only allow access to the GetSchema method if the users email contains `coleman` AND their email is verified

Expand Down Expand Up @@ -221,13 +225,80 @@ mutation {
- indexes may be used to speed up queries that iterate over a large number of elements
- secondary indexes are completely optional but recommended

please note:

- setIndexes method overwrites all indexes in the database
- indexes may be listed with the getSchema method

#### Secondary Index Examples
Coming Soon

1) index documents of type `product` that have a price > 100

```graphql
mutation {
setIndexes(input: {
indexes: [{
name: "expensiveProducts"
gtype: "product"
expression: "int(this.attributes.price) > 100"
target_docs: true
target_connections: false
}]
})
}
```

you can search for the document within the new index like so:

```graphql
query {
searchDocs(where: {
gtype: "product"
limit: 1
index: "expensiveProducts"
}){
docs {
ref {
gid
gtype
}
attributes
}
}
}
```

```json
{
"data": {
"searchDocs": {
"docs": [
{
"ref": {
"gid": "1lw7gcc5yQ01YbLcsgMX0iz0Sgx",
"gtype": "product"
},
"attributes": {
"price": 101,
"title": "this is a product"
}
}
]
}
},
"extensions": {}
}
```

### Type Validators
- type validators are CEL expressions evaluated against a particular type of Doc or Connection to enforce custom constraints
- type validators are completely optional

please note:

- setTypeValidators overwrites all validators in the database
- validators may be listed with the getSchema method

#### Type Validator Examples

1) ensure all documents of type 'note' have a title
Expand Down Expand Up @@ -704,7 +775,7 @@ add this docker-compose.yml to ${pwd}:
version: '3.7'
services:
graphik:
image: graphikdb/graphik:v0.9.3
image: graphikdb/graphik:v0.10.0
env_file:
- .env
ports:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.7'
services:
graphik:
image: graphikdb/graphik:v0.9.3
image: graphikdb/graphik:v0.10.0
env_file:
- .env
ports:
Expand Down
2 changes: 1 addition & 1 deletion docs/index.doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ <h2 id="graphql-schema-definition" class="graphdoc-section__title slds-text-head
</a>
GraphQL Schema definition
</h2>
<code class="highlight"><ul class="code" style="padding-left:42px"><li><span class="keyword operator ts">type</span> <span class="identifier">Index</span> {</li><li></li><li><span class="tab"><span class="comment line"># name is the unique name of the index in the graph</span></span></li><li><span class="tab"><span class="meta">name</span>: <a class="support type" href="string.doc.html">String</a>! </span></li><li></li><li><span class="tab"><span class="comment line"># gtype is the type of object the validator will be applied to (ex: user)</span></span></li><li><span class="tab"><span class="meta">gtype</span>: <a class="support type" href="string.doc.html">String</a>! </span></li><li></li><li><span class="tab"><span class="comment line"># expression is a boolean CEL expression used to evaluate the doc/connection</span></span></li><li><span class="tab"><span class="meta">expression</span>: <a class="support type" href="string.doc.html">String</a>! </span></li><li></li><li><span class="tab"><span class="comment line"># if docs is true, this validator will be applied to documents.</span></span></li><li><span class="tab"><span class="meta">docs</span>: <a class="support type" href="boolean.doc.html">Boolean</a>! </span></li><li></li><li><span class="tab"><span class="comment line"># if docs is true, this validator will be applied to connections.</span></span></li><li><span class="tab"><span class="meta">connections</span>: <a class="support type" href="boolean.doc.html">Boolean</a>! </span></li><li>}</li></ul></code>
<code class="highlight"><ul class="code" style="padding-left:42px"><li><span class="keyword operator ts">type</span> <span class="identifier">Index</span> {</li><li></li><li><span class="tab"><span class="comment line"># name is the unique name of the index in the graph</span></span></li><li><span class="tab"><span class="meta">name</span>: <a class="support type" href="string.doc.html">String</a>! </span></li><li></li><li><span class="tab"><span class="comment line"># gtype is the type of object the index will be applied to (ex: user)</span></span></li><li><span class="tab"><span class="meta">gtype</span>: <a class="support type" href="string.doc.html">String</a>! </span></li><li></li><li><span class="tab"><span class="comment line"># expression is a boolean CEL expression used to evaluate the doc/connection</span></span></li><li><span class="tab"><span class="meta">expression</span>: <a class="support type" href="string.doc.html">String</a>! </span></li><li></li><li><span class="tab"><span class="comment line"># if target_docs is true, this index will be applied to documents.</span></span></li><li><span class="tab"><span class="meta">target_docs</span>: <a class="support type" href="boolean.doc.html">Boolean</a>! </span></li><li></li><li><span class="tab"><span class="comment line"># if target_connections is true, this index will be applied to connections.</span></span></li><li><span class="tab"><span class="meta">target_connections</span>: <a class="support type" href="boolean.doc.html">Boolean</a>! </span></li><li>}</li></ul></code>
</div>
</section>
<section>
Expand Down
2 changes: 1 addition & 1 deletion docs/indexinput.doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ <h2 id="graphql-schema-definition" class="graphdoc-section__title slds-text-head
</a>
GraphQL Schema definition
</h2>
<code class="highlight"><ul class="code" style="padding-left:42px"><li><span class="keyword operator ts">input</span> <span class="identifier">IndexInput</span> {</li><li><span class="tab"><li><span class="tab"><span class="comment line"># name is the unique name of the index in the graph</span></span></li><li><span class="tab"><span class="meta">name</span>: <a class="support type" href="string.doc.html">String</a>!</span></li></span></li><li><span class="tab"><li><span class="tab"><span class="comment line"># gtype is the type of object the validator will be applied to (ex: user)</span></span></li><li><span class="tab"><span class="meta">gtype</span>: <a class="support type" href="string.doc.html">String</a>!</span></li></span></li><li><span class="tab"><li><span class="tab"><span class="comment line"># expression is a boolean CEL expression used to evaluate the doc/connection</span></span></li><li><span class="tab"><span class="meta">expression</span>: <a class="support type" href="string.doc.html">String</a>!</span></li></span></li><li><span class="tab"><li><span class="tab"><span class="comment line"># if docs is true, this validator will be applied to documents.</span></span></li><li><span class="tab"><span class="meta">docs</span>: <a class="support type" href="boolean.doc.html">Boolean</a>!</span></li></span></li><li><span class="tab"><li><span class="tab"><span class="comment line"># if connections is true, this validator will be applied to connections.</span></span></li><li><span class="tab"><span class="meta">connections</span>: <a class="support type" href="boolean.doc.html">Boolean</a>!</span></li></span></li><li>}</li></ul></code>
<code class="highlight"><ul class="code" style="padding-left:42px"><li><span class="keyword operator ts">input</span> <span class="identifier">IndexInput</span> {</li><li><span class="tab"><li><span class="tab"><span class="comment line"># name is the unique name of the index in the graph</span></span></li><li><span class="tab"><span class="meta">name</span>: <a class="support type" href="string.doc.html">String</a>!</span></li></span></li><li><span class="tab"><li><span class="tab"><span class="comment line"># gtype is the type of object the validator will be applied to (ex: user)</span></span></li><li><span class="tab"><span class="meta">gtype</span>: <a class="support type" href="string.doc.html">String</a>!</span></li></span></li><li><span class="tab"><li><span class="tab"><span class="comment line"># expression is a boolean CEL expression used to evaluate the doc/connection</span></span></li><li><span class="tab"><span class="meta">expression</span>: <a class="support type" href="string.doc.html">String</a>!</span></li></span></li><li><span class="tab"><li><span class="tab"><span class="comment line"># if target_docs is true, this index will be applied to documents.</span></span></li><li><span class="tab"><span class="meta">target_docs</span>: <a class="support type" href="boolean.doc.html">Boolean</a>!</span></li></span></li><li><span class="tab"><li><span class="tab"><span class="comment line"># if target_connections is true, this index will be applied to connections.</span></span></li><li><span class="tab"><span class="meta">target_connections</span>: <a class="support type" href="boolean.doc.html">Boolean</a>!</span></li></span></li><li>}</li></ul></code>
</div>
</section>
<section>
Expand Down
84 changes: 42 additions & 42 deletions gen/gql/go/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions gen/gql/go/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions gql/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ func gqlIndex(val *apipb.Index) *model.Index {
Name: val.GetName(),
Gtype: val.GetGtype(),
Expression: val.GetExpression(),
Connections: val.Connections,
Docs: val.Docs,
TargetConnections: val.GetConnections(),
TargetDocs: val.GetDocs(),
}
}

Expand Down Expand Up @@ -419,8 +419,8 @@ func protoIndex(index *model.IndexInput) *apipb.Index {
Name: index.Name,
Gtype: index.Gtype,
Expression: index.Expression,
Docs: index.Docs,
Connections: index.Connections,
Docs: index.TargetDocs,
Connections: index.TargetConnections,
}
}

Expand Down
Loading

0 comments on commit 553c603

Please sign in to comment.