graphql-compose/graphql-compose-elasticsearch

Re-use of TypeComposers

Closed this issue · 1 comments

I'd like to manage different instances of the same type composer, for example

const create = () => {
  const graphqlTypeName = 'ListingElastic'
  const elasticIndex = 'listing'
  const elasticType = 'listrec'
  const elasticMapping = { properties }
  const elasticClient = services.elasticSearch.client

  return composeWithElastic({
    elasticClient,
    elasticIndex,
    elasticMapping,
    elasticType,
    graphqlTypeName,
  })
}

export default create

with create, I may do

TC1 = create()
TC2 = create()
TC2.get(path).addFields({ differentCustomField )

However, i am getting

TypeError: Cannot read property 'addFields' of undefined

Am I missing something? Is there a pattern I can use to extend different composers of the same type?

ahhh! as i wrote this and read it back to myself, i realized i need a unique graphql type name.

this worked

const create = (typeName: string = 'ElasticListing') => {
  const graphqlTypeName = typeName
  const elasticIndex = 'listing'
  const elasticType = 'listrec'
  const elasticMapping = { properties }
  const elasticClient = services.elasticSearch.client

  return composeWithElastic({
    elasticClient,
    elasticIndex,
    elasticMapping,
    elasticType,
    graphqlTypeName,
  })
}

export default create

followed by

TC2 = create('ElasticListingExtended')