graphql_rails 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.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.hound.yml +3 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +34 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +5 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Gemfile +20 -0
  10. data/Gemfile.lock +98 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +122 -0
  13. data/Rakefile +6 -0
  14. data/bin/console +14 -0
  15. data/bin/setup +8 -0
  16. data/graphql_rails.gemspec +29 -0
  17. data/lib/graphiti.rb +10 -0
  18. data/lib/graphiti/attribute.rb +86 -0
  19. data/lib/graphiti/controller.rb +54 -0
  20. data/lib/graphiti/controller/action_configuration.rb +46 -0
  21. data/lib/graphiti/controller/configuration.rb +32 -0
  22. data/lib/graphiti/controller/controller_function.rb +41 -0
  23. data/lib/graphiti/controller/request.rb +40 -0
  24. data/lib/graphiti/errors/execution_error.rb +18 -0
  25. data/lib/graphiti/errors/validation_error.rb +26 -0
  26. data/lib/graphiti/model.rb +33 -0
  27. data/lib/graphiti/model/configuration.rb +81 -0
  28. data/lib/graphiti/router.rb +65 -0
  29. data/lib/graphiti/router/action.rb +21 -0
  30. data/lib/graphiti/router/mutation_action.rb +18 -0
  31. data/lib/graphiti/router/query_action.rb +18 -0
  32. data/lib/graphiti/router/resource_actions_builder.rb +82 -0
  33. data/lib/graphiti/router/schema_builder.rb +37 -0
  34. data/lib/graphiti/version.rb +5 -0
  35. data/lib/graphql_rails.rb +10 -0
  36. data/lib/graphql_rails/attribute.rb +86 -0
  37. data/lib/graphql_rails/controller.rb +54 -0
  38. data/lib/graphql_rails/controller/action_configuration.rb +46 -0
  39. data/lib/graphql_rails/controller/action_path_parser.rb +75 -0
  40. data/lib/graphql_rails/controller/configuration.rb +32 -0
  41. data/lib/graphql_rails/controller/controller_function.rb +41 -0
  42. data/lib/graphql_rails/controller/request.rb +40 -0
  43. data/lib/graphql_rails/errors/execution_error.rb +18 -0
  44. data/lib/graphql_rails/errors/validation_error.rb +26 -0
  45. data/lib/graphql_rails/model.rb +33 -0
  46. data/lib/graphql_rails/model/configuration.rb +81 -0
  47. data/lib/graphql_rails/router.rb +65 -0
  48. data/lib/graphql_rails/router/action.rb +21 -0
  49. data/lib/graphql_rails/router/mutation_action.rb +18 -0
  50. data/lib/graphql_rails/router/query_action.rb +18 -0
  51. data/lib/graphql_rails/router/resource_actions_builder.rb +82 -0
  52. data/lib/graphql_rails/router/schema_builder.rb +37 -0
  53. data/lib/graphql_rails/version.rb +5 -0
  54. metadata +166 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 403f0e906eb7580de0e9d7b94c61a260c4145754e157b82906a669e04d4e6297
