graphql-compose / graphql-compose-elasticsearch

Hide Elastic Search REST API behind GraphQL.

Home Page:https://graphql-compose.herokuapp.com/elasticsearch/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Elastic Internal TCs with relay connection

amarflybot opened this issue · comments

Hi @nodkz , Do you have a way to support relay/connection for internal or nested data?

So lets say you have a root defined by:

const FlightEsTC = composeWithElastic({
  graphqlTypeName: 'fl',
  elasticIndex: 'kibana_sample_data_flights',
  elasticType: '_doc',
  elasticMapping: ecommerceMapping,
  elasticClient: elasticClient,
  schemaComposer: schemaComposer
});

And You wanna add relays to internal sub query:

let EcommerceecommerceGeoipTC = schemaComposer.getOTC('ecommerceecommerceGeoip');

schemaComposer.getOTC('ecommerceecommerce').addFields({
  geoipConnection: composeWithRelay(EcommerceecommerceGeoipTC)

How can we do this?

You need to use composeWithRelay(EcommerceecommerceGeoipTC).getReolver('...').wrapResolve().
And inside wrapper get entity id from source and pass them as some arg to the elastic resolver.

Please search issues about wrapResolve in graphql-compose repo. Also it may be usefult to use addRelation method which does this and also may remove args from resolver.

When you'll be done, please post here a working solution for further googlers.

Tnx.