PagingTypeHelper
Create Enum from Rails Model Enumâ
Use paging_type_for_model to build a GraphQL Paging Type.
Arguments:
model: ActiveRecord Model Name.record_data_type: GraphQL Type for the record data.graphql_type_name:can be provided to customize the GraphQL type name.
NOTE: GraphQL Paging Type Name will be automatically generated in the format <Model Name>PagingType but can be customized.
NOTE: If Record Data Type is not provided, it will use the object type in the format Types::Objects::<Model Name>Type.
examples:
Types::PagingTypeHelper.paging_type_for_model(model: Course, record_data_type: Types::Objects::Course)
Types::PagingTypeHelper.paging_type_for_model(model: Course, record_data_type: Types::Objects::Course, graphql_type_name: 'CustomCoursePagingType')
- To create a reusable Type create a initializer in
config/initializers/graphql_paging_type_autogen.rb
Rails.application.config.to_prepare do
Types::CoursePagingType = Types::PagingTypeHelper.paging_type_for_model(model: Course, record_data_type: Types::Objects::Course)
end