{"id":13879764,"url":"https://github.com/RStankov/SearchObjectGraphQL","last_synced_at":"2025-07-16T15:32:59.899Z","repository":{"id":54450840,"uuid":"88285551","full_name":"RStankov/SearchObjectGraphQL","owner":"RStankov","description":"GraphQL plugin for SearchObject gem","archived":false,"fork":false,"pushed_at":"2023-07-24T08:59:05.000Z","size":124,"stargazers_count":159,"open_issues_count":0,"forks_count":25,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-15T13:46:13.752Z","etag":null,"topics":["filter","gem","graphql","graphql-server","ruby","search","searchobject"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RStankov.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-14T16:48:32.000Z","updated_at":"2024-06-03T12:17:07.000Z","dependencies_parsed_at":"2024-06-18T21:41:26.321Z","dependency_job_id":null,"html_url":"https://github.com/RStankov/SearchObjectGraphQL","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RStankov%2FSearchObjectGraphQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RStankov%2FSearchObjectGraphQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RStankov%2FSearchObjectGraphQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RStankov%2FSearchObjectGraphQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RStankov","download_url":"https://codeload.github.com/RStankov/SearchObjectGraphQL/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225710159,"owners_count":17511975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filter","gem","graphql","graphql-server","ruby","search","searchobject"],"created_at":"2024-08-06T08:02:32.082Z","updated_at":"2024-11-24T08:31:47.097Z","avatar_url":"https://github.com/RStankov.png","language":"Ruby","readme":"[![Gem Version](https://badge.fury.io/rb/search_object_graphql.svg)](http://badge.fury.io/rb/search_object_graphql)\n[![Code Climate](https://codeclimate.com/github/RStankov/SearchObjectGraphQL.svg)](https://codeclimate.com/github/RStankov/SearchObjectGraphQL)\n[![Code coverage](https://coveralls.io/repos/RStankov/SearchObjectGraphQL/badge.svg?branch=master#2)](https://coveralls.io/r/RStankov/SearchObjectGraphQL)\n\n# SearchObject::Plugin::GraphQL\n\n[SearchObject](https://github.com/RStankov/SearchObject) plugin for [GraphQL Ruby](https://rmosolgo.github.io/graphql-ruby/).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'search_object_graphql'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install search_object_graphql\n\n\n**Require manually in your project**\n\n```ruby\nrequire 'search_object'\nrequire 'search_object/plugin/graphql'\n```\n\n## Dependencies\n\n- `SearchObject` \u003e= 1.2\n- `Graphql` \u003e= 1.5\n\n## Changelog\n\nChanges are available in [CHANGELOG.md](https://github.com/RStankov/SearchObjectGraphQL/blob/master/CHANGELOG.md)\n\n## Usage\n\nJust include the ```SearchObject.module``` and define your search options and their types:\n\n```ruby\nclass PostResolver \u003c GraphQL::Schema::Resolver\n  include SearchObject.module(:graphql)\n\n  type [PostType], null: false\n\n  scope { Post.all }\n\n  option(:name, type: String)       { |scope, value| scope.where name: value }\n  option(:published, type: Boolean) { |scope, value| value ? scope.published : scope.unpublished }\nend\n```\n\nThen you can just use `PostResolver` as [GraphQL::Schema::Resolver](https://graphql-ruby.org/fields/resolvers.html):\n\n```ruby\nfield :posts, resolver: PostResolver\n```\n\nOptions are exposed as arguments in the GraphQL query:\n\n```\nposts(name: 'Example') { ... }\nposts(published: true) { ... }\nposts(published: true, name: 'Example') { ... }\n```\n\n### Example\n\nYou can find example of most important features and plugins - [here](https://github.com/RStankov/SearchObjectGraphQL/tree/master/example).\n\n## Features\n\n### Documentation\n\nSearch object itself can be documented, as well as its options:\n\n```ruby\nclass PostResolver \u003c GraphQL::Schema::Resolver\n  include SearchObject.module(:graphql)\n\n  description 'Lists all posts'\n\n  option(:name, type: String, description: 'Fuzzy name matching') { ... }\n  option(:published, type: Boolean, description: 'Find published/unpublished') { ... }\nend\n```\n\n### Default Values\n\n```ruby\nclass PostResolver \u003c GraphQL::Schema::Resolver\n  include SearchObject.module(:graphql)\n\n  scope { Post.all }\n\n  option(:published, type: Boolean, default: true) { |scope, value| value ? scope.published : scope.unpublished }\nend\n```\n\n### Additional Argument Options\n\nSometimes you need to pass additional options to the graphql argument method.\n\n```ruby\nclass PostResolver \u003c GraphQL::Schema::Resolver\n  include SearchObject.module(:graphql)\n\n  scope { Post.all }\n\n  option(:published, type: Boolean, argument_options: { pundit_role: :read }) { |scope, value| value ? scope.published : scope.unpublished }\nend\n```\n\n### Accessing Parent Object\n\nSometimes you want to scope posts based on parent object, it is accessible as `object` property:\n\n```ruby\nclass PostResolver \u003c GraphQL::Schema::Resolver\n  include SearchObject.module(:graphql)\n\n  # lists only posts from certain category\n  scope { object.posts }\n\n  # ...\nend\n```\n\nIf you need GraphQL context, it is accessible as `context`.\n\n### Enums Support\n\n```ruby\nclass PostSearch\n  include SearchObject.module(:graphql)\n\n  OrderEnum = GraphQL::EnumType.define do\n    name 'PostOrder'\n\n    value 'RECENT'\n    value 'VIEWS'\n    value 'COMMENTS'\n  end\n\n  option :order, type: OrderEnum, default: 'RECENT'\n\n  def apply_order_with_recent(scope)\n    scope.order 'created_at DESC'\n  end\n\n  def apply_order_with_views(scope)\n    scope.order 'views_count DESC'\n  end\n\n  def apply_order_with_comments(scope)\n    scope.order 'comments_count DESC'\n  end\nend\n```\n\n### Relay Support\n\nSearch objects can be used as [Relay Connections](https://graphql-ruby.org/relay/connections.html):\n\n```ruby\nclass PostResolver \u003c GraphQL::Schema::Resolver\n  include SearchObject.module(:graphql)\n\n  type PostType.connection_type, null: false\n\n  # ...\nend\n```\n\n```ruby\nfield :posts, resolver: PostResolver\n```\n\n## Running tests\n\nMake sure all dependencies are installed with `bundle install`\n\n```\nrake\n```\n\n## Release\n\n```\nrake release\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Run the tests (`rake`)\n6. Create new Pull Request\n\n## Authors\n\n* **Radoslav Stankov** - *creator* - [RStankov](https://github.com/RStankov)\n\nSee also the list of [contributors](https://github.com/RStankov/SearchObjectGraphQL/contributors) who participated in this project.\n\n## License\n\n**[MIT License](https://github.com/RStankov/SearchObjectGraphQL/blob/master/LICENSE.txt)**\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRStankov%2FSearchObjectGraphQL","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRStankov%2FSearchObjectGraphQL","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRStankov%2FSearchObjectGraphQL/lists"}