Giter Site home page Giter Site logo

graphql-searchkick's Introduction

Graphql::Searchkick

Integrate Searchkick with GraphQL Connections easily.

Gem Version Build Status Maintainability

Note

The current version of the gem only works with GraphQL::Pagination::Connection . If you need support for the older GraphQL::Relay::BaseConnection version use v0.1.0.

Considerations & Limits

  • This will run every usage of this field through Searchkick.
  • The current implementation doesn't support suggestions or aggregations.

If you find any of these undesirable, open an issue or PR.

Installation

Add this line to your application's Gemfile:

gem 'graphql-searchkick'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install graphql-searchkick

Setup

Include the field integration into your field class.

class BaseField < GraphQL::Schema::Field
  include GraphQL::Searchkick::FieldIntegration
end

Add the connection to your schema.

class Schema < GraphQL::Schema
  use GraphQL::Pagination::Connections
  connections.add(GraphQL::Searchkick::LazySearch, GraphQL::Searchkick::ResultConnection)
end

Usage

Add search: ModelClass to any connection field that you want to allow querying.

field :projects, Types::ProjectType.connection_type, null: false, search: Project

Your field will now have an optional query argument of type String as part of it's definition.

If query is nil? or empty? the default value '*' is used.

Search Arguments

If you would like to pass options to the search method, override the resolver for the field that returns a Hash.

def projects(arguments)
  {
    where: {
      active: arguments[:active],
      coordinates: {
        near: arguments[:coords],
        within: '1km'
      }
    }
  }
end

This will translate into:

Project.search('*', where: { active: true, coordinates: { near: { lat: 40.815110, lon: -96.709523 }, within: '1km' } })

Development

After checking out the repo, run bin/setup to install dependencies. Then run docker-compose up to start Elasticsearch. Finally, run bundle exec appraisal rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/CompanyCam/graphql-searchkick.

License

The gem is available as open source under the terms of the MIT License.

graphql-searchkick's People

Contributors

chadwilken avatar

Stargazers

Minions avatar Hector Kemp avatar Andrew Stevens avatar Diego Linhares avatar ahmad avatar Jon avatar Thomas Klemm avatar Jesse Onolememen avatar Jonian Guveli avatar  avatar Jason McKelvey avatar Ben Woodall avatar

Watchers

James Cloos avatar  avatar Kevin Scully avatar Luke Hansen avatar  avatar

graphql-searchkick's Issues

Offset value is not being setted

I'm passing the offset but the library ignores it.
The folowing code:

field :projects, Types::ProjectType.connection_type, null: false, search: Project

def projects(arguments)
  {
    where: {
      active: arguments[:active]
    },
    limit: 3
    offset: 2
  }
end

Was translated to:

Project.search('*', where: { active: true }, limit: 3)

Convert CI to GitHub Actions

TravisCI is no longer giving away free credits from what I can tell, we should probably just move CI to GitHub actions.

Set a default limit on the number of items returned.

When a first parameter isn't provided as an argument to the search query, the query will return all of the records in the elastic search index, which could be thousands if not hundreds of thousands. There should be some default limit imposed on the number of items returned in case the client does leave out the first parameter.

My suggestion would to be add something like this to the apply_pagination method in the GraphQL::Searchkick::ResultConnection

      if first
        set_limit(nodes, first) if search_limit(nodes).nil? || search_limit(nodes) > first
      else
        set_limit(nodes, 15) # possibly get max limit from schema opposed to magic number
      end

All that does there is check if there's a limit and if not apply a default limit. It would be useful to implement something like this.

Dependabot Findings updated Apr. 22, 2024

NOTE: This issue was computer generated on Apr. 22, 2024. Comments may get lost. Issues are sorted by remediation deadline. Only dependabot alerts created on or after Feb. 01, 2024 are shown.

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.