Skip to content

Commit

Permalink
fix: complete code refactoring due graphql-compose@6
Browse files Browse the repository at this point in the history
  • Loading branch information
nodkz committed Mar 16, 2019
1 parent b648bf8 commit a4b0002
Show file tree
Hide file tree
Showing 124 changed files with 2,172 additions and 2,052 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ Live demo of [Introspection of Elasticsearch API via Graphiql](https://graphql-c

---

## TypeComposer from Elastic mapping
## ObjectTypeComposer from Elastic mapping

In other side this module is a plugin for [graphql-compose](https://github.com/graphql-compose/graphql-compose), which derives GraphQLType from your [elastic mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html) generates tons of types, provides all available methods in QueryDSL, Aggregations, Sorting with field autocompletion according to types in your mapping (like Dev Tools Console in Kibana).

Generated TypeComposer model has several awesome resolvers:
Generated ObjectTypeComposer model has several awesome resolvers:

- `search` - greatly simplified elastic `search` method. According to GraphQL adaptation and its projection bunch of params setup automatically due your graphql query (eg `_source`, `explain`, `version`, `trackScores`), other rare fine tuning params moved to `opts` input field.
- `searchConnection` - elastic `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.
Expand Down
8 changes: 4 additions & 4 deletions examples/elastic50/schema.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow */

import elasticsearch from 'elasticsearch';
import { graphql, TypeComposer } from 'graphql-compose';
import { graphql, ObjectTypeComposer } from 'graphql-compose';
import { composeWithElastic, elasticApiFieldConfig } from '../../src'; // from 'graphql-compose-elasticsearch';

const { GraphQLSchema, GraphQLObjectType } = graphql;
Expand Down Expand Up @@ -94,15 +94,15 @@ const UserEsTC = composeWithElastic({
elasticMapping: demoUserMapping,
elasticClient: new elasticsearch.Client({
host: 'http://localhost:9200',
apiVersion: '5.0',
apiVersion: '5.6',
log: 'trace',
}),
// elastic mapping does not contain information about is fields are arrays or not
// so provide this information explicitly for obtaining correct types in GraphQL
pluralFields: ['skills', 'languages'],
});

const ProxyTC = TypeComposer.create(`type ProxyDebugType { source: JSON }`);
const ProxyTC = ObjectTypeComposer.createTemp(`type ProxyDebugType { source: JSON }`);
ProxyTC.addResolver({
name: 'showArgs',
kind: 'query',
Expand Down Expand Up @@ -132,7 +132,7 @@ const schema = new GraphQLSchema({
userSearchConnection: UserEsTC.getResolver('searchConnection').getFieldConfig(),
elastic50: elasticApiFieldConfig({
host: 'http://user:pass@localhost:9200',
apiVersion: '5.0',
apiVersion: '5.6',
log: 'trace',
}),
},
Expand Down
5 changes: 1 addition & 4 deletions examples/elastic50/seedData.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const client = new elasticsearch.Client({
const body = [];
seedData.forEach(row => {
const { id, ...restData } = row;
body.push(
{ index: { _index: 'demo_user', _type: 'demo_user', _id: id } },
restData
);
body.push({ index: { _index: 'demo_user', _type: 'demo_user', _id: id } }, restData);
});

client
Expand Down
Loading

0 comments on commit a4b0002

Please sign in to comment.