You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Core code lives in `lib/active_shopify_graphql/`, with entrypoint `lib/active_shopify_graphql.rb` and loaders/associations split into focused files.
5
+
- Tests sit in `spec/` using RSpec; shared config is in `spec/spec_helper.rb`.
6
+
- Executables and setup utilities are in `bin/` (`bin/setup`, `bin/console`); Rake tasks are defined in `Rakefile`.
7
+
8
+
## Build, Test, and Development Commands
9
+
-`bundle install` — install dependencies (required before any other command).
10
+
-`bin/setup` — project bootstrap (bundler + any initial prep).
11
+
-`bundle exec rake spec` or just `bundle exec rspec` — run the test suite (default Rake task).
12
+
-`bundle exec rubocop` — lint/format check using `.rubocop.yml`.
13
+
-`bin/console` — interactive console with the gem loaded for quick experiments.
14
+
15
+
## Coding Style & Naming Conventions
16
+
- Ruby 3.2+; prefer idiomatic Ruby with 2-space indentation and frozen string literals already enabled.
17
+
- Follow existing module/loader patterns under `ActiveShopifyGraphQL` (e.g., `AdminApiLoader`, `CustomerAccountApiLoader`).
18
+
- Keep loaders small: expose `fragment` and `map_response_to_attributes` for clarity.
19
+
- Use RuboCop defaults unless explicitly relaxed in `.rubocop.yml`; respect existing disables instead of re-enabling.
20
+
21
+
## Testing Guidelines
22
+
- Framework: RSpec with documentation formatter (`.rspec`).
23
+
- Place specs under `spec/` and name files `*_spec.rb` matching the class/module under test.
24
+
- Do not use `let` or `before` blocks in specs; each test case should tell a complete story.
25
+
- Use verifying doubles instead of normal doubles. Prefer `{instance|class}_{double|spy}` to `double` or `spy`
26
+
- Prefer explicit model/loader fixtures; stub external Shopify calls rather than hitting the network.
27
+
- Aim to cover happy path and schema edge cases (missing attributes, nil fragments). Add regression specs with minimal fixtures.
28
+
29
+
## Commit & Pull Request Guidelines
30
+
- Use short, imperative commit subjects (≈50 chars) with focused diffs; group related changes together.
31
+
- Reference issues in commit messages or PR bodies when relevant.
32
+
- PRs should include: what changed, why, and how to test (commands run, expected outcomes). Add screenshots only if user-facing behavior is affected.
33
+
- Ensure CI-critical commands (`bundle exec rake spec`, `bundle exec rubocop`) pass locally before opening a PR.
34
+
35
+
## Security & Configuration Tips
36
+
- Verify Admin vs Customer Account API client selection when adding loaders; avoid leaking tokens between contexts.
37
+
- If introducing new configuration knobs, document defaults and required environment variables in `README.md` and add minimal validation in configuration objects.
Attributes are now defined directly in the model class using the `attribute` method. The GraphQL fragments and response mapping are automatically generated!
72
81
73
-
Create loader classes to define how to fetch and map data from Shopify's GraphQL APIs:
The metafield attributes automatically generate the correct GraphQL syntax and handle value extraction from either `value` or `jsonValue` fields based on the type.
144
+
145
+
#### API-Specific Attributes
146
+
147
+
For models that need different attributes depending on the API being used, you can define loader-specific overrides:
The `where` method automatically converts Ruby conditions into Shopify's GraphQL query syntax and validates that the query fields are supported by Shopify.
220
+
221
+
### Optimizing Queries with Select
222
+
223
+
Use the `select` method to only fetch specific attributes, reducing GraphQL query size and improving performance:
customer =Customer.find("gid://shopify/Customer/123456789")# or Customer.find(123456789)
171
288
172
289
# Access associated orders (lazy loaded)
173
290
customer.rewards
@@ -191,16 +308,22 @@ The associations automatically handle Shopify GID format conversion, extracting
191
308
192
309
## Next steps
193
310
194
-
-[ ] Support `Model.where(param: value)` proxying params to the GraphQL query attribute
311
+
-[x] Support `Model.where(param: value)` proxying params to the GraphQL query attribute
312
+
-[x] Attribute-based model definition with automatic GraphQL fragment generation
313
+
-[x] Metafield attributes for easy access to Shopify metafields
314
+
-[x] Query optimization with `select` method
195
315
-[ ] Eager loading of GraphQL connections via `Customer.includes(:orders).find(id)` in a single GraphQL query
316
+
-[ ] Better error handling and retry mechanisms for GraphQL API calls
317
+
-[ ] Caching layer for frequently accessed data
318
+
-[ ] Support for GraphQL subscriptions
196
319
197
320
## Development
198
321
199
322
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
200
323
201
324
## Contributing
202
325
203
-
Bug reports and pull requests are welcome on GitHub at https://github.com/team-cometeer/active_shopify_graphql.
326
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nebulab/active_shopify_graphql.
0 commit comments