graphql-extras 0.2.1 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +25 -0
- data/.github/workflows/publish.yml +41 -0
- data/README.md +9 -2
- data/graphql-extras.gemspec +5 -5
- data/lib/graphql/extras/rspec.rb +46 -16
- data/lib/graphql/extras/types.rb +17 -2
- data/lib/graphql/extras/version.rb +1 -1
- metadata +15 -15
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51f813e6dda5daf0c9c0b94a768b2dc339c19e45ae08277b7fa6e1f0b7a33361
|
4
|
+
data.tar.gz: c0359145f282a0e86ea53e23a5240712c2cde97331daec88d2b754244fe5af4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58851891def9df659c6effdc2633954ffdcafbfcad544196b32f1f502bacd8d6d227e3e3a95b78bf418859b2541a284f746368934d6fa3fd8000ae36a53b86a2
|
7
|
+
data.tar.gz: 21517e559a3ab8835839b16b39689b780118838d016e9348b0c3189309ae6dfc57376eee89f920423b78ebd0f8577b18e2b796ce72f721dc8460fe00d62041b0
|
@@ -0,0 +1,25 @@
|
|
1
|
+
name: Build
|
2
|
+
on: [push]
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
runs-on: ubuntu-latest
|
6
|
+
steps:
|
7
|
+
- name: Checkout
|
8
|
+
uses: actions/checkout@v2
|
9
|
+
|
10
|
+
- name: Setup Ruby
|
11
|
+
uses: actions/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 2.6.x
|
14
|
+
|
15
|
+
- name: Install packages
|
16
|
+
run: sudo apt-get install libsqlite3-dev
|
17
|
+
|
18
|
+
- name: Install bundler
|
19
|
+
run: gem install bundler
|
20
|
+
|
21
|
+
- name: Install dependencies
|
22
|
+
run: bundle install
|
23
|
+
|
24
|
+
- name: Test
|
25
|
+
run: bundle exec rspec
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: Publish
|
2
|
+
on:
|
3
|
+
release:
|
4
|
+
types: [published]
|
5
|
+
jobs:
|
6
|
+
publish:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- name: Checkout
|
10
|
+
uses: actions/checkout@v2
|
11
|
+
|
12
|
+
- name: Setup Ruby
|
13
|
+
uses: actions/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 2.6.x
|
16
|
+
|
17
|
+
- name: Install packages
|
18
|
+
run: sudo apt-get install libsqlite3-dev
|
19
|
+
|
20
|
+
- name: Install bundler
|
21
|
+
run: gem install bundler
|
22
|
+
|
23
|
+
- name: Install dependencies
|
24
|
+
run: bundle install
|
25
|
+
|
26
|
+
- name: Test
|
27
|
+
run: bundle exec rspec
|
28
|
+
|
29
|
+
- name: Set version
|
30
|
+
run: perl -pi -e "s/0\.0\.0/${GITHUB_REF:11}/" lib/graphql/extras/version.rb
|
31
|
+
|
32
|
+
- name: Publish
|
33
|
+
run: |
|
34
|
+
mkdir -p $HOME/.gem
|
35
|
+
touch $HOME/.gem/credentials
|
36
|
+
chmod 0600 $HOME/.gem/credentials
|
37
|
+
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_TOKEN}\n" > $HOME/.gem/credentials
|
38
|
+
gem build *.gemspec
|
39
|
+
gem push *.gem
|
40
|
+
env:
|
41
|
+
RUBYGEMS_TOKEN: ${{ secrets.RUBYGEMS_TOKEN }}
|
data/README.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
|
1
|
+
<h1 align="center">GraphQL::Extras</h1>
|
2
|
+
|
3
|
+
<div align="center">
|
4
|
+
|
5
|
+
![Build](https://github.com/rzane/graphql-extras/workflows/CI/badge.svg)
|
6
|
+
![Version](https://img.shields.io/gem/v/graphql-extras)
|
7
|
+
|
8
|
+
</div>
|
2
9
|
|
3
10
|
A collection of utilities for building GraphQL APIs.
|
4
11
|
|
@@ -117,7 +124,7 @@ Here's an example using CURL:
|
|
117
124
|
|
118
125
|
Take note of the correspondence between the value `"image"` and the additional HTTP parameter called `-F image=@cats.png`.
|
119
126
|
|
120
|
-
See [apollo-
|
127
|
+
See [apollo-link-upload](https://github.com/rzane/apollo-link-upload) for the client-side implementation.
|
121
128
|
|
122
129
|
### RSpec integration
|
123
130
|
|
data/graphql-extras.gemspec
CHANGED
@@ -24,15 +24,15 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
|
-
spec.add_dependency "activesupport", "
|
27
|
+
spec.add_dependency "activesupport", ">= 5.2"
|
28
28
|
spec.add_dependency "graphql", "~> 1.9"
|
29
29
|
spec.add_dependency "graphql-batch", "~> 0.4"
|
30
30
|
|
31
31
|
spec.add_development_dependency "bundler", "~> 2.0"
|
32
|
-
spec.add_development_dependency "rake", "~>
|
32
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
33
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
-
spec.add_development_dependency "rspec-rails", "~>
|
35
|
-
spec.add_development_dependency "actionpack", "
|
36
|
-
spec.add_development_dependency "activerecord", "
|
34
|
+
spec.add_development_dependency "rspec-rails", "~> 4.0"
|
35
|
+
spec.add_development_dependency "actionpack", ">= 5.2"
|
36
|
+
spec.add_development_dependency "activerecord", ">= 5.2"
|
37
37
|
spec.add_development_dependency "sqlite3", "~> 1.4"
|
38
38
|
end
|
data/lib/graphql/extras/rspec.rb
CHANGED
@@ -6,10 +6,8 @@ module GraphQL
|
|
6
6
|
module Extras
|
7
7
|
module RSpec
|
8
8
|
class Queries
|
9
|
-
def
|
10
|
-
|
11
|
-
define_singleton_method(key) { value }
|
12
|
-
end
|
9
|
+
def add(key, value)
|
10
|
+
define_singleton_method(key) { value }
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
@@ -63,23 +61,55 @@ module GraphQL
|
|
63
61
|
end
|
64
62
|
end
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
class Parser
|
65
|
+
include ::GraphQL::Language
|
66
|
+
|
67
|
+
def initialize(document)
|
68
|
+
@operations = document.definitions
|
69
|
+
.grep(Nodes::OperationDefinition)
|
70
|
+
|
71
|
+
@fragments = document.definitions
|
72
|
+
.grep(Nodes::FragmentDefinition)
|
73
|
+
.reduce({}) { |acc, f| acc.merge(f.name => f) }
|
74
|
+
end
|
69
75
|
|
70
|
-
|
71
|
-
|
76
|
+
def parse
|
77
|
+
queries = Queries.new
|
78
|
+
printer = Printer.new
|
72
79
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
80
|
+
@operations.each do |op|
|
81
|
+
nodes = [op, *find_fragments(op)]
|
82
|
+
nodes = nodes.map { |node| printer.print(node) }
|
83
|
+
queries.add op.name.underscore, nodes.join
|
84
|
+
end
|
77
85
|
|
78
|
-
|
86
|
+
queries
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def find_fragments(node)
|
92
|
+
node.selections.flat_map do |field|
|
93
|
+
if field.is_a? Nodes::FragmentSpread
|
94
|
+
fragment = @fragments.fetch(field.name)
|
95
|
+
[fragment, *find_fragments(fragment)]
|
96
|
+
else
|
97
|
+
find_fragments(field)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def graphql_fixture(filename)
|
104
|
+
root = ::RSpec.configuration.graphql_fixture_path
|
105
|
+
file = File.join(root, filename)
|
106
|
+
document = ::GraphQL.parse_file(file)
|
107
|
+
parser = Parser.new(document)
|
108
|
+
parser.parse
|
79
109
|
end
|
80
110
|
|
81
|
-
def use_schema(*args)
|
82
|
-
Schema.new(*args)
|
111
|
+
def use_schema(*args, **opts)
|
112
|
+
Schema.new(*args, **opts)
|
83
113
|
end
|
84
114
|
end
|
85
115
|
end
|
data/lib/graphql/extras/types.rb
CHANGED
@@ -6,10 +6,19 @@ module GraphQL
|
|
6
6
|
module Extras
|
7
7
|
module Types
|
8
8
|
class DateTime < GraphQL::Types::ISO8601DateTime
|
9
|
+
description <<~DESC
|
10
|
+
The `DateTime` scalar type represents a date and time in the UTC
|
11
|
+
timezone. The DateTime appears in a JSON response as an ISO8601 formatted
|
12
|
+
string, including UTC timezone ("Z"). The parsed date and time string will
|
13
|
+
be converted to UTC and any UTC offset other than 0 will be rejected.
|
14
|
+
DESC
|
9
15
|
end
|
10
16
|
|
11
17
|
class Date < GraphQL::Schema::Scalar
|
12
|
-
description
|
18
|
+
description <<~DESC
|
19
|
+
The `Date` scalar type represents a date. The Date appears in a JSON
|
20
|
+
response as an ISO8601 formatted string.
|
21
|
+
DESC
|
13
22
|
|
14
23
|
def self.coerce_input(value, _context)
|
15
24
|
::Date.iso8601(value)
|
@@ -23,7 +32,11 @@ module GraphQL
|
|
23
32
|
end
|
24
33
|
|
25
34
|
class Decimal < GraphQL::Schema::Scalar
|
26
|
-
description
|
35
|
+
description <<~DESC
|
36
|
+
The `Decimal` scalar type represents signed double-precision fractional
|
37
|
+
values parsed by the `Decimal` library. The Decimal appears in a JSON
|
38
|
+
response as a string to preserve precision.
|
39
|
+
DESC
|
27
40
|
|
28
41
|
def self.coerce_input(value, _context)
|
29
42
|
BigDecimal(value.to_s)
|
@@ -37,6 +50,8 @@ module GraphQL
|
|
37
50
|
end
|
38
51
|
|
39
52
|
class Upload < GraphQL::Schema::Scalar
|
53
|
+
description "Represents an uploaded file."
|
54
|
+
|
40
55
|
def self.coerce_input(value, context)
|
41
56
|
return nil if value.nil?
|
42
57
|
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-extras
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ray Zane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '13.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '13.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,40 +100,40 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '4.0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '4.0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: actionpack
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '5.2'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '5.2'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: activerecord
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - "
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '5.2'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - "
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '5.2'
|
139
139
|
- !ruby/object:Gem::Dependency
|
@@ -157,9 +157,10 @@ executables: []
|
|
157
157
|
extensions: []
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
|
+
- ".github/workflows/build.yml"
|
161
|
+
- ".github/workflows/publish.yml"
|
160
162
|
- ".gitignore"
|
161
163
|
- ".rspec"
|
162
|
-
- ".travis.yml"
|
163
164
|
- Gemfile
|
164
165
|
- README.md
|
165
166
|
- Rakefile
|
@@ -192,8 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
193
|
- !ruby/object:Gem::Version
|
193
194
|
version: '0'
|
194
195
|
requirements: []
|
195
|
-
|
196
|
-
rubygems_version: 2.7.6
|
196
|
+
rubygems_version: 3.0.3
|
197
197
|
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Utiltities for building GraphQL APIs.
|