graphql-compose / graphql-compose-elasticsearch

Hide Elastic Search REST API behind GraphQL.
https://graphql-compose.herokuapp.com/elasticsearch/
MIT License
583 stars 77 forks source link

Elastic Internal TCs with relay connection #91

Open amarflybot opened 4 years ago

amarflybot commented 4 years ago

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 4 years ago

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.