Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-link-algolia

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-link-algolia - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

2

package.json
{
"name": "apollo-link-algolia",
"version": "0.0.3",
"version": "0.0.4",
"description": "Query Algoila with Apollo",

@@ -5,0 +5,0 @@ "main": "./src/index.js",

@@ -12,3 +12,3 @@ ## Apollo-link-algolia

* [Installation](#installation)
* [Example](#example)
* [Usage](#Usage)

@@ -23,9 +23,50 @@ ## Installation

## Example
## Usage
### Basic
To get the results of your request, query for `hits` field
```js
const algoliaClient = algoliasearch('APPLICATION_ID', 'API_KEY')
const algoliaLink = new AlgoliaLink({ client: algoliaClient })
const client = new ApolloClient({
link: algoliaLink,
cache: new InMemoryCache()
})
const LOCATIONS_QUERY = gql`
query LocationsQuery {
locationsInRadius @algolia(index: "dev_LOCATIONS", aroundLatLng: "40.71, -74.01", aroundRadius: 1000)
locationsInRadius @algolia(index: "INDEX_NAME", aroundLatLng: "40.71, -74.01", aroundRadius: 1000) {
hits
}
}
`
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`
import algoliasearchHelper from 'algoliasearch-helper'
import { ApolloLink, Observable } from 'apollo-link'
import { addTypenameToDocument, getMainDefinition, hasDirectives } from 'apollo-utilities'
import { ApolloLink, Observable } from 'apollo-link'
import { graphql } from 'graphql-anywhere/lib/async'

@@ -43,5 +43,13 @@

const addTypeNameToResult = (result, __typename = 'AlgoliaQuery') => ({ __typename, ...result.content })
const resolver = (fieldName, root, args, context, info) => {
const { directives } = info
const { directives, isLeaf, resultKey } = info
const isNotAlgoliaQuery = !directives || !directives.algolia
if (isLeaf || isNotAlgoliaQuery) {
const returnValue = (root || {})[resultKey] || (root || {})[fieldName]
return returnValue !== undefined ? returnValue : null
}
if (!directives.algolia.index) {

@@ -59,3 +67,3 @@ throw new Error('Algolia index name is required')

return helper.searchOnce()
return helper.searchOnce().then(result => addTypeNameToResult(result))
}

@@ -62,0 +70,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc