Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "bundler" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "monthly"
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
strategy:
matrix:
ruby:
- '3.2.2'
- '3.2'
- '3.3'

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .standard.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# For available configuration options, see:
# https://github.com/standardrb/standard
ruby_version: 2.6
ruby_version: 3.4.5
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 3.4.5
113 changes: 113 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Development Commands

## General Development Commands

### Linting
bundle exec standardrb

### Testing
rake test

### Cache Sync
rake dato_cms:cache

## Testing Usage Examples

Run specific tests to validate key usage patterns demonstrated in the test suite:

### GraphQL Field Generation and Query Classes
rake test test/graphql_fields_test.rb

### Path Configuration and Basic Functionality
rake test test/dato_cms_graphql_test.rb

## Using the Gem

This section provides a step-by-step guide to using the gem, based on usage demonstrated in tests and documented in the README.

### Installation and Environment Setup
1. Add to Gemfile and bundle:
```
gem 'dato_cms_graphql', git: 'https://github.com/Paradem/dato_cms_graphql.git'
bundle install
```

2. Set required environment variables (from README):
- `DATO_API_TOKEN`: Your DatoCMS API token.
- `DATO_API_INCLUDE_DRAFTS`: Set to `true` to include draft content (optional).

### Configuration
- **Rails Setup** (from README):
- Create a migration for the cache table (records table with type, locale, cms_id, permalink, cms_record, render, timestamps).
- Create Record model including DatoCmsGraphql::Rails::CacheTable.
- Run `rails db:migrate`.
- Cache data: `rake dato_cms:cache`.
- Configure routes: Add `DatoCmsGraphql::Rails::Routing.draw_routes(Record)` to config/routes.rb.

- **Manual/Non-Rails Setup** (from tests):
- Set query path: `DatoCmsGraphql.path_to_queries = "/path/to/queries"` (e.g., "/app/queries").

### Defining Query Classes
1. Create classes inheriting `DatoCmsGraphql::BaseQuery` in your queries directory.
2. Use `graphql_fields` to define fields (from tests and README):
```ruby
class NewsQuery < DatoCmsGraphql::BaseQuery
graphql_fields(:id, :title, :permalink)
end
```
- For nested fields: `graphql_fields(id: [:subfield])`.

3. Optional methods (from README):
- `page_size(50)`: Set pagination size.
- `single_instance(true)`: For singleton models.
- `render(false)`: Exclude from routing.

### Generating GraphQL Queries Manually
Use `DatoCmsGraphql::Fields` for direct query string generation (from tests):
```ruby
fields = [:id, :title, nested: [:field]]
query = DatoCmsGraphql::Fields.new(fields).to_query
# Produces GraphQL string like: id\ntitle\nnested {\n field\n}\n
```

### Fetching and Accessing Data
1. For multiple items: `NewsQuery.all.each { |item| puts item.title }`.
2. For single item: `item = HomeQuery.get; puts item.title`.
3. Instantiate manually (from tests): `news = NewsQuery.new(attributes.deep_transform_keys(&:underscore)); puts news.id`.
4. Access nested attributes: `item.photos.each { |photo| puts photo.url }`.

### Controllers and Routing
- In Rails controllers: `@news = News.find_by(locale: I18n.locale, permalink: params[:permalink])`.
- Routes are auto-generated based on query classes.

### Error Handling and API Failures (from tests)
Handle API errors gracefully:
```ruby
begin
result = DatoCmsGraphql.query("query { invalidField }")
rescue GraphQL::Client::Error => e
# Log or handle API failures (e.g., invalid token, network issues)
puts "API Error: #{e.message}"
end
```

### Concurrency and Thread Safety (from concurrency tests)
Use the gem in multi-threaded environments:
```ruby
threads = []
5.times do
threads << Thread.new { DatoCmsGraphql.queries } # Safe concurrent loading
end
threads.each(&:join)
```

### Rails Integration with Caching and Routing (from Rails integration tests)
In Rails apps, handle locale-specific routing and caching:
```ruby
# Automatic route generation for localized content
I18n.locale = :fr
routes = Rails.application.routes.routes # Includes /news/:permalink for each locale

# Cache data for performance
rake dato_cms:cache # Persists data to avoid API calls
```
30 changes: 29 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
## [Unreleased]
## [0.3.0] - 2026-01-13

- Update gem to support Rails 8 for improved compatibility
- Add documentation enhancements and usage examples in AGENTS.md
- Update tests and documentation for better coverage and onboarding
- Fix warnings in tests related to string handling and deprecations
- Bump supported Ruby versions for broader compatibility
- Require ostruct as a runtime dependency for Ruby 3.4+ stdlib compatibility
- Clear out unnecessary extra slashes in query paths

