Git Product home page Git Product logo

apollo-link-algolia's Introduction

Apollo-link-algolia

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

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

Usage

Basic

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

const algoliaClient = algoliasearch('APPLICATION_ID', 'API_KEY')

const algoliaLink = new AlgoliaLink({ client: algoliaClient })

const client = new ApolloClient({
  link: algoliaLink,
  cache: new InMemoryCache()
})

// Simple query example
const QUERY = gql`
  query LocationsQuery {
    locationsInRadius @algolia(index: "INDEX_NAME", aroundLatLng: "40.71, -74.01", aroundRadius: 1000) {
        hits
    }
  }
`

client.query({ query: QUERY }).then(response => console.log(response))

// Multiple queries example
type Query {
    algoliaQueries(queries: [AlgoliaQuery]): [AlgoliaQueryData!]!
}

input AlgoliaQuery {
    query: String!
}

type AlgoliaQueryData {
    result: [AlgoliaQueryResult]!
}

type AlgoliaQueryResult {
    nbHits: Int
    hitsPerPage: Int
    hits: AlgoliaQueryResultHits
}

type AlgoliaQueryResultHits {
    name: String
}

const QUERY = gql`
  query algoliaQueries($queries: [AlgoliaQuery]) {
    algoliaQueries @algolia(type: "AlgoliaQueryData", queries: $queries) {
      results @type(name: AlgoliaQueryResult) {
        nbHits
        hitsPerPage
        hits @type(name: AlgoliaQueryResultHits) {
          name
        }
      }
    }
  }
`

const queries = [{
  indexName: 'categories',
  query: 'search in categories index',
  params: {
    hitsPerPage: 3
  }
}, {
  indexName: 'products',
  query: 'first search in products',
  params: {
    hitsPerPage: 3,
    filters: '_tags:promotion'
  }
}, {
  indexName: 'products',
  query: 'another search in products',
  params: {
    hitsPerPage: 10
  }
}];

client.query({ query: QUERY, variables: { queries } }).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

apollo-link-algolia's People

Contributors

bafxyz avatar janowsiany avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.