All Projects → RStankov → Searchobjectgraphql

RStankov / Searchobjectgraphql

Licence: mit
GraphQL plugin for SearchObject gem

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Searchobjectgraphql

Graphql To Mongodb
Allows for generic run-time generation of filter types for existing graphql types and parsing client requests to mongodb find queries
Stars: ✭ 261 (+121.19%)
Mutual labels:  graphql, graphql-server, filter
Searchobject
Search object DSL
Stars: ✭ 152 (+28.81%)
Mutual labels:  search, gem, filter
Graphjin
GraphJin - Build APIs in 5 minutes with GraphQL. An instant GraphQL to SQL compiler.
Stars: ✭ 1,264 (+971.19%)
Mutual labels:  graphql, graphql-server
Ariadne
Ariadne is a Python library for implementing GraphQL servers using schema-first approach.
Stars: ✭ 1,274 (+979.66%)
Mutual labels:  graphql, graphql-server
Graphql Stack
A visual explanation of how the various tools in the GraphQL ecosystem fit together.
Stars: ✭ 117 (-0.85%)
Mutual labels:  graphql, graphql-server
Apollo Server Vercel
⚫ Production-ready Node.js GraphQL server for Vercel Serverless Functions
Stars: ✭ 69 (-41.53%)
Mutual labels:  graphql, graphql-server
Daptin
Daptin - Backend As A Service - GraphQL/JSON-API Headless CMS
Stars: ✭ 1,195 (+912.71%)
Mutual labels:  graphql, graphql-server
Graphql Log
Add logging to your GraphQL resolvers so you know what's going on in your app.
Stars: ✭ 94 (-20.34%)
Mutual labels:  graphql, graphql-server
Example Auth
User auth, session & JWT example for ReactQL
Stars: ✭ 51 (-56.78%)
Mutual labels:  graphql, graphql-server
Firebase Functions Graphql Example
GraphQL server running on Cloud Functions for Firebase
Stars: ✭ 107 (-9.32%)
Mutual labels:  graphql, graphql-server
Json Graphql Server
Get a full fake GraphQL API with zero coding in less than 30 seconds.
Stars: ✭ 1,369 (+1060.17%)
Mutual labels:  graphql, graphql-server
Qlens
QLens is an electron app which dynamically generates GraphQL Schemas and Mongo Schema visualization. QLens significantly cuts development time by automating the formation of their GraphQL schemas based on information fetched from their non-relational database.
Stars: ✭ 110 (-6.78%)
Mutual labels:  graphql, graphql-server
Locksmith
Want to use GraphQL with Clojure/script but don't want keBab or snake_keys everywhere? Use locksmith to change all the keys!
Stars: ✭ 59 (-50%)
Mutual labels:  graphql, graphql-server
Graphql Api Gateway
An open-sourced example of a GraphQL API Gateway. This service queries and joins data across different back-ends into one GraphQL schema.
Stars: ✭ 57 (-51.69%)
Mutual labels:  graphql, graphql-server
Graphql Transform Schema
Transform, filter & alias resolvers of a GraphQL schema
Stars: ✭ 84 (-28.81%)
Mutual labels:  graphql, graphql-server
Data Source Base
Boilerplate for creating a GrAMPS-compatible data source.
Stars: ✭ 52 (-55.93%)
Mutual labels:  graphql, graphql-server
Qlkube
A GraphQL api for Kubernetes
Stars: ✭ 89 (-24.58%)
Mutual labels:  graphql, graphql-server
Faltu
Search sort, filter, limit an array of objects in Mongo-style.
Stars: ✭ 112 (-5.08%)
Mutual labels:  search, filter
Graphql Kotlin
Libraries for running GraphQL in Kotlin
Stars: ✭ 1,030 (+772.88%)
Mutual labels:  graphql, graphql-server
Gql
☁ Universal GraphQL HTTP middleware for Deno
Stars: ✭ 42 (-64.41%)
Mutual labels:  graphql, graphql-server

Gem Version Code Climate Build Status Code coverage

SearchObject::Plugin::GraphQL

SearchObject plugin for GraphQL Ruby.

Table of Contents

Installation

Add this line to your application's Gemfile:

gem 'search_object_graphql'

And then execute:

$ bundle

Or install it yourself as:

$ gem install search_object_graphql

Require manually in your project

require 'search_object'
require 'search_object/plugin/graphql'

Dependencies

  • SearchObject >= 1.2
  • Graphql >= 1.5

Usage

Just include the SearchObject.module and define your search options and their types:

class PostResolver < GraphQL::Schema::Resolver
  include SearchObject.module(:graphql)

  type [PostType], null: false

  scope { Post.all }

  option(:name, type: String)       { |scope, value| scope.where name: value }
  option(:published, type: Boolean) { |scope, value| value ? scope.published : scope.unpublished }
end

Then you can just use PostResolver as GraphQL::Schema::Resolver:

field :posts, resolver: PostResolver

Options are exposed as arguments in the GraphQL query:

posts(name: 'Example') { ... }
posts(published: true) { ... }
posts(published: true, name: 'Example') { ... }

Example

You can find example of most important features and plugins - here.

Features

Documentation

Search object itself can be documented, as well as its options:

class PostResolver < GraphQL::Schema::Resolver
  include SearchObject.module(:graphql)

  description 'Lists all posts'

  option(:name, type: types.String, description: 'Fuzzy name matching') { ... }
  option(:published, type: types.Boolean, description: 'Find published/unpublished') { ... }
end

Default Values

class PostResolver < GraphQL::Schema::Resolver
  include SearchObject.module(:graphql)

  scope { Post.all }

  option(:published, type: types.Boolean, default: true) { |scope, value| value ? scope.published : scope.unpublished }
end

Accessing Parent Object

Sometimes you want to scope posts based on parent object, it is accessible as object property:

class PostResolver < GraphQL::Schema::Resolver
  include SearchObject.module(:graphql)

  # lists only posts from certain category
  scope { object.posts }

  # ...
end

If you need GraphQL context, it is accessible as context.

Enums Support

class PostSearch
  include SearchObject.module(:graphql)

  OrderEnum = GraphQL::EnumType.define do
    name 'PostOrder'

    value 'RECENT'
    value 'VIEWS'
    value 'COMMENTS'
  end

  option :order, type: OrderEnum, default: 'RECENT'

  def apply_order_with_recent(scope)
    scope.order 'created_at DESC'
  end

  def apply_order_with_views(scope)
    scope.order 'views_count DESC'
  end

  def apply_order_with_comments(scope)
    scope.order 'comments_count DESC'
  end
end

Relay Support

Search objects can be used as Relay Connections:

class PostResolver < GraphQL::Schema::Resolver
  include SearchObject.module(:graphql)

  type PostType.connection_type, null: false

  # ...
end
field :posts, resolver: PostResolver

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Run the tests (rake)
  6. Create new Pull Request

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].