4
+ data.tar.gz: 4201cccb9404a1e005ca8b978cd37784ffe400742ec5ae3d338a274a2cb8b84d
5
+ SHA512:
6
+ metadata.gz: 1d6f9038ddd9d90597d5b58a3b506b2a3124a547639d9651bdcd4be8f7dbd4feadb487ef7f8ff74062488afdac222eebe2f9a830b6a560921f42400c8fe333ae
7
+ data.tar.gz: 7135c0208d889a2429b8496337dec43c4fbf6001d6306ea3937cc938eb5b149aa0be74102f49e6a2b613a1ee7751be6769eb9d63df6994aa3b82c523bec4d372
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.history/
10
+ /.vscode/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
@@ -0,0 +1,3 @@
1
+ rubocop:
2
+ config_file: .rubocop.yml
3
+ fail_on_violations: true
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,34 @@
1
+ require: rubocop-rspec
2
+
3
+ RSpec/NestedGroups:
4
+ Enabled: false
5
+
6
+ Metrics/LineLength:
7
+ Enabled: true
8
+ Max: 120
9
+ Exclude:
10
+ - db/migrate/*
11
+
12
+ Metrics/BlockLength:
13
+ Exclude:
14
+ - spec/**/*.rb
15
+
16
+ Lint/AmbiguousBlockAssociation:
17
+ Exclude:
18
+ - spec/**/*.rb
19
+
20
+ Naming/UncommunicativeMethodParamName:
21
+ AllowedNames:
22
+ - 'to'
23
+ - 'at'
24
+ - 'on'
25
+ - 'id'
26
+ - 'in'
27
+ - 'as'
28
+
29
+ AllCops:
30
+ TargetRubyVersion: 2.5
31
+ Exclude:
32
+ - bin/*
33
+ - graphql_rails.gemspec
34
+ - Rakefile
@@ -0,0 +1 @@
1
+ 2.5.1
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
@@ -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 povilas@samesystem.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
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ group :development do
8
+ gem 'rubocop'
9
+ gem 'rubocop-rspec'
10
+ end
11
+
12
+ group :test do
13
+ gem 'activerecord'
14
+ gem 'codecov', require: false
15
+ gem 'mongoid'
16
+ gem 'simplecov', require: false
17
+ end
18
+
19
+ # Specify your gem's dependencies in graphql_rails.gemspec
20
+ gemspec
@@ -0,0 +1,98 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ graphql_rails (0.1.0)
5
+ activesupport (~> 5)
6
+ graphql (~> 1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (5.2.0)
12
+ activesupport (= 5.2.0)
13
+ activerecord (5.2.0)
14
+ activemodel (= 5.2.0)
15
+ activesupport (= 5.2.0)
16
+ arel (>= 9.0)
17
+ activesupport (5.2.0)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 0.7, < 2)
20
+ minitest (~> 5.1)
21
+ tzinfo (~> 1.1)
22
+ arel (9.0.0)
23
+ ast (2.4.0)
24
+ bson (4.3.0)
25
+ codecov (0.1.10)
26
+ json
27
+ simplecov
28
+ url
29
+ concurrent-ruby (1.0.5)
30
+ diff-lcs (1.3)
31
+ docile (1.3.0)
32
+ graphql (1.7.14)
33
+ i18n (1.0.1)
34
+ concurrent-ruby (~> 1.0)
35
+ json (2.1.0)
36
+ minitest (5.11.3)
37
+ mongo (2.5.1)
38
+ bson (>= 4.3.0, < 5.0.0)
39
+ mongoid (7.0.0)
40
+ activemodel (>= 5.1, < 6.0.0)
41
+ mongo (>= 2.5.1, < 3.0.0)
42
+ parallel (1.12.1)
43
+ parser (2.5.1.0)
44
+ ast (~> 2.4.0)
45
+ powerpack (0.1.1)
46
+ rainbow (3.0.0)
47
+ rake (10.5.0)
48
+ rspec (3.7.0)
49
+ rspec-core (~> 3.7.0)
50
+ rspec-expectations (~> 3.7.0)
51
+ rspec-mocks (~> 3.7.0)
52
+ rspec-core (3.7.1)
53
+ rspec-support (~> 3.7.0)
54
+ rspec-expectations (3.7.0)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.7.0)
57
+ rspec-mocks (3.7.0)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.7.0)
60
+ rspec-support (3.7.1)
61
+ rubocop (0.55.0)
62
+ parallel (~> 1.10)
63
+ parser (>= 2.5)
64
+ powerpack (~> 0.1)
65
+ rainbow (>= 2.2.2, < 4.0)
66
+ ruby-progressbar (~> 1.7)
67
+ unicode-display_width (~> 1.0, >= 1.0.1)
68
+ rubocop-rspec (1.25.1)
69
+ rubocop (>= 0.53.0)
70
+ ruby-progressbar (1.9.0)
71
+ simplecov (0.16.1)
72
+ docile (~> 1.1)
73
+ json (>= 1.8, < 3)
74
+ simplecov-html (~> 0.10.0)
75
+ simplecov-html (0.10.2)
76
+ thread_safe (0.3.6)
77
+ tzinfo (1.2.5)
78
+ thread_safe (~> 0.1)
79
+ unicode-display_width (1.3.0)
80
+ url (0.3.2)
81
+
82
+ PLATFORMS
83
+ ruby
84
+
85
+ DEPENDENCIES
86
+ activerecord
87
+ bundler (~> 1.16)
88
+ codecov
89
+ graphql_rails!
90
+ mongoid
91
+ rake (~> 10.0)
92
+ rspec (~> 3.0)
93
+ rubocop
94
+ rubocop-rspec
95
+ simplecov
96
+
97
+ BUNDLED WITH
98
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Povilas Jurcys
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.
@@ -0,0 +1,122 @@
1
+ # GraphqlRails
2
+
3
+ [![Build Status](https://travis-ci.org/povilasjurcys/graphiti.svg?branch=master)](https://travis-ci.org/povilasjurcys/graphiti)
4
+ [![codecov](https://codecov.io/gh/povilasjurcys/graphiti/branch/master/graph/badge.svg)](https://codecov.io/gh/povilasjurcys/graphiti)
5
+
6
+ Rails style structure for GrapQL API.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'graphiti'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install graphiti
23
+
24
+ ## Usage
25
+
26
+ ### Define GraphQL schema as RoR routes
27
+
28
+ ```ruby
29
+ MyGraphqlSchema = GraphqlRails::Router.draw do
30
+ # will create createUser, updateUser, deleteUser mutations and user, users queries.
31
+ # expects that UsersController class exist
32
+ resources :users
33
+
34
+ # if you want custom queries or mutation
35
+ query 'searchLogs', to: 'logs#search' # redirects request to LogsController
36
+ mutation 'changeUserPassword', to: 'users#change_password'
37
+ end
38
+ ```
39
+
40
+ ### Define your Graphql model
41
+
42
+ ```ruby
43
+ class User # works with any class including ActiveRecord
44
+ include GraphqlRails::Model
45
+
46
+ graphiti do |c|
47
+ # most common attributes, like :id, :name, :title has default type, so you don't have to specify it (but you can!)
48
+ c.attribute :id
49
+
50
+ c.attribute :email, :string
51
+ c.attribute :surname, :string
52
+ end
53
+ end
54
+ ```
55
+
56
+ ### Define controller
57
+
58
+ ```ruby
59
+ class UsersController < GraphqlRails::Controller
60
+ # graphql requires to describe which attributes controller action accepts and which returns
61
+ action(:change_user_password)
62
+ .permit(:password!, :id!) # Bang (!) indicates that attribute is required
63
+
64
+ def change_user_password
65
+ user = User.find(params[:id])
66
+ user.update!(password: params[:password])
67
+
68
+ # returned value needs to have all methods defined in model `graphiti do` part
69
+ user # or SomeDecorator.new(user)
70
+ end
71
+
72
+ action(:search).permit(search_fields!: SearchFieldsInput) # you can specify your own input fields
73
+ def search
74
+ end
75
+ end
76
+ ```
77
+
78
+ ## Routes
79
+
80
+ ```ruby
81
+ MyGraphqlSchema = GraphqlRails::Router.draw do
82
+ # generates `friend`, `createFriend`, `updateFriend`, `destroyFriend`, `friends` routes
83
+ resources :friends
84
+ resources :shops, only: [:show, :index] # generates `shop` and `shops` routes only
85
+ resources :orders, except: :update # generates all routes except `updateOrder`
86
+
87
+ resources :users do
88
+ # generates `findUser` query
89
+ query :find, on: :member
90
+
91
+ # generates `searchUsers` query
92
+ query :search, on: :collection
93
+ end
94
+
95
+ # you can use namespaced controllers too:
96
+ scope module: 'admin' do
97
+ # `updateTranslations` route will be handeled by `Admin::TranslationsController`
98
+ mutation :updateTranslations, to: 'translations#update'
99
+
100
+ # all :groups routes will be handeled by `Admin::GroupsController`
101
+ resources :groups
102
+ end
103
+ end
104
+ ```
105
+
106
+ ## Development
107
+
108
+ 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.
109
+
110
+ 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).
111
+
112
+ ## Contributing
113
+
114
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/graphiti. 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.
115
+
116
+ ## License
117
+
118
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
119
+
120
+ ## Code of Conduct
121
+
122
+ Everyone interacting in the GraphqlRails project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/graphiti/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "graphql_rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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