You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some parts are not ready yet. More features will be landed in near future.
11
-
-[x] ElasticApiParser
12
-
-[x] Mapping converter to GraphQL types
13
-
-[x] Extended definition for `search.body` according to Query DSL
14
-
-[x] Exporting of generated GraphQL field configs for Elastic methods
15
-
-[ ] Improve `search.body` Query DSL by field names from provided Mapping
16
-
-[ ] Helper methods/resolvers for `graphql-compose`
17
-
-[ ] Docs
18
-
-[ ] Declarations for output (can not find proper source/format for Elastic responses. Please open issue with a link if you have such)
9
+
This module expose Elastic Search REST API via GraphQL.
10
+
11
+
## Elastic Search REST API proxy
12
+
13
+
Supported all elastic versions that support official [elasticsearch-js](https://github.com/elastic/elasticsearch-js) client. Internally it parses its source code annotations and generates all available methods with params and descriptions to GraphQL Field Config Map. You may put this config map to any GraphQL Schema.
// you may provide existed Elastic Client instance
25
+
newelasticsearch.Client({
26
+
host:'http://localhost:9200',
27
+
apiVersion:'5.0',
28
+
})
29
+
),
30
+
31
+
// or may provide just config
32
+
elastic24:elasticApiFieldConfig({
33
+
host:'http://user:pass@localhost:9200',
34
+
apiVersion:'2.4',
35
+
}),
36
+
37
+
elastic17:elasticApiFieldConfig({
38
+
host:'http://user:pass@localhost:9200',
39
+
apiVersion:'1.7',
40
+
}),
41
+
},
42
+
}),
43
+
});
44
+
```
45
+
46
+
Full [code example](https://github.com/nodkz/graphql-compose-elasticsearch/tree/master/examples/differentVersions)
47
+
48
+
## TypeComposer from Elastic mapping
49
+
In other side this module is a plugin for [graphql-compose](https://github.com/nodkz/graphql-compose), which derives GraphQLType from your [elastic mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html) generates input fields for all available methods in QueryDSL, Aggregations, Sorting with field autocompletion according to types in your mapping (like query dev tool in Kibana).
50
+
51
+
Generated TypeComposer has several awesome resolvers:
52
+
-`search` - greatly simplified `search` method. According to GraphQL adaptation and its projection bunch of params setup automatically due your graphql query.
53
+
-`searchConnection` - `search` method that implements Relay Cursor Connection [spec](https://facebook.github.io/relay/graphql/connections.htm) for infinite lists. Internally it uses cheap [search_after](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html) API. One downside, Elastic does not support backward scrolling, so `before` argument will not work.
54
+
- more resolvers will be later after my vacation: `suggest`, `getById`, `updateById` and others
55
+
56
+
```js
57
+
constmapping= {
58
+
properties: {
59
+
name: {
60
+
type:'text',
61
+
fields: {
62
+
keyword: {
63
+
type:'keyword',
64
+
},
65
+
},
66
+
},
67
+
gender: {
68
+
type:'keyword',
69
+
},
70
+
skills: {
71
+
type:'text',
72
+
},
73
+
languages: {
74
+
type:'keyword',
75
+
},
76
+
location: {
77
+
properties: {
78
+
name: {
79
+
type:'text',
80
+
},
81
+
point: {
82
+
type:'geo_point',
83
+
},
84
+
},
85
+
},
86
+
createdAt: {
87
+
type:'date',
88
+
},
89
+
},
90
+
};
91
+
92
+
constUserTC=composeWithElastic({
93
+
graphqlTypeName:'UserES',
94
+
elasticIndex:'user',
95
+
elasticType:'user',
96
+
elasticMapping: mapping,
97
+
elasticClient:newelasticsearch.Client({
98
+
host:'http://localhost:9200',
99
+
apiVersion:'5.0',
100
+
log:'trace',
101
+
}),
102
+
// elastic mapping does not contain information about is fields are arrays or not
103
+
// so provide this information explicitly for obtaining correct types in GraphQL
0 commit comments