@subsquid/openreader 4.5.1 → 5.0.0-beta.62d187

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 (131) hide show
  1. package/lib/context.d.ts +2 -2
  2. package/lib/context.d.ts.map +1 -1
  3. package/lib/db.d.ts +3 -3
  4. package/lib/db.d.ts.map +1 -1
  5. package/lib/db.js +2 -2
  6. package/lib/db.js.map +1 -1
  7. package/lib/dialect/common.d.ts +19 -0
  8. package/lib/dialect/common.d.ts.map +1 -0
  9. package/lib/dialect/common.js +42 -0
  10. package/lib/dialect/common.js.map +1 -0
  11. package/lib/dialect/index.d.ts +6 -0
  12. package/lib/dialect/index.d.ts.map +1 -0
  13. package/lib/dialect/index.js +49 -0
  14. package/lib/dialect/index.js.map +1 -0
  15. package/lib/{opencrud → dialect/opencrud}/orderBy.d.ts +2 -3
  16. package/lib/dialect/opencrud/orderBy.d.ts.map +1 -0
  17. package/lib/{opencrud → dialect/opencrud}/orderBy.js +6 -21
  18. package/lib/dialect/opencrud/orderBy.js.map +1 -0
  19. package/lib/{opencrud → dialect/opencrud}/schema.d.ts +2 -6
  20. package/lib/dialect/opencrud/schema.d.ts.map +1 -0
  21. package/lib/{opencrud → dialect/opencrud}/schema.js +21 -34
  22. package/lib/dialect/opencrud/schema.js.map +1 -0
  23. package/lib/{opencrud → dialect/opencrud}/tree.d.ts +3 -3
  24. package/lib/dialect/opencrud/tree.d.ts.map +1 -0
  25. package/lib/{opencrud → dialect/opencrud}/tree.js +3 -3
  26. package/lib/dialect/opencrud/tree.js.map +1 -0
  27. package/lib/{opencrud → dialect/opencrud}/where.d.ts +1 -1
  28. package/lib/dialect/opencrud/where.d.ts.map +1 -0
  29. package/lib/{opencrud → dialect/opencrud}/where.js +4 -13
  30. package/lib/dialect/opencrud/where.js.map +1 -0
  31. package/lib/dialect/thegraph/locale.d.ts +2 -0
  32. package/lib/dialect/thegraph/locale.d.ts.map +1 -0
  33. package/lib/dialect/thegraph/locale.js +49 -0
  34. package/lib/dialect/thegraph/locale.js.map +1 -0
  35. package/lib/dialect/thegraph/orderBy.d.ts +11 -0
  36. package/lib/dialect/thegraph/orderBy.d.ts.map +1 -0
  37. package/lib/dialect/thegraph/orderBy.js +71 -0
  38. package/lib/dialect/thegraph/orderBy.js.map +1 -0
  39. package/lib/dialect/thegraph/schema.d.ts +25 -0
  40. package/lib/dialect/thegraph/schema.d.ts.map +1 -0
  41. package/lib/dialect/thegraph/schema.js +429 -0
  42. package/lib/dialect/thegraph/schema.js.map +1 -0
  43. package/lib/dialect/thegraph/tree.d.ts +10 -0
  44. package/lib/dialect/thegraph/tree.d.ts.map +1 -0
  45. package/lib/dialect/thegraph/tree.js +148 -0
  46. package/lib/dialect/thegraph/tree.js.map +1 -0
  47. package/lib/dialect/thegraph/where.d.ts +9 -0
  48. package/lib/dialect/thegraph/where.d.ts.map +1 -0
  49. package/lib/dialect/thegraph/where.js +188 -0
  50. package/lib/dialect/thegraph/where.js.map +1 -0
  51. package/lib/ir/args.d.ts +2 -2
  52. package/lib/ir/args.d.ts.map +1 -1
  53. package/lib/main.js +1 -1
  54. package/lib/main.js.map +1 -1
  55. package/lib/model.d.ts +2 -0
  56. package/lib/model.d.ts.map +1 -1
  57. package/lib/model.schema.d.ts.map +1 -1
  58. package/lib/model.schema.js +31 -2
  59. package/lib/model.schema.js.map +1 -1
  60. package/lib/server.d.ts +3 -1
  61. package/lib/server.d.ts.map +1 -1
  62. package/lib/server.js +7 -6
  63. package/lib/server.js.map +1 -1
  64. package/lib/sql/cursor.d.ts +2 -2
  65. package/lib/sql/cursor.d.ts.map +1 -1
  66. package/lib/sql/cursor.js +2 -2
  67. package/lib/sql/cursor.js.map +1 -1
  68. package/lib/sql/printer.d.ts +3 -3
  69. package/lib/sql/printer.d.ts.map +1 -1
  70. package/lib/sql/printer.js +17 -15
  71. package/lib/sql/printer.js.map +1 -1
  72. package/lib/sql/query.d.ts +5 -5
  73. package/lib/sql/query.d.ts.map +1 -1
  74. package/lib/sql/query.js.map +1 -1
  75. package/lib/sql/util.d.ts +2 -2
  76. package/lib/sql/util.d.ts.map +1 -1
  77. package/lib/sql/util.js.map +1 -1
  78. package/lib/test/basic.test.js +471 -229
  79. package/lib/test/basic.test.js.map +1 -1
  80. package/lib/test/isNull.test.js +87 -36
  81. package/lib/test/isNull.test.js.map +1 -1
  82. package/lib/test/limits.test.js +206 -94
  83. package/lib/test/limits.test.js.map +1 -1
  84. package/lib/test/lookup.test.js +184 -81
  85. package/lib/test/lookup.test.js.map +1 -1
  86. package/lib/test/setup.js +2 -2
  87. package/lib/test/setup.js.map +1 -1
  88. package/lib/test/where.test.js +216 -99
  89. package/lib/test/where.test.js.map +1 -1
  90. package/package.json +8 -6
  91. package/src/context.ts +2 -2
  92. package/src/db.ts +4 -2
  93. package/src/dialect/common.ts +49 -0
  94. package/src/dialect/index.ts +20 -0
  95. package/src/{opencrud → dialect/opencrud}/orderBy.ts +6 -22
  96. package/src/{opencrud → dialect/opencrud}/schema.ts +30 -55
  97. package/src/{opencrud → dialect/opencrud}/tree.ts +6 -7
  98. package/src/{opencrud → dialect/opencrud}/where.ts +4 -16
  99. package/src/dialect/thegraph/locale.ts +284 -0
  100. package/src/dialect/thegraph/orderBy.ts +75 -0
  101. package/src/dialect/thegraph/schema.ts +484 -0
  102. package/src/dialect/thegraph/tree.ts +162 -0
  103. package/src/dialect/thegraph/where.ts +184 -0
  104. package/src/ir/args.ts +3 -1
  105. package/src/main.ts +3 -3
  106. package/src/model.schema.ts +37 -4
  107. package/src/model.ts +2 -0
  108. package/src/server.ts +21 -19
  109. package/src/sql/cursor.ts +4 -4
  110. package/src/sql/printer.ts +22 -18
  111. package/src/sql/query.ts +5 -5
  112. package/src/sql/util.ts +2 -2
  113. package/src/test/basic.test.ts +570 -282
  114. package/src/test/isNull.test.ts +95 -38
  115. package/src/test/limits.test.ts +212 -91
  116. package/src/test/lookup.test.ts +190 -83
  117. package/src/test/setup.ts +2 -2
  118. package/src/test/where.test.ts +235 -108
  119. package/lib/dialect.d.ts +0 -2
  120. package/lib/dialect.d.ts.map +0 -1
  121. package/lib/dialect.js +0 -3
  122. package/lib/dialect.js.map +0 -1
  123. package/lib/opencrud/orderBy.d.ts.map +0 -1
  124. package/lib/opencrud/orderBy.js.map +0 -1
  125. package/lib/opencrud/schema.d.ts.map +0 -1
  126. package/lib/opencrud/schema.js.map +0 -1
  127. package/lib/opencrud/tree.d.ts.map +0 -1
  128. package/lib/opencrud/tree.js.map +0 -1
  129. package/lib/opencrud/where.d.ts.map +0 -1
  130. package/lib/opencrud/where.js.map +0 -1
  131. package/src/dialect.ts +0 -2
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const dialect_1 = require("../dialect");
3
4
  const setup_1 = require("./setup");