## [0.2.8] - 2025-12-17

- Add ostruct and logger as runtime dependencies for Ruby 3.4+ stdlib compatibility
- Update minitest to ~> 5.21 for better Ruby 3.4 support
- Update standardrb to ~> 1.52 for Ruby 3.4.5 linting support
- Fix literal string mutation in Fields class to avoid Ruby 3 warnings
- Update .standard.yml ruby_version to 3.4.5
- Resolve test warnings related to deprecated stdlib gems and string handling
- Enhanced AGENTS.md with targeted testing usage examples (e.g., commands for GraphQL field generation and path configuration tests) and a comprehensive "Using the Gem" guide, drawing from test suite patterns and README documentation for better developer onboarding
- Enhanced test suite with comprehensive edge case coverage for gem usage:
- Error handling tests for API failures and invalid configurations
- Boundary condition tests for field generation and data handling
- Invalid input validation for queries and attributes
- Concurrency tests for thread-safe query loading
- Rails integration tests for caching, routing, and localization
- Added test dependencies: webmock, mocha, concurrent-ruby for mocking and simulation
- Improved gem reliability and developer confidence through test-demonstrated usage patterns

## [0.2.7] - 2025-12-17

## [0.1.0] - 2024-01-29

Expand Down
8 changes: 7 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ gemspec

gem "rake", "~> 13.0"

gem "minitest", "~> 5.16"
gem "minitest", "~> 5.21"

gem "standard", "~> 1.3"

group :test do
gem "webmock"
gem "concurrent-ruby"
gem "mocha"
end
124 changes: 78 additions & 46 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,93 +1,125 @@
PATH
remote: .
specs:
dato_cms_graphql (0.2.4)
activesupport (~> 7.1.3)
graphql-client (~> 0.19.0)
dato_cms_graphql (0.3.0)
activesupport (>= 7.1, < 9.0)
graphql-client (>= 0.24.0, < 1.0)
logger
ostruct

GEM
remote: https://rubygems.org/
specs:
activesupport (7.1.3)
activesupport (8.1.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
json
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.6)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
drb (2.2.0)
ruby2_keywords
graphql (2.2.7)
graphql-client (0.19.0)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1)
addressable (2.8.8)
public_suffix (>= 2.0.2, < 8.0)
ast (2.4.3)
base64 (0.3.0)
bigdecimal (4.0.1)
concurrent-ruby (1.3.6)
connection_pool (3.0.2)
crack (1.0.1)
bigdecimal
rexml
drb (2.2.3)
fiber-storage (1.0.1)
graphql (2.5.16)
base64
fiber-storage
logger
graphql-client (0.26.0)
activesupport (>= 3.0)
graphql
i18n (1.14.1)
graphql (>= 1.13.0)
hashdiff (1.2.1)
i18n (1.14.8)
concurrent-ruby (~> 1.0)
json (2.7.1)
language_server-protocol (3.17.0.3)
json (2.18.0)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
minitest (5.21.2)
mutex_m (0.2.0)
parallel (1.24.0)
parser (3.3.0.5)
logger (1.7.0)
minitest (5.27.0)
mocha (3.0.1)
ruby2_keywords (>= 0.0.5)
ostruct (0.6.3)
parallel (1.27.0)
parser (3.3.10.0)
ast (~> 2.4.1)
racc
racc (1.7.3)
prism (1.6.0)
public_suffix (7.0.0)
racc (1.8.1)
rainbow (3.1.1)
rake (13.1.0)
regexp_parser (2.9.0)
rexml (3.2.6)
rubocop (1.59.0)
regexp_parser (2.11.3)
rexml (3.4.4)
rubocop (1.81.7)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.47.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-performance (1.20.2)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.48.0)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-performance (1.26.1)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.47.1, < 2.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
standard (1.33.0)
securerandom (0.4.1)
standard (1.52.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.59.0)
rubocop (~> 1.81.7)
standard-custom (~> 1.0.0)
standard-performance (~> 1.3)
standard-performance (~> 1.8)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.3.1)
standard-performance (1.9.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.20.2)
rubocop-performance (~> 1.26.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.1.0)
uri (1.1.1)
webmock (3.26.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
arm64-darwin-22
ruby

DEPENDENCIES
concurrent-ruby
dato_cms_graphql!
minitest (~> 5.16)
minitest (~> 5.21)
mocha
rake (~> 13.0)
standard (~> 1.3)
webmock

BUNDLED WITH
2.5.5
Loading