agoo 2.15.5 → 2.15.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 607fa2958764488d8aa14ef42fd80b551c9579ac4ebfb4052f9ce60f2404c67f
4
- data.tar.gz: e9491e0fd3e1b469710b33559043543931cc0e27f6041e3694ba49c06b0b0f6f
3
+ metadata.gz: 6860d541228cbc1c4eb2cde9ff1ca990165c8bc6a94e7c3100b9815c5e7f355a
4
+ data.tar.gz: 67a498d6cb3a1b979d17222f0c6b0b15fe6860af2bc2f16eefe665801e8257f9
5
5
  SHA512:
6
- metadata.gz: aa65f902c1e4ddba350a0cb11aa9952a47d523236a2b8ee7b1a3249bce891734286c12ec7afee410de7166de3c7c260a78d3cfb5d0c11be4c4cda5470170db67
7
- data.tar.gz: b9ed399e7edf096b0f4b7cb01225179abd5c85105581af8deb00e6ae2847189e0bb68f3c8046f5b0d6e21a695270489a0ded5940123a5e9bc4d5286aa681ef39
6
+ metadata.gz: 35bebcb546facab91fffd989fcf8d6abe4e09130840abe5066063a9858d2e7432b8979e497a1e3f3cd7e7c6a1673920c51c2ed92475cf81ed478c809973f34e5
7
+ data.tar.gz: '0302865a039bcee648d1212296ec72039beff8edc02ce32dae21f1a5badcb4b8de9586ca97e6e9afcdd3cfbf72a4398af7c135354dcfdf4afeb7ab1556d41445'
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  All changes to the Agoo gem are documented here. Releases follow semantic versioning.
4
4
 
5
+ ## [2.15.7] - 2023-07-10
6
+
7
+ ### Fixed
8
+
9
+ - Support for Apollo style POST requests fixed (again).
10
+
11
+ ## [2.15.6] - 2023-07-07
12
+
13
+ ### Fixed
14
+
15
+ - Support for Apollo style POST requests fixed.
16
+
5
17
  ## [2.15.5] - 2023-04-07
6
18
 
7
19
  ### Changed