4
5
  describe('AND, OR on entity filters', function () {
5
6
  (0, setup_1.useDatabase)([
@@ -11,116 +12,232 @@ describe('AND, OR on entity filters', function () {
11
12
  `insert into item (id, a, b) values ('5', 5, 4)`,
12
13
  `insert into item (id, a, b) values ('6', 5, 6)`,
13
14
  ]);
14
- const client = (0, setup_1.useServer)(`
15
- type Item @entity {
16
- id: ID!
17
- a: Int
18
- b: Int
19
- }
20
- `);
21
- it('{c, and: {c}}', function () {
22
- return client.test(`
23
- query {
24
- items(where: {a_eq: 1, AND: {b_eq: 1}} orderBy: id_ASC) { id }
15
+ describe('opencrud', function () {
16
+ const client = (0, setup_1.useServer)(`
17
+ type Item @entity {
18
+ id: ID!
19
+ a: Int
20
+ b: Int
25
21
  }
26
- `, {
27
- items: [
28
- { id: '1' }
29
- ]
22
+ `);
23
+ it('{c, and: {c}}', function () {
24
+ return client.test(`
25
+ query {
26
+ items(where: {a_eq: 1, AND: {b_eq: 1}} orderBy: id_ASC) { id }
27
+ }
28
+ `, {
29
+ items: [
30
+ { id: '1' }
31
+ ]
32
+ });
30
33
  });
31
- });
32
- it('{and: {and: {c}, c}}', function () {
33
- return client.test(`
34
- query {
35
- items(where: {AND: {b_eq: 2, AND: {a_eq: 3}}} orderBy: id_ASC) { id }
36
- }
37
- `, {
38
- items: [
39
- { id: '3' }
40
- ]
34
+ it('{and: {and: {c}, c}}', function () {
35
+ return client.test(`
36
+ query {
37
+ items(where: {AND: {b_eq: 2, AND: {a_eq: 3}}} orderBy: id_ASC) { id }
38
+ }
39
+ `, {
40
+ items: [
41
+ { id: '3' }
42
+ ]
43
+ });
41
44
  });
42
- });
43
- it('{and: [{c}, {c}]}', function () {
44
- return client.test(`
45
- query {
46
- items(where: {AND: [{a_eq: 2}, {b_eq: 2}]} orderBy: id_ASC) { id }
47
- }
48
- `, {
49
- items: [
50
- { id: '2' }
51
- ]
45
+ it('{and: [{c}, {c}]}', function () {
46
+ return client.test(`
47
+ query {
48
+ items(where: {AND: [{a_eq: 2}, {b_eq: 2}]} orderBy: id_ASC) { id }
49
+ }
50
+ `, {
51
+ items: [
52
+ { id: '2' }
53
+ ]
54
+ });
52
55
  });
53
- });
54
- it('{c, {or: {c}}}', function () {
55
- return client.test(`
56
- query {
57
- items(where: {a_eq: 1, OR: {a_eq: 2}} orderBy: id_ASC) { id }
58
- }
59
- `, {
60
- items: [
61
- { id: '1' },
62
- { id: '2' }
63
- ]
56
+ it('{c, {or: {c}}}', function () {
57
+ return client.test(`
58
+ query {
59
+ items(where: {a_eq: 1, OR: {a_eq: 2}} orderBy: id_ASC) { id }
60
+ }
61
+ `, {
62
+ items: [
63
+ { id: '1' },
64
+ { id: '2' }
65
+ ]
66
+ });
64
67
  });
65
- });
66
- it('{or: [{c}, {c}]}', function () {
67
- return client.test(`
68
- query {
69
- items(where: {OR: [{a_eq: 2}, {a_eq: 3}]} orderBy: id_ASC) { id }
70
- }
71
- `, {
72
- items: [
73
- { id: '2' },
74
- { id: '3' }
75
- ]
68
+ it('{or: [{c}, {c}]}', function () {
69
+ return client.test(`
70
+ query {
71
+ items(where: {OR: [{a_eq: 2}, {a_eq: 3}]} orderBy: id_ASC) { id }
72
+ }
73
+ `, {
74
+ items: [
75
+ { id: '2' },
76
+ { id: '3' }
77
+ ]
78
+ });
76
79
  });
77
- });
78
- it('{or: {or: {c}, c}}', function () {
79
- return client.test(`
80
- query {
81
- items(where: {OR: {a_eq: 1, OR: {b_eq: 2}}} orderBy: id_ASC) { id }
82
- }
83
- `, {
84
- items: [
85
- { id: '1' },
86
- { id: '2' },
87
- { id: '3' }
88
- ]
80
+ it('{or: {or: {c}, c}}', function () {
81
+ return client.test(`
82
+ query {
83
+ items(where: {OR: {a_eq: 1, OR: {b_eq: 2}}} orderBy: id_ASC) { id }
84
+ }
85
+ `, {
86
+ items: [
87
+ { id: '1' },
88
+ { id: '2' },
89
+ { id: '3' }
90
+ ]
91
+ });
89
92
  });
90
- });
91
- it('{and: [{or: {c}, c}, {or: {c}, c}]}', function () {
92
- return client.test(`
93
- query {
94
- items(where: {AND: [{OR: {a_eq: 5}, a_eq: 4}, {OR: {b_eq: 2}, b_eq: 4}]} orderBy: id_ASC) { id }
95
- }
96
- `, {
97
- items: [
98
- { id: '4' },
99
- { id: '5' }
100
- ]
93
+ it('{and: [{or: {c}, c}, {or: {c}, c}]}', function () {
94
+ return client.test(`
95
+ query {
96
+ items(where: {AND: [{OR: {a_eq: 5}, a_eq: 4}, {OR: {b_eq: 2}, b_eq: 4}]} orderBy: id_ASC) { id }
97
+ }
98
+ `, {
99
+ items: [
100
+ { id: '4' },
101
+ { id: '5' }
102
+ ]
103
+ });
101
104
  });
102
- });
103
- it('{c, and: {c}, or: {c}}', function () {
104
- return client.test(`
105
- query {
106
- items(where: { a_eq: 4, AND: {b_eq: 4}, OR: {b_eq: 6} } orderBy: id_ASC) { id }
107
- }
108
- `, {
109
- items: [
110
- { id: '4' },
111
- { id: '6' }
112
- ]
105
+ it('{c, and: {c}, or: {c}}', function () {
106
+ return client.test(`
107
+ query {
108
+ items(where: { a_eq: 4, AND: {b_eq: 4}, OR: {b_eq: 6} } orderBy: id_ASC) { id }
109
+ }
110
+ `, {
111
+ items: [
112
+ { id: '4' },
113
+ { id: '6' }
114
+ ]
115
+ });
116
+ });
117
+ it('handles empty wheres', function () {
118
+ return client.test(`
119
+ query {
120
+ items(where: { a_eq: 4, AND: { OR: {}, AND: {} }, OR: { OR: {AND: {} } } } orderBy: id_ASC) { id }
121
+ }
122
+ `, {
123
+ items: [
124
+ { id: '4' }
125
+ ]
126
+ });
113
127
  });
114
128
  });
115
- it('handles empty wheres', function () {
116
- return client.test(`
117
- query {
118
- items(where: { a_eq: 4, AND: { OR: {}, AND: {} }, OR: { OR: {AND: {} } } } orderBy: id_ASC) { id }
129
+ describe('thegraph', function () {
130
+ const client = (0, setup_1.useServer)(`
131
+ type Item @entity {
132
+ id: ID!
133
+ a: Int
134
+ b: Int
119
135
  }
120
- `, {
121
- items: [
122
- { id: '4' }
123
- ]
136
+ `, { dialect: dialect_1.Dialect.TheGraph });
137
+ it('{c, and: {c}}', function () {
138
+ return client.test(`
139
+ query {
140
+ items(where: {a: 1, and: {b: 1}}, orderBy: id, orderDirection: asc) { id }
141
+ }
142
+ `, {
143
+ items: [
144
+ { id: '1' }
145
+ ]
146
+ });
147
+ });
148
+ it('{and: {and: {c}, c}}', function () {
149
+ return client.test(`
150
+ query {
151
+ items(where: {and: {b: 2, and: {a: 3}}}, orderBy: id, orderDirection: asc) { id }
152
+ }
153
+ `, {
154
+ items: [
155
+ { id: '3' }
156
+ ]
157
+ });
158
+ });
159
+ it('{and: [{c}, {c}]}', function () {
160
+ return client.test(`
161
+ query {
162
+ items(where: {and: [{a: 2}, {b: 2}]}, orderBy: id, orderDirection: asc) { id }
163
+ }
164
+ `, {
165
+ items: [
166
+ { id: '2' }
167
+ ]
168
+ });
169
+ });
170
+ it('{c, {or: {c}}}', function () {
171
+ return client.test(`
172
+ query {
173
+ items(where: {a: 1, or: {a: 2}}, orderBy: id, orderDirection: asc) { id }
174
+ }
175
+ `, {
176
+ items: [
177
+ { id: '1' },
178
+ { id: '2' }
179
+ ]
180
+ });
181
+ });
182
+ it('{or: [{c}, {c}]}', function () {
183
+ return client.test(`
184
+ query {
185
+ items(where: {or: [{a: 2}, {a: 3}]}, orderBy: id, orderDirection: asc) { id }
186
+ }
187
+ `, {
188
+ items: [
189
+ { id: '2' },
190
+ { id: '3' }
191
+ ]
192
+ });
193
+ });
194
+ it('{or: {or: {c}, c}}', function () {
195
+ return client.test(`
196
+ query {
197
+ items(where: {or: {a: 1, or: {b: 2}}}, orderBy: id, orderDirection: asc) { id }
198
+ }
199
+ `, {
200
+ items: [
201
+ { id: '1' },
202
+ { id: '2' },
203
+ { id: '3' }
204
+ ]
205
+ });
206
+ });
207
+ it('{and: [{or: {c}, c}, {or: {c}, c}]}', function () {
208
+ return client.test(`
209
+ query {
210
+ items(where: {and: [{or: {a: 5}, a: 4}, {or: {b: 2}, b: 4}]}, orderBy: id, orderDirection: asc) { id }
211
+ }
212
+ `, {
213
+ items: [
214
+ { id: '4' },
215
+ { id: '5' }
216
+ ]
217
+ });
218
+ });
219
+ it('{c, and: {c}, or: {c}}', function () {
220
+ return client.test(`
221
+ query {
222
+ items(where: { a: 4, and: {b: 4}, or: {b: 6} }, orderBy: id, orderDirection: asc) { id }
223
+ }
224
+ `, {
225
+ items: [
226
+ { id: '4' },
227
+ { id: '6' }
228
+ ]
229
+ });
230
+ });
231
+ it('handles empty wheres', function () {
232
+ return client.test(`
233
+ query {
234
+ items(where: { a: 4, and: { or: {}, and: {} }, or: { or: {and: {} } } }, orderBy: id, orderDirection: asc) { id }
235
+ }
236
+ `, {
237
+ items: [
238
+ { id: '4' }
239
+ ]
240
+ });
124
241
  });
125
242
  });
126
243
  });
@@ -1 +1 @@
1
- {"version":3,"file":"where.test.js","sourceRoot":"","sources":["../../src/test/where.test.ts"],"names":[],"mappings":";;AAAA,mCAA8C;AAE9C,QAAQ,CAAC,2BAA2B,EAAE;IAClC,IAAA,mBAAW,EAAC;QACR,uDAAuD;QACvD,gDAAgD;QAChD,gDAAgD;QAChD,gDAAgD;QAChD,g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aACJ,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,sBAAsB,EAAE;YACvB,OAAO,MAAM,CAAC,IAAI,CAAC;;;;aAIlB,EAAE;gBACC,KAAK,EAAE;oBACH,EAAC,EAAE,EAAE,GAAG,EAAC;iBACZ;aACJ,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subsquid/openreader",
3
- "version": "4.5.1",
3
+ "version": "5.0.0-beta.62d187",
4
4
  "description": "GraphQL server for postgres-compatible databases",
5
5
  "keywords": [
6
6
  "graphql",
@@ -24,11 +24,11 @@
24
24
  "@graphql-tools/merge": "^9.0.1",
25
25
  "@subsquid/graphiql-console": "^0.3.0",
26
26
  "@subsquid/logger": "^1.3.3",
27
- "@subsquid/util-internal": "^3.1.0",
28
- "@subsquid/util-internal-commander": "^1.3.2",
27
+ "@subsquid/util-internal": "^3.2.0",
28
+ "@subsquid/util-internal-commander": "^1.4.0",
29
29
  "@subsquid/util-internal-hex": "^1.2.2",
30
30
  "@subsquid/util-internal-http-server": "^2.0.0",
31
- "@subsquid/util-naming": "^1.2.2",
31
+ "@subsquid/util-naming": "^1.3.0",
32
32
  "apollo-server-core": "^3.13.0",
33
33
  "apollo-server-express": "^3.13.0",
34
34
  "commander": "^11.1.0",
@@ -38,7 +38,8 @@
38
38
  "graphql-parse-resolve-info": "^4.14.0",
39
39
  "graphql-ws": "^5.14.2",
40
40
  "pg": "^8.11.3",
41
- "ws": "^8.14.2"
41
+ "ws": "^8.14.2",
42
+ "inflected": "^2.1.0"
42
43
  },
43
44
  "peerDependencies": {
44
45
  "@subsquid/big-decimal": "^1.0.0"
@@ -59,7 +60,8 @@
59
60
  "expect": "^29.7.0",
60
61
  "gql-test-client": "^0.0.0",
61
62
  "mocha": "^10.2.0",
62
- "typescript": "~5.3.2"
63
+ "typescript": "~5.3.2",
64
+ "@types/inflected": "^2.1.3"
63
65
  },
64
66
  "scripts": {
65
67
  "build": "rm -rf lib && tsc",
package/src/context.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type {Logger} from '@subsquid/logger'
2
- import type {Dialect} from './dialect'
2
+ import type {DbType} from './db'
3
3
  import type {Query} from './sql/query'
4
4
  import type {Limit} from './util/limit'
5
5
 
@@ -11,7 +11,7 @@ export interface Context {
11
11
 
12
12
  export interface OpenreaderContext {
13
13
  id: number
14
- dialect: Dialect
14
+ dbType: DbType
15
15
  executeQuery<T>(query: Query<T>): Promise<T>
16
16
  subscription<T>(query: Query<T>): AsyncIterable<T>
17
17
  responseSizeLimit?: Limit
package/src/db.ts CHANGED
@@ -3,7 +3,6 @@ import {addErrorContext} from '@subsquid/util-internal'
3
3
  import type {ClientBase, Pool} from 'pg'
4
4
  import {QueryResult} from 'pg'
5
5
  import {OpenreaderContext} from './context'
6
- import {Dialect} from './dialect'
7
6
  import {Query} from './sql/query'
8
7
  import {Subscription} from './subscription'
9
8
  import {LazyTransaction} from './util/lazy-transaction'
@@ -12,6 +11,9 @@ import {LazyTransaction} from './util/lazy-transaction'
12
11
  let CTX_COUNTER = 0
13
12
 
14
13
 
14
+ export type DbType = 'postgres' | 'cockroach'
15
+
16
+
15
17
  export class PoolOpenreaderContext implements OpenreaderContext {
16
18
  public id = (CTX_COUNTER = (CTX_COUNTER + 1) % Number.MAX_SAFE_INTEGER)
17
19
  public log?: Logger
@@ -20,7 +22,7 @@ export class PoolOpenreaderContext implements OpenreaderContext {
20
22
  private queryCounter = 0
21
23
 
22
24
  constructor(
23
- public readonly dialect: Dialect,
25
+ public readonly dbType: DbType,
24
26
  pool: Pool,
25
27
  subscriptionPool?: Pool,
26
28
  private subscriptionPollInterval: number = 1000,
@@ -0,0 +1,49 @@
1
+ import {GraphQLFieldConfigMap, GraphQLSchema} from 'graphql'
2
+ import {Model} from '../model'
3
+ import {Context} from '../context'
4
+ import {OrderBy, Where} from '../ir/args'
5
+ import assert from 'assert'
6
+
7
+ export enum Dialect {
8
+ OpenCrud = 'opencrud',
9
+ TheGraph = 'thegraph',
10
+ }
11
+
12
+ export interface SchemaBuilder {
13
+ build(): GraphQLSchema
14
+ }
15
+
16
+ export interface SchemaOptions {
17
+ model: Model
18
+ subscriptions?: boolean
19
+ }
20
+
21
+ export type GqlFieldMap = GraphQLFieldConfigMap<unknown, Context>
22
+
23
+ export function mergeOrderBy(list: OrderBy[]): OrderBy {
24
+ let result: OrderBy = {}
25
+ list.forEach((item) => {
26
+ for (let key in item) {
27
+ let current = result[key]
28
+ if (current == null) {
29
+ result[key] = item[key]
30
+ } else if (typeof current != 'string') {
31
+ let it = item[key]
32
+ assert(typeof it == 'object')
33
+ result[key] = mergeOrderBy([current, it])
34
+ }
35
+ }
36
+ })
37
+ return result
38
+ }
39
+
40
+ export function toCondition(op: 'AND' | 'OR', operands: Where[]): Where | undefined {
41
+ switch(operands.length) {
42
+ case 0:
43
+ return undefined
44
+ case 1:
45
+ return operands[0]
46
+ default:
47
+ return {op, args: operands}
48
+ }
49
+ }
@@ -0,0 +1,20 @@
1
+ import {unexpectedCase} from '@subsquid/util-internal'
2
+ import {Dialect, SchemaBuilder, SchemaOptions} from './common'
3
+
4
+ export * from './common'
5
+
6
+ export async function getSchemaBuilder(options: SchemaOptions & {dialect?: Dialect}): Promise<SchemaBuilder> {
7
+ switch (options.dialect) {
8
+ case undefined:
9
+ case Dialect.OpenCrud: {
10
+ const {SchemaBuilder} = await import('./opencrud/schema')
11
+ return new SchemaBuilder(options)
12
+ }
13
+ case Dialect.TheGraph: {
14
+ const {SchemaBuilder} = await import('./thegraph/schema')
15
+ return new SchemaBuilder(options)
16
+ }
17
+ default:
18
+ throw unexpectedCase(options.dialect)
19
+ }
20
+ }
@@ -1,7 +1,8 @@
1
1
  import assert from "assert"
2
- import type { Model } from "../model"
3
- import { getUniversalProperties } from '../model.tools'
4
- import { OrderBy } from "../ir/args"
2
+ import type { Model } from "../../model"
3
+ import { getUniversalProperties } from '../../model.tools'
4
+ import { OrderBy } from "../../ir/args"
5
+ import {mergeOrderBy} from '../common'
5
6
 
6
7
 
7
8
  /**
@@ -43,8 +44,9 @@ function buildOrderByMapping(model: Model, typeName: string, depth: number): Ope
43
44
  m.set(key + '_ASC', { [key]: 'ASC' })
44
45
  m.set(key + '_DESC', { [key]: 'DESC' })
45
46
  m.set(key + '_ASC_NULLS_FIRST', { [key]: 'ASC NULLS FIRST' });
47
+ m.set(key + '_ASC_NULLS_LAST', { [key]: 'ASC NULLS LAST' });
48
+ m.set(key + '_DESC_NULLS_FIRST', { [key]: 'DESC NULLS FIRST' });
46
49
  m.set(key + '_DESC_NULLS_LAST', { [key]: 'DESC NULLS LAST' });
47
-
48
50
  }
49
51
  break
50
52
  case 'object':
@@ -79,21 +81,3 @@ export function parseOrderBy(model: Model, typeName: string, input: OpenCrudOrde
79
81
  })
80
82
  )
81
83
  }
82
-
83
-
84
- export function mergeOrderBy(list: OrderBy[]): OrderBy {
85
- let result: OrderBy = {}
86
- list.forEach(item => {
87
- for (let key in item) {
88
- let current = result[key]
89
- if (current == null) {
90
- result[key] = item[key]
91
- } else if (typeof current != 'string') {
92
- let it = item[key]
93
- assert(typeof it == 'object')
94
- result[key] = mergeOrderBy([current, it])
95
- }
96
- }
97
- })
98
- return result
99
- }