graphql_rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.hound.yml +3 -0
- data/.rspec +3 -0
- data/.rubocop.yml +34 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +98 -0
- data/LICENSE.txt +21 -0
- data/README.md +122 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/graphql_rails.gemspec +29 -0
- data/lib/graphiti.rb +10 -0
- data/lib/graphiti/attribute.rb +86 -0
- data/lib/graphiti/controller.rb +54 -0
- data/lib/graphiti/controller/action_configuration.rb +46 -0
- data/lib/graphiti/controller/configuration.rb +32 -0
- data/lib/graphiti/controller/controller_function.rb +41 -0
- data/lib/graphiti/controller/request.rb +40 -0
- data/lib/graphiti/errors/execution_error.rb +18 -0
- data/lib/graphiti/errors/validation_error.rb +26 -0
- data/lib/graphiti/model.rb +33 -0
- data/lib/graphiti/model/configuration.rb +81 -0
- data/lib/graphiti/router.rb +65 -0
- data/lib/graphiti/router/action.rb +21 -0
- data/lib/graphiti/router/mutation_action.rb +18 -0
- data/lib/graphiti/router/query_action.rb +18 -0
- data/lib/graphiti/router/resource_actions_builder.rb +82 -0
- data/lib/graphiti/router/schema_builder.rb +37 -0
- data/lib/graphiti/version.rb +5 -0
- data/lib/graphql_rails.rb +10 -0
- data/lib/graphql_rails/attribute.rb +86 -0
- data/lib/graphql_rails/controller.rb +54 -0
- data/lib/graphql_rails/controller/action_configuration.rb +46 -0
- data/lib/graphql_rails/controller/action_path_parser.rb +75 -0
- data/lib/graphql_rails/controller/configuration.rb +32 -0
- data/lib/graphql_rails/controller/controller_function.rb +41 -0
- data/lib/graphql_rails/controller/request.rb +40 -0
- data/lib/graphql_rails/errors/execution_error.rb +18 -0
- data/lib/graphql_rails/errors/validation_error.rb +26 -0
- data/lib/graphql_rails/model.rb +33 -0
- data/lib/graphql_rails/model/configuration.rb +81 -0
- data/lib/graphql_rails/router.rb +65 -0
- data/lib/graphql_rails/router/action.rb +21 -0
- data/lib/graphql_rails/router/mutation_action.rb +18 -0
- data/lib/graphql_rails/router/query_action.rb +18 -0
- data/lib/graphql_rails/router/resource_actions_builder.rb +82 -0
- data/lib/graphql_rails/router/schema_builder.rb +37 -0
- data/lib/graphql_rails/version.rb +5 -0
- metadata +166 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'action'
|
4
|
+
|
5
|
+
module GraphqlRails
|
6
|
+
class Router
|
7
|
+
# stores query type graphql action info
|
8
|
+
class QueryAction < Action
|
9
|
+
def query?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def mutation?
|
14
|
+
false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'query_action'
|
4
|
+
require_relative 'mutation_action'
|
5
|
+
|
6
|
+
module GraphqlRails
|
7
|
+
class Router
|
8
|
+
# Generates graphql actions based on resource name and options
|
9
|
+
class ResourceActionsBuilder
|
10
|
+
AVAILABLE_ACTIONS = %i[show index create update destroy].freeze
|
11
|
+
|
12
|
+
def initialize(name, only: nil, except: [], **options)
|
13
|
+
@name = name.to_s
|
14
|
+
|
15
|
+
@options = options
|
16
|
+
@autogenerated_action_names = initial_action_names(only, except, AVAILABLE_ACTIONS)
|
17
|
+
end
|
18
|
+
|
19
|
+
def actions
|
20
|
+
@actions ||= initial_actions
|
21
|
+
end
|
22
|
+
|
23
|
+
def query(*args)
|
24
|
+
actions << build_query(*args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def mutation(*args)
|
28
|
+
actions << build_mutation(*args)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :autogenerated_action_names, :name, :options
|
34
|
+
|
35
|
+
def initial_actions
|
36
|
+
actions = initial_query_actions
|
37
|
+
actions << build_mutation(:create, on: :member) if autogenerated_action_names.include?(:create)
|
38
|
+
actions << build_mutation(:update, on: :member) if autogenerated_action_names.include?(:update)
|
39
|
+
actions << build_mutation(:destroy, on: :member) if autogenerated_action_names.include?(:destroy)
|
40
|
+
actions
|
41
|
+
end
|
42
|
+
|
43
|
+
def initial_query_actions
|
44
|
+
actions = Set.new
|
45
|
+
|
46
|
+
if autogenerated_action_names.include?(:show)
|
47
|
+
actions << build_action(QueryAction, 'show', to: "#{name}#show", prefix: '', on: :member)
|
48
|
+
end
|
49
|
+
|
50
|
+
if autogenerated_action_names.include?(:index)
|
51
|
+
actions << build_action(QueryAction, 'index', to: "#{name}#index", prefix: '', on: :collection)
|
52
|
+
end
|
53
|
+
|
54
|
+
actions
|
55
|
+
end
|
56
|
+
|
57
|
+
def build_mutation(*args)
|
58
|
+
build_action(MutationAction, *args)
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_query(*args)
|
62
|
+
build_action(QueryAction, *args)
|
63
|
+
end
|
64
|
+
|
65
|
+
def build_action(builder, action, prefix: action, on: :member, **custom_options)
|
66
|
+
action_options = options.merge(custom_options)
|
67
|
+
action_name = [prefix, resource_name(on)].reject(&:empty?).join('_')
|
68
|
+
builder.new(action_name, to: "#{name}##{action}", **action_options)
|
69
|
+
end
|
70
|
+
|
71
|
+
def initial_action_names(only, except, available)
|
72
|
+
alowed_actions = Array(only || available) & available
|
73
|
+
only_actions = alowed_actions.map(&:to_sym) - Array(except).map(&:to_sym)
|
74
|
+
Set.new(only_actions)
|
75
|
+
end
|
76
|
+
|
77
|
+
def resource_name(type)
|
78
|
+
type.to_sym == :member ? name.singularize : name
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphqlRails
|
4
|
+
class Router
|
5
|
+
# builds GraphQL::Schema based on previously defined grahiti data
|
6
|
+
class SchemaBuilder
|
7
|
+
attr_reader :queries, :mutations
|
8
|
+
|
9
|
+
def initialize(queries:, mutations:)
|
10
|
+
@queries = queries
|
11
|
+
@mutations = mutations
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
query_type = build_type('Query', queries)
|
16
|
+
mutation_type = build_type('Mutation', mutations)
|
17
|
+
|
18
|
+
GraphQL::Schema.define do
|
19
|
+
query(query_type)
|
20
|
+
mutation(mutation_type)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def build_type(type_name, actions)
|
27
|
+
GraphQL::ObjectType.define do
|
28
|
+
name type_name
|
29
|
+
|
30
|
+
actions.each do |action|
|
31
|
+
field action.name, action.options
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: graphql_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Povilas Jurčys
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: graphql
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- bloomrain@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".hound.yml"
|
92
|
+
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".ruby-version"
|
95
|
+
- ".travis.yml"
|
96
|
+
- CODE_OF_CONDUCT.md
|
97
|
+
- Gemfile
|
98
|
+
- Gemfile.lock
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- bin/console
|
103
|
+
- bin/setup
|
104
|
+
- graphql_rails.gemspec
|
105
|
+
- lib/graphiti.rb
|
106
|
+
- lib/graphiti/attribute.rb
|
107
|
+
- lib/graphiti/controller.rb
|
108
|
+
- lib/graphiti/controller/action_configuration.rb
|
109
|
+
- lib/graphiti/controller/configuration.rb
|
110
|
+
- lib/graphiti/controller/controller_function.rb
|
111
|
+
- lib/graphiti/controller/request.rb
|
112
|
+
- lib/graphiti/errors/execution_error.rb
|
113
|
+
- lib/graphiti/errors/validation_error.rb
|
114
|
+
- lib/graphiti/model.rb
|
115
|
+
- lib/graphiti/model/configuration.rb
|
116
|
+
- lib/graphiti/router.rb
|
117
|
+
- lib/graphiti/router/action.rb
|
118
|
+
- lib/graphiti/router/mutation_action.rb
|
119
|
+
- lib/graphiti/router/query_action.rb
|
120
|
+
- lib/graphiti/router/resource_actions_builder.rb
|
121
|
+
- lib/graphiti/router/schema_builder.rb
|
122
|
+
- lib/graphiti/version.rb
|
123
|
+
- lib/graphql_rails.rb
|
124
|
+
- lib/graphql_rails/attribute.rb
|
125
|
+
- lib/graphql_rails/controller.rb
|
126
|
+
- lib/graphql_rails/controller/action_configuration.rb
|
127
|
+
- lib/graphql_rails/controller/action_path_parser.rb
|
128
|
+
- lib/graphql_rails/controller/configuration.rb
|
129
|
+
- lib/graphql_rails/controller/controller_function.rb
|
130
|
+
- lib/graphql_rails/controller/request.rb
|
131
|
+
- lib/graphql_rails/errors/execution_error.rb
|
132
|
+
- lib/graphql_rails/errors/validation_error.rb
|
133
|
+
- lib/graphql_rails/model.rb
|
134
|
+
- lib/graphql_rails/model/configuration.rb
|
135
|
+
- lib/graphql_rails/router.rb
|
136
|
+
- lib/graphql_rails/router/action.rb
|
137
|
+
- lib/graphql_rails/router/mutation_action.rb
|
138
|
+
- lib/graphql_rails/router/query_action.rb
|
139
|
+
- lib/graphql_rails/router/resource_actions_builder.rb
|
140
|
+
- lib/graphql_rails/router/schema_builder.rb
|
141
|
+
- lib/graphql_rails/version.rb
|
142
|
+
homepage: https://github.com/povilasjurcys/graphql_rails
|
143
|
+
licenses:
|
144
|
+
- MIT
|
145
|
+
metadata: {}
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 2.7.6
|
163
|
+
signing_key:
|
164
|
+
specification_version: 4
|
165
|
+
summary: GrapQL server and client for rails
|
166
|
+
test_files: []
|