graphql-compose/graphql-compose-elasticsearch

Elastic Internal TCs with relay connection

amarflybot opened this issue · 1 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?

nodkz commented

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.