ralphql 0.1.1
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/.byebug_history +17 -0
- data/.gitignore +12 -0
- data/.rakeTasks +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +95 -0
- data/Guardfile +29 -0
- data/LICENSE.txt +21 -0
- data/README.md +86 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/ralphql.rb +10 -0
- data/lib/ralphql/inflections.rb +31 -0
- data/lib/ralphql/node.rb +94 -0
- data/lib/ralphql/version.rb +5 -0
- data/ralphql.gemspec +41 -0
- metadata +179 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a635d5a16e8a02590511fd54b807607ee9285ebaa64e1062758bcfb1e5bda889
|
4
|
+
data.tar.gz: 9ade863bb30b6d67246a54e8e9aad61fb3d85c3ce0f182448c3eafceb5c41f1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '086e9e4f8ab9cb47de0234ce47755f6fa417e0cb1cbd4f9047b0c82c1b44421c99652b7746c52dca13f380dcb5b4da05b1542d1ab85cb7c310b2aa5de3e91d07'
|
7
|
+
data.tar.gz: 05f4e94903c234b799d26b935db7b228c65ba2848d091406519ca3cdc89eb0500aa40e41bc2be00b15721fa8e256e15495e9eda4eb93d57f1147aeb6c3cf29b0
|
data/.byebug_history
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
c
|
2
|
+
cc
|
3
|
+
c
|
4
|
+
nodes
|
5
|
+
c
|
6
|
+
nodes
|
7
|
+
c
|
8
|
+
args = values.select { |value| value.is_a?(Hash) && value[sym] }.first
|
9
|
+
nodes
|
10
|
+
c
|
11
|
+
nodes
|
12
|
+
c
|
13
|
+
Ralphql.extract({foo: [:bar, {_args: { id: 3 }}]}, :args)
|
14
|
+
Ralphql.extract(foo: [:bar, {_args: { id: 3 }}])
|
15
|
+
result
|
16
|
+
c
|
17
|
+
nodes.class
|
data/.gitignore
ADDED
data/.rakeTasks
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Settings><!--This file was automatically generated by Ruby plugin.
|
3
|
+
You are allowed to:
|
4
|
+
1. Remove rake task
|
5
|
+
2. Add existing rake tasks
|
6
|
+
To add existing rake tasks automatically delete this file and reload the project.
|
7
|
+
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build ralphql-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install ralphql-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install ralphql-0.1.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.0 and build and push ralphql-0.1.0.gem to TODO: Set to 'http://mygemserver.com'" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at jcpenche@hotmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ralphql (0.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
byebug (11.0.1)
|
11
|
+
coderay (1.1.2)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
ffi (1.11.1)
|
14
|
+
formatador (0.2.5)
|
15
|
+
guard (2.15.0)
|
16
|
+
formatador (>= 0.2.4)
|
17
|
+
listen (>= 2.7, < 4.0)
|
18
|
+
lumberjack (>= 1.0.12, < 2.0)
|
19
|
+
nenv (~> 0.1)
|
20
|
+
notiffany (~> 0.0)
|
21
|
+
pry (>= 0.9.12)
|
22
|
+
shellany (~> 0.0)
|
23
|
+
thor (>= 0.18.1)
|
24
|
+
guard-compat (1.2.1)
|
25
|
+
guard-rspec (4.7.3)
|
26
|
+
guard (~> 2.1)
|
27
|
+
guard-compat (~> 1.1)
|
28
|
+
rspec (>= 2.99.0, < 4.0)
|
29
|
+
guard-rubocop (1.3.0)
|
30
|
+
guard (~> 2.0)
|
31
|
+
rubocop (~> 0.20)
|
32
|
+
jaro_winkler (1.5.3)
|
33
|
+
listen (3.1.5)
|
34
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
35
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
36
|
+
ruby_dep (~> 1.2)
|
37
|
+
lumberjack (1.0.13)
|
38
|
+
method_source (0.9.2)
|
39
|
+
nenv (0.3.0)
|
40
|
+
notiffany (0.1.3)
|
41
|
+
nenv (~> 0.1)
|
42
|
+
shellany (~> 0.0)
|
43
|
+
parallel (1.17.0)
|
44
|
+
parser (2.6.3.0)
|
45
|
+
ast (~> 2.4.0)
|
46
|
+
pry (0.12.2)
|
47
|
+
coderay (~> 1.1.0)
|
48
|
+
method_source (~> 0.9.0)
|
49
|
+
rainbow (3.0.0)
|
50
|
+
rake (10.5.0)
|
51
|
+
rb-fsevent (0.10.3)
|
52
|
+
rb-inotify (0.10.0)
|
53
|
+
ffi (~> 1.0)
|
54
|
+
rspec (3.8.0)
|
55
|
+
rspec-core (~> 3.8.0)
|
56
|
+
rspec-expectations (~> 3.8.0)
|
57
|
+
rspec-mocks (~> 3.8.0)
|
58
|
+
rspec-core (3.8.2)
|
59
|
+
rspec-support (~> 3.8.0)
|
60
|
+
rspec-expectations (3.8.4)
|
61
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
+
rspec-support (~> 3.8.0)
|
63
|
+
rspec-mocks (3.8.1)
|
64
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
+
rspec-support (~> 3.8.0)
|
66
|
+
rspec-support (3.8.2)
|
67
|
+
rubocop (0.74.0)
|
68
|
+
jaro_winkler (~> 1.5.1)
|
69
|
+
parallel (~> 1.10)
|
70
|
+
parser (>= 2.6)
|
71
|
+
rainbow (>= 2.2.2, < 4.0)
|
72
|
+
ruby-progressbar (~> 1.7)
|
73
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
74
|
+
ruby-progressbar (1.10.1)
|
75
|
+
ruby_dep (1.5.0)
|
76
|
+
shellany (0.0.1)
|
77
|
+
thor (0.20.3)
|
78
|
+
unicode-display_width (1.6.0)
|
79
|
+
|
80
|
+
PLATFORMS
|
81
|
+
ruby
|
82
|
+
|
83
|
+
DEPENDENCIES
|
84
|
+
bundler (~> 2.0)
|
85
|
+
byebug
|
86
|
+
guard
|
87
|
+
guard-rspec
|
88
|
+
guard-rubocop
|
89
|
+
rake (~> 10.0)
|
90
|
+
ralphql!
|
91
|
+
rspec (~> 3.0)
|
92
|
+
rubocop
|
93
|
+
|
94
|
+
BUNDLED WITH
|
95
|
+
2.0.2
|
data/Guardfile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A sample Guardfile
|
4
|
+
# More info at https://github.com/guard/guard#readme
|
5
|
+
|
6
|
+
## Uncomment and set this to only include directories you want to watch
|
7
|
+
# directories %w(app lib config test spec features) \
|
8
|
+
# .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
9
|
+
|
10
|
+
## Note: if you are using the `directories` clause above and you are not
|
11
|
+
## watching the project directory ('.'), then you will want to move
|
12
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
13
|
+
#
|
14
|
+
# $ mkdir config
|
15
|
+
# $ mv Guardfile config/
|
16
|
+
# $ ln -s config/Guardfile .
|
17
|
+
#
|
18
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
19
|
+
|
20
|
+
guard :rspec, cmd: 'rspec' do
|
21
|
+
watch(%r{^spec/.+_spec\.rb$})
|
22
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
23
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
24
|
+
end
|
25
|
+
|
26
|
+
guard :rubocop, all_on_start: false, cli: ['--display-cop-names', '--auto-correct'] do
|
27
|
+
watch(/.+\.rb$/)
|
28
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
29
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Jake
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Ralphql
|
2
|
+
|
3
|
+
Ralphql is a DSL language written in ruby to aid in the creation fo GraphQL queries.
|
4
|
+
It provides convenient methods to create and update queries as needed.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'ralphql'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install ralphql
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
node = Ralphql::Node.new(:query_name, atts: %i[id name])
|
26
|
+
node.add Ralphql::Node.new(:items, atts: %i[title body], args: { first: 3 })
|
27
|
+
|
28
|
+
node.query
|
29
|
+
#=> "{queryName{id name items(first:3){title body}}}"
|
30
|
+
```
|
31
|
+
|
32
|
+
###Atts
|
33
|
+
Attributes are string, they represent attribute names of a query, they dont contain options. Ralphql camelizes for you.
|
34
|
+
```ruby
|
35
|
+
Ralphql::Node.new(:query_name, atts: :id).query
|
36
|
+
#=> "{queryName{id}}"
|
37
|
+
Ralphql::Node.new(:query_name, atts: %i[name simple_body]).query
|
38
|
+
#=> "{queryName{name simpleBody}}"
|
39
|
+
```
|
40
|
+
|
41
|
+
###Args
|
42
|
+
Arguments affect the nodes query, you can write them snake cased and Ralphql camelizes for you. For example
|
43
|
+
```ruby
|
44
|
+
Ralphql::Node.new(:query_name, args: { first: 3, order: 'id' }, atts: :id).query
|
45
|
+
#=> "{queryName(first:3,order:'id'){id}}"
|
46
|
+
```
|
47
|
+
|
48
|
+
###Pagination
|
49
|
+
Ralphql can take care of pagination for you. As of this version pagination includes all
|
50
|
+
attributes and updates the body accordingly. So for example:
|
51
|
+
```ruby
|
52
|
+
Ralphql::Node.new(:query_name, atts: :id).query
|
53
|
+
#=> "{queryName{id}}"
|
54
|
+
Ralphql::Node.new(:query_name, atts: :id, paginated: true).query
|
55
|
+
#=> "{queryName{pageInfo{endCursor startCursor hasPreviousPage hasNextPage}edges{cursor node{id}}}}"
|
56
|
+
```
|
57
|
+
|
58
|
+
###Nodes
|
59
|
+
Every node can have many child nodes and almost every node has a parent node. Ralphql takes care of this for you.
|
60
|
+
It allows to build complex queries where attributes are queries themselves with arguments, pagination...etc etc
|
61
|
+
```ruby
|
62
|
+
node = Ralphql::Node.new(:query_name, atts: %i[name])
|
63
|
+
node.add Ralphql::Node.new(:items, atts: %i[id name], args: { exclude: :unpublished })
|
64
|
+
node.add Ralphql::Node.new(:comments, atts: %i[title body], args: { first: 3, order: :popular }, paginated: true)
|
65
|
+
|
66
|
+
node.query
|
67
|
+
#=> "{queryName{name items(exclude:'unpublished'){id name} comments(first:3,order:'popular'){pageInfo{endCursor startCursor hasPreviousPage hasNextPage}edges{cursor node{title body}}}}}"
|
68
|
+
```
|
69
|
+
|
70
|
+
## Development
|
71
|
+
|
72
|
+
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.
|
73
|
+
|
74
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/wolas/ralphql. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
83
|
+
|
84
|
+
## Code of Conduct
|
85
|
+
|
86
|
+
Everyone interacting in the Ralphql project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/wolas/ralphql/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'ralphql'
|
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
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/ralphql.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
def to_ralphql
|
5
|
+
"{#{map { |key, value| "#{key}:#{value.to_ralphql}" }.join(', ')}}"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Integer
|
10
|
+
def to_ralphql
|
11
|
+
self
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class String
|
16
|
+
def to_ralphql
|
17
|
+
"'#{self}'"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Symbol
|
22
|
+
def to_ralphql
|
23
|
+
"'#{self}'"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Array
|
28
|
+
def to_ralphql
|
29
|
+
"[#{map(&:to_ralphql).join(', ')}]"
|
30
|
+
end
|
31
|
+
end
|
data/lib/ralphql/node.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ralphql
|
4
|
+
# A Node represents a query type object in GraphQL.
|
5
|
+
# It has name, attributes, arguments and other associated nodes.
|
6
|
+
# It can be paginated, which includes rails GraphQL default
|
7
|
+
# pagination attributes and the edges, nodes schema
|
8
|
+
#
|
9
|
+
class Node
|
10
|
+
attr_accessor :parent_node
|
11
|
+
|
12
|
+
PAGINATION_ATTS = %i[endCursor startCursor hasPreviousPage hasNextPage].freeze
|
13
|
+
|
14
|
+
def initialize(name, opts = {})
|
15
|
+
@name = name
|
16
|
+
@args = opts[:args] || {}
|
17
|
+
@atts = [opts[:atts]].flatten.compact
|
18
|
+
@nodes = [opts[:nodes]].flatten.compact
|
19
|
+
@parent_node = opts[:parent_node]
|
20
|
+
@paginated = opts[:paginated] || false
|
21
|
+
|
22
|
+
@nodes.each { |node| node.parent_node = self }
|
23
|
+
end
|
24
|
+
|
25
|
+
def query
|
26
|
+
raise EmptyNodeError if empty_body? && @args.empty?
|
27
|
+
|
28
|
+
args = resolve_args
|
29
|
+
body = resolve_body
|
30
|
+
|
31
|
+
result = camelize(@name) + args + body
|
32
|
+
result = "{#{result}}" if @parent_node.nil?
|
33
|
+
result
|
34
|
+
end
|
35
|
+
|
36
|
+
def replace(opts)
|
37
|
+
@name = opts[:name] if opts[:name]
|
38
|
+
@args = opts[:args] if opts[:args]
|
39
|
+
@atts = [opts[:atts]].flatten if opts[:atts]
|
40
|
+
@nodes = [opts[:nodes]].flatten if opts[:nodes]
|
41
|
+
@parent_node = opts[:parent_node] if opts[:parent_node]
|
42
|
+
@paginated = opts[:paginated] if opts[:paginated]
|
43
|
+
end
|
44
|
+
|
45
|
+
def add(obj)
|
46
|
+
case obj
|
47
|
+
when Symbol then @atts << obj.to_s
|
48
|
+
when String then @atts << obj
|
49
|
+
when Array then @atts += obj.map(&:to_s)
|
50
|
+
when Node then obj.parent_node = self && @nodes << obj
|
51
|
+
else raise AttributeNotSupportedError
|
52
|
+
end
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
def add_node(name, args: {}, atts: [], nodes: [], paginated: false)
|
57
|
+
node = self.class.new(name, args: args, atts: atts, nodes: nodes, paginated: paginated)
|
58
|
+
add(node)
|
59
|
+
node
|
60
|
+
end
|
61
|
+
|
62
|
+
def empty_body?
|
63
|
+
@nodes.empty? && @atts.empty?
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def resolve_args
|
69
|
+
args = @args.map { |arg, value| "#{camelize(arg)}:#{value.to_ralphql}" }
|
70
|
+
args = args.to_a.join(',')
|
71
|
+
args = "(#{args})" if args.size > 1
|
72
|
+
args
|
73
|
+
end
|
74
|
+
|
75
|
+
def resolve_body
|
76
|
+
body = @atts.map { |att| camelize(att) }.join(' ')
|
77
|
+
body += ' ' if @atts.any? && @nodes.any?
|
78
|
+
body += @nodes.map(&:query).join(' ')
|
79
|
+
body = resolve_pagination(body)
|
80
|
+
|
81
|
+
empty_body? ? body : "{#{body}}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def resolve_pagination(body)
|
85
|
+
return body unless @paginated
|
86
|
+
|
87
|
+
"pageInfo{#{PAGINATION_ATTS.join(' ')}}edges{cursor node{#{body}}}"
|
88
|
+
end
|
89
|
+
|
90
|
+
def camelize(term)
|
91
|
+
term.to_s.gsub(%r{(?:_|(/))([a-z\d]*)}i) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/ralphql.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'ralphql/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'ralphql'
|
9
|
+
spec.version = Ralphql::VERSION
|
10
|
+
spec.authors = ['Jake']
|
11
|
+
spec.email = ['jcpenche@hotmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'A ruby DSL for graphQL queries'
|
14
|
+
spec.description = 'A ruby DSL for graphQL queries'
|
15
|
+
spec.homepage = 'https://github.com/wolas/ralphql'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
19
|
+
|
20
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
21
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
22
|
+
spec.metadata['changelog_uri'] = spec.homepage
|
23
|
+
|
24
|
+
# Specify which files should be added to the gem when it is released.
|
25
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
34
|
+
spec.add_development_dependency 'byebug'
|
35
|
+
spec.add_development_dependency 'guard'
|
36
|
+
spec.add_development_dependency 'guard-rspec'
|
37
|
+
spec.add_development_dependency 'guard-rubocop'
|
38
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
39
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
40
|
+
spec.add_development_dependency 'rubocop'
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ralphql
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jake
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: A ruby DSL for graphQL queries
|
126
|
+
email:
|
127
|
+
- jcpenche@hotmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".byebug_history"
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rakeTasks"
|
135
|
+
- ".rspec"
|
136
|
+
- ".rubocop.yml"
|
137
|
+
- ".travis.yml"
|
138
|
+
- CODE_OF_CONDUCT.md
|
139
|
+
- Gemfile
|
140
|
+
- Gemfile.lock
|
141
|
+
- Guardfile
|
142
|
+
- LICENSE.txt
|
143
|
+
- README.md
|
144
|
+
- Rakefile
|
145
|
+
- bin/console
|
146
|
+
- bin/setup
|
147
|
+
- lib/ralphql.rb
|
148
|
+
- lib/ralphql/inflections.rb
|
149
|
+
- lib/ralphql/node.rb
|
150
|
+
- lib/ralphql/version.rb
|
151
|
+
- ralphql.gemspec
|
152
|
+
homepage: https://github.com/wolas/ralphql
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata:
|
156
|
+
allowed_push_host: https://rubygems.org
|
157
|
+
homepage_uri: https://github.com/wolas/ralphql
|
158
|
+
source_code_uri: https://github.com/wolas/ralphql
|
159
|
+
changelog_uri: https://github.com/wolas/ralphql
|
160
|
+
post_install_message:
|
161
|
+
rdoc_options: []
|
162
|
+
require_paths:
|
163
|
+
- lib
|
164
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
requirements: []
|
175
|
+
rubygems_version: 3.0.4
|
176
|
+
signing_key:
|
177
|
+
specification_version: 4
|
178
|
+
summary: A ruby DSL for graphQL queries
|
179
|
+
test_files: []
|