SearchObjectGraphQL
1.0.0
GraphQL Ruby용 SearchObject 플러그인.
애플리케이션의 Gemfile에 다음 줄을 추가하세요.
gem 'search_object_graphql'
그런 다음 다음을 실행합니다.
$ bundle
또는 다음과 같이 직접 설치하십시오.
$ gem install search_object_graphql
프로젝트에서 수동으로 요구
require 'search_object'
require 'search_object/plugin/graphql'
SearchObject
>= 1.2Graphql
>= 1.5 변경 사항은 CHANGELOG.md에서 확인할 수 있습니다.
SearchObject.module
포함하고 검색 옵션과 해당 유형을 정의하기만 하면 됩니다.
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
그런 다음 PostResolver
GraphQL::Schema::Resolver로 사용할 수 있습니다.
field :posts , resolver : PostResolver
옵션은 GraphQL 쿼리에서 인수로 노출됩니다.
posts(name: 'Example') { ... }
posts(published: true) { ... }
posts(published: true, name: 'Example') { ... }
여기에서 가장 중요한 기능과 플러그인의 예를 찾을 수 있습니다.
검색 개체 자체와 해당 옵션을 문서화할 수 있습니다.
class PostResolver < GraphQL :: Schema :: Resolver
include SearchObject . module ( :graphql )
description 'Lists all posts'
option ( :name , type : String , description : 'Fuzzy name matching' ) { ... }
option ( :published , type : Boolean , description : 'Find published/unpublished' ) { ... }
end
class PostResolver < GraphQL :: Schema :: Resolver
include SearchObject . module ( :graphql )
scope { Post . all }
option ( :published , type : Boolean , default : true ) { | scope , value | value ? scope . published : scope . unpublished }
end
때로는 graphql 인수 메서드에 추가 옵션을 전달해야 하는 경우도 있습니다.
class PostResolver < GraphQL :: Schema :: Resolver
include SearchObject . module ( :graphql )
scope { Post . all }
option ( :published , type : Boolean , argument_options : { pundit_role : :read } ) { | scope , value | value ? scope . published : scope . unpublished }
end
때로는 상위 개체를 기반으로 게시물 범위를 지정하려는 경우 object
속성으로 액세스할 수 있습니다.
class PostResolver < GraphQL :: Schema :: Resolver
include SearchObject . module ( :graphql )
# lists only posts from certain category
scope { object . posts }
# ...
end
GraphQL 컨텍스트가 필요한 경우 context
로 액세스할 수 있습니다.
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
검색 개체는 릴레이 연결로 사용될 수 있습니다.
class PostResolver < GraphQL :: Schema :: Resolver
include SearchObject . module ( :graphql )
type PostType . connection_type , null : false
# ...
end
field :posts , resolver : PostResolver
bundle install
통해 모든 종속성이 설치되었는지 확인하세요.
rake
rake release
git checkout -b my-new-feature
).git commit -am 'Add some feature'
)git push origin my-new-feature
)rake
)이 프로젝트에 참여한 기여자 목록도 참조하세요.
MIT 라이센스