active_shopify_graphql 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/lint.yml +35 -0
- data/.github/workflows/test.yml +35 -0
- data/.rubocop.yml +50 -0
- data/AGENTS.md +53 -0
- data/LICENSE.txt +21 -0
- data/README.md +544 -0
- data/Rakefile +8 -0
- data/lib/active_shopify_graphql/associations.rb +90 -0
- data/lib/active_shopify_graphql/attributes.rb +49 -0
- data/lib/active_shopify_graphql/base.rb +29 -0
- data/lib/active_shopify_graphql/configuration.rb +29 -0
- data/lib/active_shopify_graphql/connection_loader.rb +96 -0
- data/lib/active_shopify_graphql/connections/connection_proxy.rb +112 -0
- data/lib/active_shopify_graphql/connections.rb +170 -0
- data/lib/active_shopify_graphql/finder_methods.rb +154 -0
- data/lib/active_shopify_graphql/fragment_builder.rb +195 -0
- data/lib/active_shopify_graphql/gid_helper.rb +54 -0
- data/lib/active_shopify_graphql/graphql_type_resolver.rb +91 -0
- data/lib/active_shopify_graphql/loader.rb +183 -0
- data/lib/active_shopify_graphql/loader_context.rb +88 -0
- data/lib/active_shopify_graphql/loader_switchable.rb +121 -0
- data/lib/active_shopify_graphql/loaders/admin_api_loader.rb +32 -0
- data/lib/active_shopify_graphql/loaders/customer_account_api_loader.rb +71 -0
- data/lib/active_shopify_graphql/metafield_attributes.rb +61 -0
- data/lib/active_shopify_graphql/query_node.rb +160 -0
- data/lib/active_shopify_graphql/query_tree.rb +204 -0
- data/lib/active_shopify_graphql/response_mapper.rb +202 -0
- data/lib/active_shopify_graphql/search_query.rb +71 -0
- data/lib/active_shopify_graphql/version.rb +5 -0
- data/lib/active_shopify_graphql.rb +34 -0
- metadata +147 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 209f2565381c7c64385baecde798f09270b6b1e55df8adaadfaa436c5d0890f2
|
|
4
|
+
data.tar.gz: 3813282f284e46583305ff2afb3ff143a69b8051a60bbcd6f42a567e562685e2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 338c590007e3510507cc197912db871979f77dc8a905cae118a29982a75fd8a74a178dde94ea25f7133857312e8b5d04820d99813c77efd803aadc51b8e49c37
|
|
7
|
+
data.tar.gz: 7f40d85c87be589b9c2df2461c035c43560e3c3ae6a343b2cac209c2c3974374acf7583b68261e1b1f259feb98e8c7310a3a6d11140e5c7314b34e98b9e6f385
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
+
# They are provided by a third-party and are governed by
|
|
3
|
+
# separate terms of service, privacy policy, and support
|
|
4
|
+
# documentation.
|
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
|
7
|
+
|
|
8
|
+
name: Lint with RuboCop
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [ "main" ]
|
|
13
|
+
pull_request:
|
|
14
|
+
branches: [ "main" ]
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
contents: read
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
test:
|
|
21
|
+
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
strategy:
|
|
24
|
+
matrix:
|
|
25
|
+
ruby-version: ['3.4']
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v4
|
|
29
|
+
- name: Set up Ruby
|
|
30
|
+
uses: ruby/setup-ruby@v1
|
|
31
|
+
with:
|
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
34
|
+
- name: Run tests
|
|
35
|
+
run: bundle exec rubocop
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
+
# They are provided by a third-party and are governed by
|
|
3
|
+
# separate terms of service, privacy policy, and support
|
|
4
|
+
# documentation.
|
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
|
7
|
+
|
|
8
|
+
name: Run specs
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [ "main" ]
|
|
13
|
+
pull_request:
|
|
14
|
+
branches: [ "main" ]
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
contents: read
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
test:
|
|
21
|
+
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
strategy:
|
|
24
|
+
matrix:
|
|
25
|
+
ruby-version: ['3.2', '3.3', '3.4']
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v4
|
|
29
|
+
- name: Set up Ruby
|
|
30
|
+
uses: ruby/setup-ruby@v1
|
|
31
|
+
with:
|
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
34
|
+
- name: Run tests
|
|
35
|
+
run: bundle exec rspec
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Style/StringLiterals:
|
|
2
|
+
Enabled: false
|
|
3
|
+
|
|
4
|
+
Metrics/BlockLength:
|
|
5
|
+
Enabled: false
|
|
6
|
+
|
|
7
|
+
Style/Documentation:
|
|
8
|
+
Enabled: false
|
|
9
|
+
|
|
10
|
+
Metrics/CyclomaticComplexity:
|
|
11
|
+
Enabled: false
|
|
12
|
+
|
|
13
|
+
Metrics/AbcSize:
|
|
14
|
+
Enabled: false
|
|
15
|
+
|
|
16
|
+
Metrics/MethodLength:
|
|
17
|
+
Enabled: false
|
|
18
|
+
|
|
19
|
+
Metrics/ModuleLength:
|
|
20
|
+
Enabled: false
|
|
21
|
+
|
|
22
|
+
Layout/LineLength:
|
|
23
|
+
Enabled: false
|
|
24
|
+
|
|
25
|
+
Lint/MissingSuper:
|
|
26
|
+
Enabled: false
|
|
27
|
+
|
|
28
|
+
Metrics/PerceivedComplexity:
|
|
29
|
+
Enabled: false
|
|
30
|
+
|
|
31
|
+
Naming/PredicatePrefix:
|
|
32
|
+
Enabled: false
|
|
33
|
+
|
|
34
|
+
Style/TrailingCommaInHashLiteral:
|
|
35
|
+
Enabled: false
|
|
36
|
+
|
|
37
|
+
Style/TrailingCommaInArrayLiteral:
|
|
38
|
+
Enabled: false
|
|
39
|
+
|
|
40
|
+
Metrics/ParameterLists:
|
|
41
|
+
Enabled: false
|
|
42
|
+
|
|
43
|
+
Metrics/ClassLength:
|
|
44
|
+
Enabled: false
|
|
45
|
+
|
|
46
|
+
Naming/MethodParameterName:
|
|
47
|
+
Enabled: false
|
|
48
|
+
|
|
49
|
+
Naming/AccessorMethodName:
|
|
50
|
+
Enabled: false
|
data/AGENTS.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Repository Guidelines
|
|
2
|
+
|
|
3
|
+
## Project Structure & Module Organization
|
|
4
|
+
- 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
|
+
## GID (Global ID) Handling
|
|
22
|
+
- **Always** use `URI::GID.build` to construct Shopify GIDs programmatically; never concatenate strings manually.
|
|
23
|
+
- **Always** use `URI::GID.parse` to validate and parse existing GID strings.
|
|
24
|
+
- GID format: `gid://shopify/ModelName/id_value` where `app: 'shopify'`, `model_name:` is the GraphQL type (e.g., `Customer`, `Order`), and `model_id:` is the numeric or string identifier.
|
|
25
|
+
- When building GIDs, use `model_name.name.demodulize` to extract the model type name (e.g., `Customer` from `ActiveShopifyGraphQL::Customer`) unless it's specified via the model's `graphql_type`.
|
|
26
|
+
- When checking if a value is already a GID, parse it with `URI::GID.parse` and handle exceptions (`URI::InvalidURIError`, `URI::BadURIError`, `ArgumentError`).
|
|
27
|
+
- Examples:
|
|
28
|
+
- Build: `URI::GID.build(app: "shopify", model_name: "Customer", model_id: 123).to_s` → `"gid://shopify/Customer/123"`
|
|
29
|
+
- Parse: `URI::GID.parse("gid://shopify/Customer/123")` → returns a `URI::GID` object
|
|
30
|
+
- Check validity: Wrap `URI::GID.parse` in a rescue block to detect non-GID strings.
|
|
31
|
+
|
|
32
|
+
## Testing Guidelines
|
|
33
|
+
- Framework: RSpec with documentation formatter (`.rspec`).
|
|
34
|
+
- Place specs under `spec/` and name files `*_spec.rb` matching the class/module under test.
|
|
35
|
+
- Do not use `let` or `before` blocks in specs; each test case should tell a complete story.
|
|
36
|
+
- Use verifying doubles instead of normal doubles. Prefer `{instance|class}_{double|spy}` to `double` or `spy`
|
|
37
|
+
- Prefer explicit model/loader fixtures; stub external Shopify calls rather than hitting the network.
|
|
38
|
+
- Aim to cover happy path and schema edge cases (missing attributes, nil fragments). Add regression specs with minimal fixtures.
|
|
39
|
+
|
|
40
|
+
## Commit & Pull Request Guidelines
|
|
41
|
+
- Use short, imperative commit subjects (≈50 chars) with focused diffs; group related changes together.
|
|
42
|
+
- Reference issues in commit messages or PR bodies when relevant.
|
|
43
|
+
- PRs should include: what changed, why, and how to test (commands run, expected outcomes). Add screenshots only if user-facing behavior is affected.
|
|
44
|
+
- When changing public APIs, update relevant documentation in the README.
|
|
45
|
+
- Ensure CI-critical commands (`bundle exec rake spec`, `bundle exec rubocop`) pass locally before opening a PR.
|
|
46
|
+
|
|
47
|
+
## Security & Configuration Tips
|
|
48
|
+
- Verify Admin vs Customer Account API client selection when adding loaders; avoid leaking tokens between contexts.
|
|
49
|
+
- If introducing new configuration knobs, document defaults and required environment variables in `README.md` and add minimal validation in configuration objects.
|
|
50
|
+
|
|
51
|
+
## Implementation details
|
|
52
|
+
- ALWAYS use inline argument values instead of arguments in the root query signature. This makes orders of magnitude easier working with enums, we move the burden on the developer instead of the gem.
|
|
53
|
+
- Instead of passing down arguments in deep method chains, PREFER orthogonally using configurations. If you notice doing this in your work, consider extracting that to a config.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Nicolò Rebughini
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|