项目作者: janowsiany

项目描述 :
Query Algolia with Apollo
高级语言: JavaScript
项目地址: git://github.com/janowsiany/apollo-link-algolia.git
创建时间: 2018-03-29T21:57:24Z
项目社区:https://github.com/janowsiany/apollo-link-algolia

开源协议:MIT License

下载


This is heavly work in progress!

apollo-link-algolia provides you a simple way to query Algolia in graphQL with apollo-client without building a graphQL server.

Currently, we support features below:

  1. Query parameters: list of supported parametes can be checked here.

Contents

Installation

  1. npm install --save apollo-link-algolia
  2. # or if you're using yarn
  3. yarn add apollo-link-algolia

Usage

Basic

To get the results of your request, query for hits field

  1. const algoliaClient = algoliasearch('APPLICATION_ID', 'API_KEY')
  2. const algoliaLink = new AlgoliaLink({ client: algoliaClient })
  3. const client = new ApolloClient({
  4. link: algoliaLink,
  5. cache: new InMemoryCache()
  6. })
  7. const LOCATIONS_QUERY = gql`
  8. query LocationsQuery {
  9. locationsInRadius @algolia(index: "INDEX_NAME", aroundLatLng: "40.71, -74.01", aroundRadius: 1000) {
  10. hits
  11. }
  12. }
  13. `
  14. client.query({ query: LOCATIONS_QUERY }).then(response => console.log(response))

Query meta fields

Aside from the hits field, the result may contain several other fields that contain meta information:

  • aroundLatLng
  • automaticRadius
  • disjunctiveFacets
  • exhaustiveFacetsCount
  • exhaustiveNbHits
  • facets
  • hierarchicalFacets
  • hitsPerPage
  • index
  • nbHits
  • nbPages
  • page
  • parsedQuery
  • processingTimeMS
  • query
  • queryID
  • serverUsed
  • timeoutCounts
  • timeoutHits
  • userData
  • _rawResults
  • _state