/
resolver_get.go
75 lines (63 loc) · 2.04 KB
/
resolver_get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* _ _
*__ _____ __ ___ ___ __ _| |_ ___
*\ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
* \ V V / __/ (_| |\ V /| | (_| | || __/
* \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
*
* Copyright © 2016 - 2019 Weaviate. All rights reserved.
* LICENSE: https://github.com/creativesoftwarefdn/weaviate/blob/develop/LICENSE.md
* DESIGN & CONCEPT: Bob van Luijt (@bobvanluijt)
* CONTACT: hello@creativesoftwarefdn.org
*/
package janusgraph
import (
"fmt"
"runtime/debug"
jget "github.com/creativesoftwarefdn/weaviate/database/connectors/janusgraph/get"
"github.com/creativesoftwarefdn/weaviate/database/schema"
"github.com/creativesoftwarefdn/weaviate/graphqlapi/local/get"
"github.com/creativesoftwarefdn/weaviate/gremlin"
)
type resolveResult struct {
results []interface{}
err error
}
// Implement the Local->Get->KIND->CLASS lookup.
func (j *Janusgraph) LocalGetClass(params *get.Params) (interface{}, error) {
first := 100
offset := 0
if params.Pagination != nil {
first = params.Pagination.First
offset = params.Pagination.After
}
ch := make(chan resolveResult, 1)
go func() {
defer func() {
if r := recover(); r != nil {
// send error over the channel
ch <- resolveResult{err: fmt.Errorf("Janusgraph.LocalGetClass paniced: %#v\n%s", r, string(debug.Stack()))}
}
close(ch)
}()
results, err := j.doLocalGetClass(first, offset, params)
if err != nil {
ch <- resolveResult{err: fmt.Errorf("Janusgraph.LocalGetClass: %#v", err)}
} else {
ch <- resolveResult{results: results}
}
}()
result := <-ch
if result.err != nil {
fmt.Printf("Paniced %#v\n", result.err)
return nil, result.err
}
return result.results, nil
}
func (j *Janusgraph) doLocalGetClass(first, offset int, params *get.Params) ([]interface{}, error) {
q, err := jget.NewQuery(*params, &j.state, &j.schema).String()
if err != nil {
return nil, fmt.Errorf("could not build query: %s", err)
}
return jget.NewProcessor(j.client, &j.state, schema.ClassName(params.ClassName)).
Process(gremlin.New().Raw(q))
}