Skip to content

Commit e71c687

Browse files
committed
init
0 parents  commit e71c687

19 files changed

+619
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.gem
2+
.idea/

Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'rails'
4+
5+
group :test do
6+
7+
end

Gemfile.lock

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
actionmailer (4.2.6)
5+
actionpack (= 4.2.6)
6+
actionview (= 4.2.6)
7+
activejob (= 4.2.6)
8+
mail (~> 2.5, >= 2.5.4)
9+
rails-dom-testing (~> 1.0, >= 1.0.5)
10+
actionpack (4.2.6)
11+
actionview (= 4.2.6)
12+
activesupport (= 4.2.6)
13+
rack (~> 1.6)
14+
rack-test (~> 0.6.2)
15+
rails-dom-testing (~> 1.0, >= 1.0.5)
16+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
17+
actionview (4.2.6)
18+
activesupport (= 4.2.6)
19+
builder (~> 3.1)
20+
erubis (~> 2.7.0)
21+
rails-dom-testing (~> 1.0, >= 1.0.5)
22+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
23+
activejob (4.2.6)
24+
activesupport (= 4.2.6)
25+
globalid (>= 0.3.0)
26+
activemodel (4.2.6)
27+
activesupport (= 4.2.6)
28+
builder (~> 3.1)
29+
activerecord (4.2.6)
30+
activemodel (= 4.2.6)
31+
activesupport (= 4.2.6)
32+
arel (~> 6.0)
33+
activesupport (4.2.6)
34+
i18n (~> 0.7)
35+
json (~> 1.7, >= 1.7.7)
36+
minitest (~> 5.1)
37+
thread_safe (~> 0.3, >= 0.3.4)
38+
tzinfo (~> 1.1)
39+
arel (6.0.3)
40+
builder (3.2.2)
41+
concurrent-ruby (1.0.2)
42+
erubis (2.7.0)
43+
globalid (0.3.6)
44+
activesupport (>= 4.1.0)
45+
i18n (0.7.0)
46+
json (1.8.3)
47+
loofah (2.0.3)
48+
nokogiri (>= 1.5.9)
49+
mail (2.6.4)
50+
mime-types (>= 1.16, < 4)
51+
mime-types (3.0)
52+
mime-types-data (~> 3.2015)
53+
mime-types-data (3.2016.0221)
54+
mini_portile2 (2.0.0)
55+
minitest (5.8.4)
56+
nokogiri (1.6.7.2)
57+
mini_portile2 (~> 2.0.0.rc2)
58+
rack (1.6.4)
59+
rack-test (0.6.3)
60+
rack (>= 1.0)
61+
rails (4.2.6)
62+
actionmailer (= 4.2.6)
63+
actionpack (= 4.2.6)
64+
actionview (= 4.2.6)
65+
activejob (= 4.2.6)
66+
activemodel (= 4.2.6)
67+
activerecord (= 4.2.6)
68+
activesupport (= 4.2.6)
69+
bundler (>= 1.3.0, < 2.0)
70+
railties (= 4.2.6)
71+
sprockets-rails
72+
rails-deprecated_sanitizer (1.0.3)
73+
activesupport (>= 4.2.0.alpha)
74+
rails-dom-testing (1.0.7)
75+
activesupport (>= 4.2.0.beta, < 5.0)
76+
nokogiri (~> 1.6.0)
77+
rails-deprecated_sanitizer (>= 1.0.1)
78+
rails-html-sanitizer (1.0.3)
79+
loofah (~> 2.0)
80+
railties (4.2.6)
81+
actionpack (= 4.2.6)
82+
activesupport (= 4.2.6)
83+
rake (>= 0.8.7)
84+
thor (>= 0.18.1, < 2.0)
85+
rake (11.1.2)
86+
sprockets (3.6.0)
87+
concurrent-ruby (~> 1.0)
88+
rack (> 1, < 3)
89+
sprockets-rails (3.0.4)
90+
actionpack (>= 4.0)
91+
activesupport (>= 4.0)
92+
sprockets (>= 3.0.0)
93+
thor (0.19.1)
94+
thread_safe (0.3.5)
95+
tzinfo (1.2.2)
96+
thread_safe (~> 0.1)
97+
98+
PLATFORMS
99+
ruby
100+
101+
DEPENDENCIES
102+
rails
103+
104+
BUNDLED WITH
105+
1.11.2

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Rails Graph Generator
2+
3+
*A GraphQL Relay schema created by reflection over a Rails models*
4+
5+
## Usage
6+
Add your Gemfile:
7+
8+
```bash
9+
gem 'rails-graphql-generator'
10+
bundle install
11+
```
12+
13+
and then just run it!
14+
15+
```bash
16+
rails g graphql:init
17+
18+
rails g graphql:create_all
19+
20+
# or
21+
22+
rails g model User name:string email:string
23+
rake db:migrate
24+
rails g graphql User
25+
```
26+
27+
and start server [http://localhost:3000/graphiql](http://localhost:3000/graphiql)
28+
29+
Check out the **[example][]** for a demo of Rails GraphQL Generator in action.
30+
31+
## Road Map
32+
33+
* Add test
34+
* Add without relay option

Rakefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require "bundler/gem_tasks"
2+
require "rake/testtask"
3+
4+
Rake::TestTask.new(:test) do |t|
5+
t.libs << "test"
6+
t.libs << "lib"
7+
t.test_files = FileList['test/**/*_test.rb']
8+
end
9+
10+
task :default => :spec

lib/generators/graphql/USAGE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Description:
2+
3+
4+
Example:
5+
rails generate graphql Model
6+
7+
This will create:
8+
app/graphql/types/model_type.rb
9+
app/graphql/mutations/model_.rb
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'generators/graphql/graphql_helpers'
2+
3+
module Graphql
4+
module Generators
5+
class CreateAllGenerator < Rails::Generators::Base
6+
source_root File.expand_path('../templates', __FILE__)
7+
8+
include Graphql::Generators::GraphqlHelpers
9+
10+
def create
11+
models.each { |model| create_type(model) }
12+
models.each { |model| add_fields(model) }
13+
models.each { |model| add_methods(model) }
14+
models.each { |model| add_connections(model) }
15+
models.each { |model| add_connection_query(model) }
16+
models.each { |model| create_mutation(model) }
17+
models.each { |model| add_fields_to_mutation(model) }
18+
models.each { |model| add_mutation_query(model) }
19+
end
20+
21+
end
22+
end
23+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'generators/graphql/graphql_helpers'
2+
3+
module Graphql
4+
module Generators
5+
class GraphqlGenerator < Rails::Generators::NamedBase
6+
source_root File.expand_path('../templates', __FILE__)
7+
namespace 'graphql'
8+
9+
include Graphql::Generators::GraphqlHelpers
10+
11+
def create
12+
model = name.classify.constantize
13+
create_type(model)
14+
add_fields(model)
15+
add_methods(model)
16+
add_connections(model)
17+
add_connection_query(model)
18+
create_mutation(model)
19+
add_fields_to_mutation(model)
20+
add_mutation_query(model)
21+
end
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)