Skip to content

Commit dfc852f

Browse files
sshawclaude
andcommitted
Initial commit
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
0 parents  commit dfc852f

26 files changed

+2235
-0
lines changed

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SHOPIFY_DOMAIN=
2+
SHOPIFY_TOKEN=
3+
BULK_SUCCESS_ID=
4+
BULK_FAILED_ID_ERRORS=
5+
BULK_FAILED_ID_USER_ERRORS=
6+
BULK_PARTIAL_ID=

.github/workflows/main.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
env:
11+
SHOPIFY_DOMAIN: "${{ secrets.SHOPIFY_DOMAIN }}"
12+
SHOPIFY_TOKEN: "${{ secrets.SHOPIFY_TOKEN }}"
13+
BULK_SUCCESS_ID: "${{ secrets.BULK_SUCCESS_ID }}"
14+
BULK_FAILED_ID_ERRORS: "${{ secrets.BULK_FAILED_ID_ERRORS }}"
15+
BULK_FAILED_ID_USER_ERRORS: "${{ secrets.BULK_FAILED_ID_USER_ERRORS }}"
16+
BULK_CANCELED_ID: "${{ secrets.BULK_CANCELED_ID }}"
17+
BULK_PARTIAL_ID: "${{ secrets.BULK_PARTIAL_ID }}"
18+
19+
strategy:
20+
matrix:
21+
ruby: ['3.4', '3.3', '3.2', '3.1', '3.0', '2.7']
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: ruby/setup-ruby@v1
26+
with:
27+
bundler-cache: true
28+
ruby-version: ${{ matrix.ruby }}
29+
bundler: '2.4.22'
30+
31+
- run: bundle install
32+
- run: bundle exec rake

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/
9+
10+
# rspec failure tracking
11+
.rspec_status
12+
.env
13+
.env.test

.rspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--format documentation
2+
--color
3+
--require spec_helper

Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
# Specify your gem's dependencies in shopify_api-graphql-bulk.gemspec
6+
gemspec
7+
8+
gem "irb"

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2026 sshaw
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.

README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# ShopifyAPI::GraphQL::Bulk
2+
3+
Bulk import data with the [Shopify GraphQL Admin Bulk API](https://shopify.dev/docs/api/usage/bulk-operations/imports)
4+
5+
## Install
6+
7+
`Gemfile`:
8+
9+
```rb
10+
gem "shopify_api-graphql-bulk"
11+
```
12+
13+
Or via the `gem` command:
14+
15+
```
16+
gem install "shopify_api-graphql-bulk"
17+
```
18+
19+
## Usage
20+
21+
```rb
22+
# Mutation parameters. Here we'll use the productSet mutation.
23+
params = [
24+
{
25+
:identifier => { :handle => "handle-1" },
26+
:input => {
27+
:title => "My New Title",
28+
:handle => "handle-1",
29+
# More params
30+
}
31+
},
32+
{
33+
:identifier => { :handle => "handle-2" },
34+
:input => {
35+
:title => "Another Title",
36+
:handle => "handle-2",
37+
# More params
38+
}
39+
},
40+
# etc...
41+
]
42+
43+
bulk = ShopifyAPI::GraphQL::Bulk.new(shop, token)
44+
id = bulk.create("productSet", params)
45+
46+
# Wait a bit...
47+
48+
operation = bulk.result(id) # ShopifyAPI::GraphQL::Bulk::Operation instance
49+
p operation.id
50+
p operation.completed_at
51+
p operation.url
52+
# etc...
53+
54+
if operation.completed?
55+
operation.results[:data].each { }
56+
operation.results[:errors].each { }
57+
operation.results[:user_errors].each { }
58+
end
59+
```
60+
61+
`#create` also accepts a block:
62+
63+
```rb
64+
id = bulk.create("mutationName") do |args|
65+
args << input1
66+
args << input2 # etc...
67+
end
68+
```
69+
70+
Cancel a pending request:
71+
72+
```rb
73+
operation = bulk.cancel(id) # returns ShopifyAPI::GraphQL::Bulk::Operation instance
74+
```
75+
76+
`ShopifyAPI::GraphQL::Bulk::Operation` corresponds to the GraphQL `BulkOperation` type.
77+
Hashes returned by this gem have `Symbol` keys that are snake_cased.
78+
79+
## Development
80+
81+
Tests use VCR. To re-record you need to define bulk operation IDs in `.env`. `cp .env.example .env` and update `.env`
82+
83+
## See Also
84+
85+
- [`ShopifyAPI::GraphQL::Request`](https://github.com/ScreenStaring/shopify_api-graphql-request/) - Simplify GraphQL handling. Comes with built-in retry, pagination, error handling, and more!
86+
- [`TinyGID`](https://github.com/sshaw/tiny_gid/) - Build Global ID (`gid://`) URI strings from scalar values
87+
- [Shopify Dev Tools](https://github.com/ScreenStaring/shopify-dev-tools/) - Command-line program to assist with the development and/or maintenance of Shopify apps and stores
88+
89+
## License
90+
91+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
92+
93+
---
94+
95+
Made by [ScreenStaring](http://screenstaring.com)

Rakefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
require "bundler/gem_tasks"
4+
require "rspec/core/rake_task"
5+
6+
Dir.glob("lib/tasks/**/*.rake").each { |r| import r }
7+
8+
RSpec::Core::RakeTask.new(:spec)
9+
10+
task default: :spec

bin/console

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "bundler/setup"
5+
require "shopify_api/graphql/bulk"
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
require "irb"
11+
IRB.start(__FILE__)

bin/setup

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

0 commit comments

Comments
 (0)