agoo 2.12.1 → 2.12.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of agoo might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/bin/agoo_stubs +166 -0
- data/ext/agoo/rgraphql.c +86 -4
- data/lib/agoo.rb +1 -0
- data/lib/agoo/graphql.rb +9 -0
- data/lib/agoo/graphql/arg.rb +13 -0
- data/lib/agoo/graphql/field.rb +14 -0
- data/lib/agoo/graphql/type.rb +12 -0
- data/lib/agoo/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecda60c70d9a3bbf2ca2e9917f7cce3d073366a66684045425ffa770c2a0fb56
|
4
|
+
data.tar.gz: 5bbbd47dfc06d93b0aa93827391cabff6728a4feb2323286e36948c25b2e7968
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38785b90ca7250269e33afdc9358da60351ccee96c4f4cbeff6dd4f7dbef445456e59010c9303c06538e4b070ed5ef2e563a97ba6d06ac524556e2dd53d9e91e
|
7
|
+
data.tar.gz: 93272b21eb3d4f3457bd09633503f2720a0d1f044abb3a34f68f56a9afa7be7b19dbf4817d5dafb55c322c0d42b93935cd3c938aac2e4cf7a809dcc712de918b
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
All changes to the Agoo gem are documented here. Releases follow semantic versioning.
|
4
4
|
|
5
|
+
## [2.12.2] - 2020-03-22
|
6
|
+
|
7
|
+
Stub generator
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- GraphQL stub generator to generate Ruby class file corresponding to GraphQL schema type. The generator is `bin/agoo_stubs`.
|
12
|
+
|
5
13
|
## [2.12.1] - 2020-03-17
|
6
14
|
|
7
15
|
Check SO_REUSEPORT
|
data/bin/agoo_stubs
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
while (index = ARGV.index('-I'))
|
4
|
+
_, path = ARGV.slice!(index, 2)
|
5
|
+
$LOAD_PATH << path
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'optparse'
|
9
|
+
|
10
|
+
require 'agoo'
|
11
|
+
|
12
|
+
usage = %{
|
13
|
+
Usage: agoo_stubs [options] <graphql_schema>
|
14
|
+
|
15
|
+
version #{Agoo::VERSION}
|
16
|
+
|
17
|
+
Generates Ruby files that match the types in the GraphQL schema file specified.
|
18
|
+
|
19
|
+
Example:
|
20
|
+
|
21
|
+
agoo_stubs --module Data --dir lib schema.graphql
|
22
|
+
|
23
|
+
}
|
24
|
+
|
25
|
+
@verbose = false
|
26
|
+
@single = nil
|
27
|
+
@dir = nil
|
28
|
+
@mod = nil
|
29
|
+
|
30
|
+
@opts = OptionParser.new(usage)
|
31
|
+
@opts.on('-h', '--help', 'show this display') { puts @opts.help; Process.exit!(0) }
|
32
|
+
@opts.on('-v', '--verbose', 'verbose output') { @verbose = true }
|
33
|
+
@opts.on('-s', '--single PATH', String, 'path to fiel for all stubs') { |s| @single = s }
|
34
|
+
@opts.on('-d', '--dir PATH', String, 'directory to write files into') { |d| @dir = d }
|
35
|
+
@opts.on('-m', '--module STRING', String, 'module for the stub classes') { |m| @mod = m }
|
36
|
+
|
37
|
+
@files = @opts.parse(ARGV)
|
38
|
+
|
39
|
+
if @files.empty?
|
40
|
+
puts "A schema file must be specified."
|
41
|
+
puts @opts.help
|
42
|
+
Process.exit!(0)
|
43
|
+
elsif 1 < @files.size
|
44
|
+
puts "Only one schema file can be specified."
|
45
|
+
puts @opts.help
|
46
|
+
Process.exit!(0)
|
47
|
+
end
|
48
|
+
|
49
|
+
Agoo::GraphQL.schema(nil) {
|
50
|
+
Agoo::GraphQL.load_file(@files[0])
|
51
|
+
}
|
52
|
+
|
53
|
+
def write_type_stub(f, t, depth)
|
54
|
+
indent = ' ' * depth
|
55
|
+
f.puts "#{indent}# #{t.description}" unless t.description.nil?
|
56
|
+
f.puts "#{indent}class #{t.name}"
|
57
|
+
t.fields.each { |field|
|
58
|
+
next unless field.args.nil?
|
59
|
+
f.puts "#{indent} # #{field.description}" unless field.description.nil?
|
60
|
+
f.puts "#{indent} attr_accessor :#{field.name}"
|
61
|
+
}
|
62
|
+
f.puts
|
63
|
+
f.puts "#{indent} def initialize"
|
64
|
+
f.puts "#{indent} end"
|
65
|
+
t.fields.each { |field|
|
66
|
+
next if field.args.nil?
|
67
|
+
f.puts
|
68
|
+
f.puts "#{indent} # #{field.description}" unless field.description.nil?
|
69
|
+
args = field.args.map { |a| a.name }.join(', ')
|
70
|
+
f.puts "#{indent} def #{field.name}(#{args})"
|
71
|
+
f.puts "#{indent} end"
|
72
|
+
}
|
73
|
+
f.puts "#{indent}end"
|
74
|
+
end
|
75
|
+
|
76
|
+
def calc_filepath(t)
|
77
|
+
path = @dir
|
78
|
+
path += '/' + @mod.split('::').map { |m| m.downcase }.join('/') unless @mod.nil?
|
79
|
+
path + '/' + t.name.downcase + '.rb'
|
80
|
+
end
|
81
|
+
|
82
|
+
def assure_parent_dir(path)
|
83
|
+
dirs = path.split('/')[0..-2]
|
84
|
+
dirs.each_index { |i|
|
85
|
+
path = dirs[0..i].join('/')
|
86
|
+
Dir.mkdir(path) unless Dir.exist?(path)
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
def write_type_stub_file(t)
|
91
|
+
path = calc_filepath(t)
|
92
|
+
assure_parent_dir(path)
|
93
|
+
File.open(path, 'w') { |f|
|
94
|
+
f.puts "# #{t.name} class for schema file #{@files[0]}"
|
95
|
+
f.puts
|
96
|
+
depth = 0
|
97
|
+
unless @mod.nil?
|
98
|
+
@mod.split('::').each { |m|
|
99
|
+
f.puts("#{' ' * depth}module #{m}")
|
100
|
+
depth += 1
|
101
|
+
}
|
102
|
+
f.puts
|
103
|
+
end
|
104
|
+
write_type_stub(f, t, depth)
|
105
|
+
f.puts
|
106
|
+
unless @mod.nil?
|
107
|
+
@mod.split('::').size.times {
|
108
|
+
depth -= 1
|
109
|
+
f.puts("#{' ' * depth}end")
|
110
|
+
}
|
111
|
+
end
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
@out = nil
|
116
|
+
|
117
|
+
if @dir.nil?
|
118
|
+
if @single.nil?
|
119
|
+
@out = STDOUT
|
120
|
+
else @single
|
121
|
+
@out = File.new(@single, 'w')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
unless @out.nil?
|
126
|
+
@out.puts "# Classes for schema file #{@files[0]}"
|
127
|
+
@out.puts
|
128
|
+
depth = 0
|
129
|
+
unless @mod.nil?
|
130
|
+
@mod.split('::').each { |m|
|
131
|
+
@out.puts("#{' ' * depth}module #{m}")
|
132
|
+
depth += 1
|
133
|
+
}
|
134
|
+
@out.puts
|
135
|
+
end
|
136
|
+
Agoo::GraphQL.sdl_types.sort { |a,b| a.name <=> b.name }.each { |t|
|
137
|
+
write_type_stub(@out, t, depth)
|
138
|
+
@out.puts
|
139
|
+
}
|
140
|
+
unless @mod.nil?
|
141
|
+
@mod.split('::').size.times {
|
142
|
+
depth -= 1
|
143
|
+
@out.puts("#{' ' * depth}end")
|
144
|
+
}
|
145
|
+
end
|
146
|
+
@out.close unless STDOUT == @out
|
147
|
+
else
|
148
|
+
Agoo::GraphQL.sdl_types.each { |t|
|
149
|
+
write_type_stub_file(t)
|
150
|
+
}
|
151
|
+
unless @mod.nil?
|
152
|
+
path = @dir
|
153
|
+
path += '/' + @mod.split('::').map { |m| m.downcase }.join('/')
|
154
|
+
assure_parent_dir(path)
|
155
|
+
m = path.split('/')[-1]
|
156
|
+
path += '.rb'
|
157
|
+
|
158
|
+
File.open(path, 'w') { |f|
|
159
|
+
f.puts "# Classes for schema file #{@files[0]}"
|
160
|
+
f.puts
|
161
|
+
Agoo::GraphQL.sdl_types.sort { |a,b| a.name <=> b.name }.each { |t|
|
162
|
+
f.puts "require_relative '#{m}/#{t.name.downcase}'"
|
163
|
+
}
|
164
|
+
}
|
165
|
+
end
|
166
|
+
end
|
data/ext/agoo/rgraphql.c
CHANGED
@@ -37,6 +37,9 @@ typedef struct _bhArgs {
|
|
37
37
|
static VALUE graphql_class = Qundef;
|
38
38
|
static VALUE vroot = Qnil;
|
39
39
|
static VALUE build_headers_func = Qnil;
|
40
|
+
static VALUE arg_clas = Qnil;
|
41
|
+
static VALUE field_clas = Qnil;
|
42
|
+
static VALUE type_clas = Qnil;
|
40
43
|
|
41
44
|
static ID call_id;
|
42
45
|
|
@@ -774,16 +777,16 @@ graphql_load_file(VALUE self, VALUE path) {
|
|
774
777
|
return Qnil;
|
775
778
|
}
|
776
779
|
|
777
|
-
/* Document-method:
|
780
|
+
/* Document-method: sdl_dump
|
778
781
|
*
|
779
|
-
* call-seq:
|
782
|
+
* call-seq: sdl_dump()
|
780
783
|
*
|
781
784
|
* The preferred method of inspecting a GraphQL schema is to use introspection
|
782
785
|
* queries but for debugging and for reviewing the schema a dump of the schema
|
783
|
-
* as SDL can be helpful. The _#
|
786
|
+
* as SDL can be helpful. The _#sdl_dump_ method returns the schema as an SDL
|
784
787
|
* string.
|
785
788
|
*
|
786
|
-
* - *options* [_Hash_]
|
789
|
+
* - *options* [_Hash_] options
|
787
790
|
*
|
788
791
|
* - *:with_description* [_true_|_false_] if true the description strings are included. If false they are not included.
|
789
792
|
*
|
@@ -817,6 +820,79 @@ graphql_sdl_dump(VALUE self, VALUE options) {
|
|
817
820
|
return dump;
|
818
821
|
}
|
819
822
|
|
823
|
+
static void
|
824
|
+
type_cb(gqlType type, void *ctx) {
|
825
|
+
VALUE rtypes = (VALUE)ctx;
|
826
|
+
VALUE t;
|
827
|
+
|
828
|
+
if (GQL_OBJECT != type->kind || type->core) {
|
829
|
+
return;
|
830
|
+
}
|
831
|
+
t = rb_obj_alloc(type_clas);
|
832
|
+
rb_ivar_set(t, rb_intern("@name"), rb_str_new_cstr(type->name));
|
833
|
+
if (NULL != type->desc) {
|
834
|
+
rb_ivar_set(t, rb_intern("@description"), rb_str_new_cstr(type->desc));
|
835
|
+
}
|
836
|
+
if (NULL != type->fields) {
|
837
|
+
VALUE fields = rb_ary_new();
|
838
|
+
VALUE field;
|
839
|
+
gqlField f;
|
840
|
+
|
841
|
+
rb_ivar_set(t, rb_intern("@fields"), fields);
|
842
|
+
for (f = type->fields; NULL != f; f = f->next) {
|
843
|
+
field = rb_obj_alloc(field_clas);
|
844
|
+
rb_ary_push(fields, field);
|
845
|
+
rb_ivar_set(field, rb_intern("@name"), rb_str_new_cstr(f->name));
|
846
|
+
if (NULL != f->desc) {
|
847
|
+
rb_ivar_set(field, rb_intern("@description"), rb_str_new_cstr(f->desc));
|
848
|
+
}
|
849
|
+
if (NULL != f->type) {
|
850
|
+
rb_ivar_set(field, rb_intern("@type_name"), rb_str_new_cstr(f->type->name));
|
851
|
+
}
|
852
|
+
if (NULL != f->default_value) {
|
853
|
+
rb_ivar_set(field, rb_intern("@default_value"), gval_to_ruby(f->default_value));
|
854
|
+
}
|
855
|
+
if (NULL != f->args) {
|
856
|
+
VALUE args = rb_ary_new();
|
857
|
+
VALUE arg;
|
858
|
+
gqlArg a;
|
859
|
+
|
860
|
+
rb_ivar_set(field, rb_intern("@args"), args);
|
861
|
+
for (a = f->args; NULL != a; a = a->next) {
|
862
|
+
arg = rb_obj_alloc(arg_clas);
|
863
|
+
rb_ary_push(args, arg);
|
864
|
+
rb_ivar_set(arg, rb_intern("@name"), rb_str_new_cstr(a->name));
|
865
|
+
if (NULL != a->desc) {
|
866
|
+
rb_ivar_set(arg, rb_intern("@description"), rb_str_new_cstr(a->desc));
|
867
|
+
}
|
868
|
+
if (NULL != a->type) {
|
869
|
+
rb_ivar_set(arg, rb_intern("@type_name"), rb_str_new_cstr(a->type->name));
|
870
|
+
}
|
871
|
+
if (NULL != a->default_value) {
|
872
|
+
rb_ivar_set(arg, rb_intern("@default_value"), gval_to_ruby(a->default_value));
|
873
|
+
}
|
874
|
+
}
|
875
|
+
}
|
876
|
+
}
|
877
|
+
}
|
878
|
+
rb_ary_push(rtypes, t);
|
879
|
+
}
|
880
|
+
|
881
|
+
/* Document-method: sdl_types
|
882
|
+
*
|
883
|
+
* call-seq: sdl_types()
|
884
|
+
*
|
885
|
+
* Returns an array of all SDL types as Ruby objects.
|
886
|
+
*/
|
887
|
+
static VALUE
|
888
|
+
graphql_sdl_types(VALUE self) {
|
889
|
+
VALUE rtypes = rb_ary_new();
|
890
|
+
|
891
|
+
gql_type_iterate(type_cb, (void*)rtypes);
|
892
|
+
|
893
|
+
return rtypes;
|
894
|
+
}
|
895
|
+
|
820
896
|
/* Document-method: publish
|
821
897
|
*
|
822
898
|
* call-seq: publish(subject, event)
|
@@ -963,10 +1039,16 @@ graphql_init(VALUE mod) {
|
|
963
1039
|
|
964
1040
|
rb_define_module_function(graphql_class, "sdl_dump", graphql_sdl_dump, 1);
|
965
1041
|
|
1042
|
+
rb_define_module_function(graphql_class, "sdl_types", graphql_sdl_types, 0);
|
1043
|
+
|
966
1044
|
rb_define_module_function(graphql_class, "publish", graphql_publish, 2);
|
967
1045
|
|
968
1046
|
rb_define_module_function(graphql_class, "build_headers=", graphql_build_headers, 1);
|
969
1047
|
rb_define_module_function(graphql_class, "headers", graphql_headers, 1);
|
970
1048
|
|
1049
|
+
arg_clas = rb_const_get_at(graphql_class, rb_intern("Arg"));
|
1050
|
+
field_clas = rb_const_get_at(graphql_class, rb_intern("Field"));
|
1051
|
+
type_clas = rb_const_get_at(graphql_class, rb_intern("Type"));
|
1052
|
+
|
971
1053
|
call_id = rb_intern("call");
|
972
1054
|
}
|
data/lib/agoo.rb
CHANGED
data/lib/agoo/graphql.rb
ADDED
data/lib/agoo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.12.
|
4
|
+
version: 2.12.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -34,6 +34,7 @@ description: A fast HTTP server supporting rack.
|
|
34
34
|
email: peter@ohler.com
|
35
35
|
executables:
|
36
36
|
- agoo
|
37
|
+
- agoo_stubs
|
37
38
|
extensions:
|
38
39
|
- ext/agoo/extconf.rb
|
39
40
|
extra_rdoc_files:
|
@@ -45,6 +46,7 @@ files:
|
|
45
46
|
- LICENSE
|
46
47
|
- README.md
|
47
48
|
- bin/agoo
|
49
|
+
- bin/agoo_stubs
|
48
50
|
- ext/agoo/agoo.c
|
49
51
|
- ext/agoo/atomic.h
|
50
52
|
- ext/agoo/base64.c
|
@@ -142,6 +144,10 @@ files:
|
|
142
144
|
- ext/agoo/websocket.c
|
143
145
|
- ext/agoo/websocket.h
|
144
146
|
- lib/agoo.rb
|
147
|
+
- lib/agoo/graphql.rb
|
148
|
+
- lib/agoo/graphql/arg.rb
|
149
|
+
- lib/agoo/graphql/field.rb
|
150
|
+
- lib/agoo/graphql/type.rb
|
145
151
|
- lib/agoo/version.rb
|
146
152
|
- lib/rack/handler/agoo.rb
|
147
153
|
- test/base_handler_test.rb
|