@snowtop/ent 0.1.0-alpha8 → 0.1.0-alpha9
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.
- package/graphql/builtins/connection.js +3 -3
- package/graphql/builtins/edge.js +2 -2
- package/graphql/builtins/node.js +1 -1
- package/graphql/graphql.js +2 -2
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/page_info.js +4 -4
- package/graphql/query/shared_assoc_test.js +2 -2
- package/graphql/scalars/time.d.ts +1 -1
- package/package.json +2 -2
- package/parse_schema/parse.d.ts +5 -1
- package/parse_schema/parse.js +1 -0
- package/schema/base_schema.d.ts +1 -1
- package/scripts/read_schema.js +15 -1
- package/scripts/transform_schema.js +12 -4
- package/testutils/ent-graphql-tests/index.js +19 -12
|
@@ -11,13 +11,13 @@ exports.GraphQLConnectionInterface = new graphql_1.GraphQLInterfaceType({
|
|
|
11
11
|
description: "connection interface",
|
|
12
12
|
fields: () => ({
|
|
13
13
|
edges: {
|
|
14
|
-
type:
|
|
14
|
+
type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(edge_1.GraphQLEdgeInterface))),
|
|
15
15
|
},
|
|
16
16
|
nodes: {
|
|
17
|
-
type:
|
|
17
|
+
type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(node_1.GraphQLNodeInterface))),
|
|
18
18
|
},
|
|
19
19
|
pageInfo: {
|
|
20
|
-
type:
|
|
20
|
+
type: new graphql_1.GraphQLNonNull(page_info_1.GraphQLPageInfo),
|
|
21
21
|
},
|
|
22
22
|
}),
|
|
23
23
|
});
|
package/graphql/builtins/edge.js
CHANGED
|
@@ -9,10 +9,10 @@ exports.GraphQLEdgeInterface = new graphql_1.GraphQLInterfaceType({
|
|
|
9
9
|
description: "edge interface",
|
|
10
10
|
fields: () => ({
|
|
11
11
|
node: {
|
|
12
|
-
type:
|
|
12
|
+
type: new graphql_1.GraphQLNonNull(node_1.GraphQLNodeInterface),
|
|
13
13
|
},
|
|
14
14
|
cursor: {
|
|
15
|
-
type:
|
|
15
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString),
|
|
16
16
|
},
|
|
17
17
|
}),
|
|
18
18
|
});
|
package/graphql/builtins/node.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.GraphQLNodeInterface = new graphql_1.GraphQLInterfaceType({
|
|
|
8
8
|
description: "node interface",
|
|
9
9
|
fields: () => ({
|
|
10
10
|
id: {
|
|
11
|
-
type:
|
|
11
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID),
|
|
12
12
|
},
|
|
13
13
|
}),
|
|
14
14
|
});
|
package/graphql/graphql.js
CHANGED
|
@@ -79,8 +79,8 @@ const addCustomType = (type) => {
|
|
|
79
79
|
description: ct.description,
|
|
80
80
|
name: ct.name,
|
|
81
81
|
};
|
|
82
|
-
if (ct.
|
|
83
|
-
type.scalarInfo.specifiedByUrl = ct.
|
|
82
|
+
if (ct.specifiedByURL) {
|
|
83
|
+
type.scalarInfo.specifiedByUrl = ct.specifiedByURL;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -15,10 +15,10 @@ class GraphQLEdgeType extends graphql_1.GraphQLObjectType {
|
|
|
15
15
|
name: `${name}Edge`,
|
|
16
16
|
fields: () => ({
|
|
17
17
|
node: {
|
|
18
|
-
type:
|
|
18
|
+
type: new graphql_1.GraphQLNonNull(nodeType),
|
|
19
19
|
},
|
|
20
20
|
cursor: {
|
|
21
|
-
type:
|
|
21
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString),
|
|
22
22
|
},
|
|
23
23
|
...optional,
|
|
24
24
|
}),
|
|
@@ -34,25 +34,25 @@ class GraphQLConnectionType extends graphql_1.GraphQLObjectType {
|
|
|
34
34
|
name: `${name}Connection`,
|
|
35
35
|
fields: () => ({
|
|
36
36
|
edges: {
|
|
37
|
-
type:
|
|
37
|
+
type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(edgeType))),
|
|
38
38
|
resolve: (source) => {
|
|
39
39
|
return source.queryEdges();
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
42
|
nodes: {
|
|
43
|
-
type:
|
|
43
|
+
type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(nodeType))),
|
|
44
44
|
resolve: (source) => {
|
|
45
45
|
return source.queryNodes();
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
48
|
pageInfo: {
|
|
49
|
-
type:
|
|
49
|
+
type: new graphql_1.GraphQLNonNull(page_info_1.GraphQLPageInfo),
|
|
50
50
|
resolve: (source) => {
|
|
51
51
|
return source.queryPageInfo();
|
|
52
52
|
},
|
|
53
53
|
},
|
|
54
54
|
rawCount: {
|
|
55
|
-
type:
|
|
55
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt),
|
|
56
56
|
resolve: (source) => {
|
|
57
57
|
return source.queryTotalCount();
|
|
58
58
|
},
|
|
@@ -7,22 +7,22 @@ exports.GraphQLPageInfo = new graphql_1.GraphQLObjectType({
|
|
|
7
7
|
name: "PageInfo",
|
|
8
8
|
fields: () => ({
|
|
9
9
|
hasNextPage: {
|
|
10
|
-
type:
|
|
10
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean),
|
|
11
11
|
resolve: (source) => {
|
|
12
12
|
return source.hasNextPage || false;
|
|
13
13
|
},
|
|
14
14
|
},
|
|
15
15
|
hasPreviousPage: {
|
|
16
|
-
type:
|
|
16
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean),
|
|
17
17
|
resolve: (source) => {
|
|
18
18
|
return source.hasPreviousPage || false;
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
21
|
startCursor: {
|
|
22
|
-
type:
|
|
22
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString),
|
|
23
23
|
},
|
|
24
24
|
endCursor: {
|
|
25
|
-
type:
|
|
25
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString),
|
|
26
26
|
},
|
|
27
27
|
}),
|
|
28
28
|
});
|
|
@@ -110,7 +110,7 @@ function sharedAssocTests() {
|
|
|
110
110
|
name: "User",
|
|
111
111
|
fields: {
|
|
112
112
|
id: {
|
|
113
|
-
type:
|
|
113
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID),
|
|
114
114
|
},
|
|
115
115
|
firstName: {
|
|
116
116
|
type: graphql_1.GraphQLString,
|
|
@@ -128,7 +128,7 @@ function sharedAssocTests() {
|
|
|
128
128
|
name: "Event",
|
|
129
129
|
fields: {
|
|
130
130
|
id: {
|
|
131
|
-
type:
|
|
131
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID),
|
|
132
132
|
},
|
|
133
133
|
},
|
|
134
134
|
interfaces: [node_1.GraphQLNodeInterface],
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const GraphQLTime: GraphQLScalarType
|
|
2
|
+
export declare const GraphQLTime: GraphQLScalarType<Date, string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snowtop/ent",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-alpha9",
|
|
4
4
|
"description": "snowtop ent framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"better-sqlite3": "^7.4.1",
|
|
34
|
-
"graphql": "^
|
|
34
|
+
"graphql": "^16.5.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"better-sqlite3": {
|
package/parse_schema/parse.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" |
|
|
|
23
23
|
assocEdges: ProcessedAssocEdge[];
|
|
24
24
|
assocEdgeGroups: ProcessedAssocEdgeGroup[];
|
|
25
25
|
fields: ProcessedField[];
|
|
26
|
+
schemaPath?: string;
|
|
26
27
|
};
|
|
27
28
|
declare type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
|
|
28
29
|
edgeAction?: OutputAction;
|
|
@@ -59,5 +60,8 @@ interface Result {
|
|
|
59
60
|
schemas: schemasDict;
|
|
60
61
|
patterns: patternsDict;
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
+
declare type PotentialSchemas = {
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
};
|
|
66
|
+
export declare function parseSchema(potentialSchemas: PotentialSchemas): Result;
|
|
63
67
|
export {};
|
package/parse_schema/parse.js
CHANGED
package/schema/base_schema.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare class EntSchema implements Schema {
|
|
|
20
20
|
hideFromGraphQL?: boolean;
|
|
21
21
|
constructor(cfg: SchemaConfig);
|
|
22
22
|
}
|
|
23
|
-
export declare class EntSchemaWithTZ {
|
|
23
|
+
export declare class EntSchemaWithTZ implements Schema {
|
|
24
24
|
fields: FieldMap | Field[];
|
|
25
25
|
tableName: string | undefined;
|
|
26
26
|
patterns: Pattern[];
|
package/scripts/read_schema.js
CHANGED
|
@@ -44,7 +44,21 @@ function main() {
|
|
|
44
44
|
if (!match) {
|
|
45
45
|
throw new Error(`non-typescript file ${p} returned by glob`);
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
let schema = match[1];
|
|
48
|
+
// convert foo_schema.ts -> foo
|
|
49
|
+
if (schema.endsWith("_schema")) {
|
|
50
|
+
schema = schema.slice(0, -7);
|
|
51
|
+
}
|
|
52
|
+
let relativePath;
|
|
53
|
+
const index = p.indexOf("src/schema");
|
|
54
|
+
if (index !== -1) {
|
|
55
|
+
relativePath = p.substring(index);
|
|
56
|
+
}
|
|
57
|
+
const s = require(p).default;
|
|
58
|
+
if (relativePath !== undefined) {
|
|
59
|
+
s.schemaPath = relativePath;
|
|
60
|
+
}
|
|
61
|
+
potentialSchemas[(0, pascal_case_1.pascalCase)(schema)] = s;
|
|
48
62
|
}
|
|
49
63
|
// console.log(potentialSchemas);
|
|
50
64
|
const result = (0, parse_1.parseSchema)(potentialSchemas);
|
|
@@ -27,6 +27,7 @@ const typescript_1 = __importDefault(require("typescript"));
|
|
|
27
27
|
const fs = __importStar(require("fs"));
|
|
28
28
|
const compilerOptions_1 = require("../tsc/compilerOptions");
|
|
29
29
|
const child_process_1 = require("child_process");
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
30
31
|
function getTarget(target) {
|
|
31
32
|
switch (target.toLowerCase()) {
|
|
32
33
|
case "es2015":
|
|
@@ -62,12 +63,15 @@ async function main() {
|
|
|
62
63
|
getTarget(options.target)
|
|
63
64
|
: typescript_1.default.ScriptTarget.ESNext;
|
|
64
65
|
// filter to only event.ts e.g. for comments and whitespace...
|
|
65
|
-
//
|
|
66
|
+
// files = files.filter((f) => f.endsWith("event.ts"));
|
|
66
67
|
files.forEach((file) => {
|
|
67
68
|
// assume valid file since we do glob above
|
|
68
69
|
// const idx = file.lastIndexOf(".ts");
|
|
69
70
|
// const writeFile = file.substring(0, idx) + "2" + ".ts";
|
|
70
|
-
|
|
71
|
+
// console.debug(file);
|
|
72
|
+
const writeFile = "src/schema/" + path_1.default.basename(file).slice(0, -3) + "_schema.ts";
|
|
73
|
+
// const writeFile = file;
|
|
74
|
+
// console.debug(file, writeFile);
|
|
71
75
|
let contents = fs.readFileSync(file).toString();
|
|
72
76
|
// go through the file and print everything back if not starting immediately after other position
|
|
73
77
|
const sourceFile = typescript_1.default.createSourceFile(file, contents, target, false, typescript_1.default.ScriptKind.TS);
|
|
@@ -115,6 +119,7 @@ async function main() {
|
|
|
115
119
|
// console.debug(newContents);
|
|
116
120
|
// ideally there's a flag that indicates if we write
|
|
117
121
|
fs.writeFileSync(writeFile, newContents);
|
|
122
|
+
fs.rmSync(file);
|
|
118
123
|
});
|
|
119
124
|
(0, child_process_1.execSync)("prettier src/schema/*.ts --write");
|
|
120
125
|
}
|
|
@@ -173,7 +178,10 @@ function transformSchema(str) {
|
|
|
173
178
|
return str;
|
|
174
179
|
}
|
|
175
180
|
function getClassInfo(fileContents, sourceFile, node) {
|
|
176
|
-
|
|
181
|
+
let className = node.name?.text;
|
|
182
|
+
if (!className?.endsWith("Schema")) {
|
|
183
|
+
className += "Schema";
|
|
184
|
+
}
|
|
177
185
|
let classExtends;
|
|
178
186
|
let implementsSchema = false;
|
|
179
187
|
if (node.heritageClauses) {
|
|
@@ -429,7 +437,7 @@ function transformImport(importNode, sourceFile, removeImports) {
|
|
|
429
437
|
importText.substring(end) +
|
|
430
438
|
' from "' +
|
|
431
439
|
text +
|
|
432
|
-
'"');
|
|
440
|
+
'";');
|
|
433
441
|
}
|
|
434
442
|
function getPreText(fileContents, node, sourceFile) {
|
|
435
443
|
return fileContents.substring(node.getFullStart(), node.getStart(sourceFile));
|
|
@@ -26,7 +26,7 @@ exports.expectMutation = exports.expectQueryFromRoot = void 0;
|
|
|
26
26
|
// NB: this is copied from ent-graphql-tests package until I have time to figure out how to share code here effectively
|
|
27
27
|
// the circular dependencies btw this package and ent-graphql-tests seems to imply something needs to change
|
|
28
28
|
const express_1 = __importDefault(require("express"));
|
|
29
|
-
const
|
|
29
|
+
const graphql_helix_1 = require("graphql-helix");
|
|
30
30
|
const graphql_1 = require("graphql");
|
|
31
31
|
const auth_1 = require("../../auth");
|
|
32
32
|
const supertest_1 = __importDefault(require("supertest"));
|
|
@@ -45,17 +45,22 @@ function server(config) {
|
|
|
45
45
|
if (config.init) {
|
|
46
46
|
config.init(app);
|
|
47
47
|
}
|
|
48
|
+
app.use(express_1.default.json());
|
|
48
49
|
let handlers = config.customHandlers || [];
|
|
49
|
-
handlers.push(
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
handlers.push(async (req, res) => {
|
|
51
|
+
const { operationName, query, variables } = (0, graphql_helix_1.getGraphQLParameters)(req);
|
|
52
|
+
const result = await (0, graphql_helix_1.processRequest)({
|
|
53
|
+
operationName,
|
|
54
|
+
query,
|
|
55
|
+
variables,
|
|
56
|
+
request: req,
|
|
57
|
+
schema: config.schema,
|
|
58
|
+
contextFactory: async (executionContext) => {
|
|
59
|
+
return (0, auth_1.buildContext)(req, res);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
await (0, graphql_helix_1.sendResult)(result, res);
|
|
63
|
+
});
|
|
59
64
|
app.use(config.graphQLPath || "/graphql", ...handlers);
|
|
60
65
|
return app;
|
|
61
66
|
}
|
|
@@ -355,7 +360,9 @@ async function expectFromRoot(config, ...options) {
|
|
|
355
360
|
else {
|
|
356
361
|
expect(res.ok, `expected ok response. instead got ${res.status} and result ${JSON.stringify(res.body)}`);
|
|
357
362
|
}
|
|
358
|
-
|
|
363
|
+
// res.ok = true in graphql-helix when there's errors...
|
|
364
|
+
// res.ok = false in express-graphql when there's errors...
|
|
365
|
+
if (!res.ok || (res.body.errors && res.body.errors.length > 0)) {
|
|
359
366
|
let errors = res.body.errors;
|
|
360
367
|
expect(errors.length).toBeGreaterThan(0);
|
|
361
368
|
if (config.expectedError) {
|