data/ext/agoo/con.c CHANGED
@@ -991,7 +991,6 @@ static void
991
991
  publish_pub(agooPub pub, agooConLoop loop) {
992
992
  agooUpgraded up;
993
993
  const char *sub = pub->subject->pattern;
994
- int cnt = 0;
995
994
 
996
995
  for (up = agoo_server.up_list; NULL != up; up = up->next) {
997
996
  if (NULL != up->con && up->con->loop == loop && agoo_upgraded_match(up, sub)) {
@@ -1001,7 +1000,6 @@ publish_pub(agooPub pub, agooConLoop loop) {
1001
1000
  agoo_con_res_append(up->con, res);
1002
1001
  res->con_kind = AGOO_CON_ANY;
1003
1002
  agoo_res_message_push(res, agoo_text_dup(pub->msg));
1004
- cnt++;
1005
1003
  }
1006
1004
  }
1007
1005
  }
@@ -112,5 +112,6 @@ void
112
112
  early_hints_init(VALUE mod) {
113
113
  eh_class = rb_define_class_under(mod, "EarlyHints", rb_cObject);
114
114
 
115
+ rb_undef_alloc_func(eh_class);
115
116
  rb_define_method(eh_class, "call", eh_call, 1);
116
117
  }
@@ -131,6 +131,7 @@ void
131
131
  error_stream_init(VALUE mod) {
132
132
  es_class = rb_define_class_under(mod, "ErrorStream", rb_cObject);
133
133
 
134
+ rb_undef_alloc_func(es_class);
134
135
  rb_define_method(es_class, "puts", es_puts, 1);
135
136
  rb_define_method(es_class, "write", es_write, 1);
136
137
  rb_define_method(es_class, "flush", es_flush, 0);
data/ext/agoo/request.c CHANGED
@@ -728,6 +728,7 @@ void
728
728
  request_init(VALUE mod) {
729
729
  req_class = rb_define_class_under(mod, "Request", rb_cObject);
730
730
 
731
+ rb_undef_alloc_func(req_class);
731
732
  rb_define_method(req_class, "to_s", to_s, 0);
732
733
  rb_define_method(req_class, "to_h", to_h, 0);
733
734
  rb_define_method(req_class, "environment", to_h, 0);
data/ext/agoo/rgraphql.c CHANGED
@@ -1054,6 +1054,8 @@ void
1054
1054
  graphql_init(VALUE mod) {
1055
1055
  graphql_class = rb_define_class_under(mod, "GraphQL", rb_cObject);
1056
1056
 
1057
+ rb_undef_alloc_func(graphql_class);
1058
+
1057
1059
  rb_define_module_function(graphql_class, "schema", graphql_schema, 1);
1058
1060
 
1059
1061
  rb_define_module_function(graphql_class, "load", graphql_load, 1);
data/ext/agoo/rresponse.c CHANGED
@@ -243,6 +243,7 @@ void
243
243
  response_init(VALUE mod) {
244
244
  res_class = rb_define_class_under(mod, "Response", rb_cObject);
245
245
 
246
+ rb_undef_alloc_func(res_class);
246
247
  rb_define_method(res_class, "to_s", to_s, 0);
247
248
  rb_define_method(res_class, "body", body_get, 0);
248
249
  rb_define_method(res_class, "body=", body_set, 1);
data/ext/agoo/rupgraded.c CHANGED
@@ -39,7 +39,7 @@ get_upgraded(VALUE self) {
39
39
  const char*
40
40
  extract_subject(VALUE subject, int *slen) {
41
41
  const char *subj;
42
-
42
+
43
43
  switch (rb_type(subject)) {
44
44
  case T_STRING:
45
45
  subj = StringValuePtr(subject);
@@ -84,7 +84,7 @@ rup_write(VALUE self, VALUE msg) {
84
84
  }
85
85
  } else {
86
86
  volatile VALUE rs = rb_funcall(msg, to_s_id, 0);
87
-
87
+
88
88
  message = StringValuePtr(rs);
89
89
  mlen = RSTRING_LEN(rs);
90
90
  }
@@ -165,7 +165,7 @@ static VALUE
165
165
  rup_pending(VALUE self) {
166
166
  agooUpgraded up = get_upgraded(self);
167
167
  int pending = -1;
168
-
168
+
169
169
  if (NULL != up) {
170
170
  pending = agoo_upgraded_pending(up);
171
171
  atomic_fetch_sub(&up->ref_cnt, 1);
@@ -183,7 +183,7 @@ static VALUE
183
183
  rup_open(VALUE self) {
184
184
  agooUpgraded up = get_upgraded(self);
185
185
  int pending = -1;
186
-
186
+
187
187
  if (NULL != up) {
188
188
  pending = (int)(long)atomic_load(&up->pending);
189
189
  atomic_fetch_sub(&up->ref_cnt, 1);
@@ -204,7 +204,7 @@ rup_protocol(VALUE self) {
204
204
 
205
205
  if (agoo_server.active) {
206
206
  agooUpgraded up;
207
-
207
+
208
208
  pthread_mutex_lock(&agoo_server.up_lock);
209
209
  if (NULL != (up = DATA_PTR(self)) && NULL != up->con) {
210
210
  switch (up->con->bind->kind) {
@@ -249,7 +249,7 @@ rupgraded_create(agooCon c, VALUE obj, VALUE env) {
249
249
  up->wrap = (void*)Data_Wrap_Struct(upgraded_class, NULL, NULL, up);
250
250
 
251
251
  agoo_server_add_upgraded(up);
252
-
252
+
253
253
  if (rb_respond_to(obj, on_open_id)) {
254
254
  rb_funcall(obj, on_open_id, 1, (VALUE)up->wrap);
255
255
  }
@@ -285,6 +285,7 @@ void
285
285
  upgraded_init(VALUE mod) {
286
286
  upgraded_class = rb_define_class_under(mod, "Upgraded", rb_cObject);
287
287
 
288
+ rb_undef_alloc_func(upgraded_class);
288
289
  rb_define_method(upgraded_class, "write", rup_write, 1);
289
290
  rb_define_method(upgraded_class, "subscribe", rup_subscribe, 1);
290
291
  rb_define_method(upgraded_class, "unsubscribe", rup_unsubscribe, -1);
data/ext/agoo/sdl.c CHANGED
@@ -22,6 +22,38 @@ static const char union_str[] = "union";
22
22
 
23
23
  static int make_sel(agooErr err, agooDoc doc, gqlDoc gdoc, gqlOp op, gqlSel *parentp);
24
24
 
25
+ /*
26
+ static void
27
+ debug_sels(gqlSel sel, int indent) {
28
+ char pad[100];
29
+
30
+ memset(pad, ' ', sizeof(pad));
31
+ pad[indent] = '\0';
32
+
33
+ printf("%s{%s %s", pad, sel->name, (NULL == sel->type) ? "NULL" : sel->type->name);
34
+ if (NULL == sel->sels) {
35
+ printf("}\n");
36
+ } else {
37
+ printf("\n");
38
+ for (gqlSel sc = sel->sels; NULL != sc; sc = sc->next) {
39
+ debug_sels(sc, indent + 2);
40
+ }
41
+ printf("%s}\n", pad);
42
+ }
43
+ }
44
+
45
+ static void
46
+ debug_doc(gqlDoc doc) {
47
+ printf("*** doc: {\n");
48
+ for (gqlOp op = doc->ops; NULL != op; op = op->next) {
49
+ printf(" {%s\n", op->name);
50
+ debug_sels(op->sels, 4);
51
+ }
52
+ printf(" }\n");
53
+ printf("}\n");
54
+ }
55
+ */
56
+
25
57
  static int
26
58
  extract_desc(agooErr err, agooDoc doc, const char **descp, size_t *lenp) {
27
59
  agoo_doc_skip_white(doc);
@@ -1312,10 +1344,61 @@ make_sel(agooErr err, agooDoc doc, gqlDoc gdoc, gqlOp op, gqlSel *parentp) {
1312
1344
  return AGOO_ERR_OK;
1313
1345
  }
1314
1346
 
1347
+ static gqlType
1348
+ lookup_field_type(gqlType type, const char *field, bool qroot) {
1349
+ gqlType ftype = NULL;
1350
+
1351
+ switch (type->kind) {
1352
+ case GQL_SCHEMA:
1353
+ case GQL_OBJECT:
1354
+ case GQL_INPUT:
1355
+ case GQL_INTERFACE: {
1356
+ gqlField f;
1357
+
1358
+ for (f = type->fields; NULL != f; f = f->next) {
1359
+ if (0 == strcmp(field, f->name)) {
1360
+ ftype = f->type;
1361
+ break;
1362
+ }
1363
+ }
1364
+ if (NULL == ftype) {
1365
+ if (0 == strcmp("__typename", field)) {
1366
+ ftype = &gql_string_type;
1367
+ } else if (qroot) {
1368
+ if (0 == strcmp("__type", field)) {
1369
+ ftype = gql_type_get("__Type");
1370
+ } else if (0 == strcmp("__schema", field)) {
1371
+ ftype = gql_type_get("__Schema");
1372
+ }
1373
+ }
1374
+ }
1375
+ break;
1376
+ }
1377
+ case GQL_LIST:
1378
+ case GQL_NON_NULL:
1379
+ ftype = lookup_field_type(type->base, field, false);
1380
+ break;
1381
+ case GQL_UNION: // Can not be used directly for query type determinations.
1382
+ default:
1383
+ break;
1384
+ }
1385
+ return ftype;
1386
+ }
1387
+
1388
+ static bool
1389
+ has_all_fields(gqlType type, gqlSel sel) {
1390
+ for (; NULL != sel; sel = sel->next) {
1391
+ if (NULL == lookup_field_type(type, sel->name, false)) {
1392
+ return false;
1393
+ }
1394
+ }
1395
+ return true;
1396
+ }
1315
1397
 
1316
1398
  static int
1317
1399
  make_op(agooErr err, agooDoc doc, gqlDoc gdoc, gqlOpKind kind) {
1318
1400
  char name[256];
1401
+ const char *kind_str = query_str;
1319
1402
  const char *start;
1320
1403
  gqlOp op;
1321
1404
  size_t nlen;
@@ -1323,13 +1406,15 @@ make_op(agooErr err, agooDoc doc, gqlDoc gdoc, gqlOpKind kind) {
1323
1406
  agoo_doc_skip_white(doc);
1324
1407
  start = doc->cur;
1325
1408
  agoo_doc_read_token(doc);
1326
- if ( start < doc->cur) {
1409
+ if (start < doc->cur) {
1327
1410
  if (5 == (doc->cur - start) && 0 == strncmp(query_str, start, sizeof(query_str) - 1)) {
1328
1411
  kind = GQL_QUERY;
1329
1412
  } else if (8 == (doc->cur - start) && 0 == strncmp(mutation_str, start, sizeof(mutation_str) - 1)) {
1330
1413
  kind = GQL_MUTATION;
1414
+ kind_str = mutation_str;
1331
1415
  } else if (12 == (doc->cur - start) && 0 == strncmp(subscription_str, start, sizeof(subscription_str) - 1)) {
1332
1416
  kind = GQL_SUBSCRIPTION;
1417
+ kind_str = subscription_str;
1333
1418
  } else {
1334
1419
  return agoo_doc_err(doc, err, "Invalid operation type");
1335
1420
  }
@@ -1384,6 +1469,22 @@ make_op(agooErr err, agooDoc doc, gqlDoc gdoc, gqlOpKind kind) {
1384
1469
  if (doc->end <= doc->cur && '}' != doc->cur[-1]) {
1385
1470
  return agoo_doc_err(doc, err, "Expected a }");
1386
1471
  }
1472
+ if (0 < nlen) {
1473
+ gqlType schema = gql_root_type();
1474
+ gqlType type = lookup_field_type(schema, kind_str, false);
1475
+
1476
+ if ((NULL != lookup_field_type(type, name, false)) &&
1477
+ !has_all_fields(type, op->sels)) {
1478
+
1479
+ gqlSel wrap = sel_create(err, NULL, name, NULL);
1480
+
1481
+ if (NULL == wrap) {
1482
+ return err->code;
1483
+ }
1484
+ wrap->sels = op->sels;
1485
+ op->sels = wrap;
1486
+ }
1487
+ }
1387
1488
  if (NULL == gdoc->ops) {
1388
1489
  gdoc->ops = op;
1389
1490
  } else {
@@ -1461,47 +1562,6 @@ make_fragment(agooErr err, agooDoc doc, gqlDoc gdoc) {
1461
1562
  return AGOO_ERR_OK;
1462
1563
  }
1463
1564
 
1464
- static gqlType
1465
- lookup_field_type(gqlType type, const char *field, bool qroot) {
1466
- gqlType ftype = NULL;
1467
-
1468
- switch (type->kind) {
1469
- case GQL_SCHEMA:
1470
- case GQL_OBJECT:
1471
- case GQL_INPUT:
1472
- case GQL_INTERFACE: {
1473
- gqlField f;
1474
-
1475
- for (f = type->fields; NULL != f; f = f->next) {
1476
- if (0 == strcmp(field, f->name)) {
1477
- ftype = f->type;
1478
- break;
1479
- }
1480
- }
1481
- if (NULL == ftype) {
1482
- if (0 == strcmp("__typename", field)) {
1483
- ftype = &gql_string_type;
1484
- } else if (qroot) {
1485
- if (0 == strcmp("__type", field)) {
1486
- ftype = gql_type_get("__Type");
1487
- } else if (0 == strcmp("__schema", field)) {
1488
- ftype = gql_type_get("__Schema");
1489
- }
1490
- }
1491
- }
1492
- break;
1493
- }
1494
- case GQL_LIST:
1495
- case GQL_NON_NULL:
1496
- ftype = lookup_field_type(type->base, field, false);
1497
- break;
1498
- case GQL_UNION: // Can not be used directly for query type determinations.
1499
- default:
1500
- break;
1501
- }
1502
- return ftype;
1503
- }
1504
-
1505
1565
  static int
1506
1566
  sel_set_type(agooErr err, gqlType type, gqlSel sels, bool qroot) {
1507
1567
  gqlSel sel;
data/lib/agoo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Agoo
3
3
  # Agoo version.
4
- VERSION = '2.15.5'
4
+ VERSION = '2.15.7'
5
5
  end
data/test/graphql_test.rb CHANGED
@@ -428,6 +428,24 @@ directive @ruby(class: String!) on SCHEMA | OBJECT
428
428
  post_test(uri, body, 'application/json', expect)
429
429
  end
430
430
 
431
+ def test_post_json_op
432
+ uri = URI('http://localhost:6472/graphql?indent=2')
433
+ body = %^{
434
+ "query":"query artists{name}"
435
+ }^
436
+ expect = %^{
437
+ "data":{
438
+ "artists":[
439
+ {
440
+ "name":"Fazerdaze"
441
+ }
442
+ ]
443
+ }
444
+ }^
445
+
446
+ post_test(uri, body, 'application/json', expect)
447
+ end
448
+
431
449
  def test_post_fragment
432
450
  uri = URI('http://localhost:6472/graphql?indent=2')
433
451
  body = %^
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.15.5
4
+ version: 2.15.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-07 00:00:00.000000000 Z
11
+ date: 2023-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj