@luvio/compiler 0.81.0 → 0.81.1-238.0
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/dist/codegen/graphql/enum/interface.d.ts +4 -0
- package/dist/codegen/graphql/enum/interface.js +32 -0
- package/dist/codegen/graphql/enum/interface.js.map +1 -0
- package/dist/codegen/graphql/graphql-dsl.d.ts +19 -0
- package/dist/codegen/graphql/graphql-dsl.js +29 -0
- package/dist/codegen/graphql/graphql-dsl.js.map +1 -0
- package/dist/codegen/graphql/source-printer/graphql-adapter-source-printer.d.ts +8 -0
- package/dist/codegen/graphql/source-printer/graphql-adapter-source-printer.js +11 -0
- package/dist/codegen/graphql/source-printer/graphql-adapter-source-printer.js.map +1 -0
- package/dist/codegen/graphql/source-printer/graphql-resource-source-printer.d.ts +8 -0
- package/dist/codegen/graphql/source-printer/graphql-resource-source-printer.js +11 -0
- package/dist/codegen/graphql/source-printer/graphql-resource-source-printer.js.map +1 -0
- package/dist/codegen/graphql/source-printer/graphql-source-printer.d.ts +19 -0
- package/dist/codegen/graphql/source-printer/graphql-source-printer.js +44 -0
- package/dist/codegen/graphql/source-printer/graphql-source-printer.js.map +1 -0
- package/dist/codegen/graphql/source-printer/graphql-type-source-printer.d.ts +16 -0
- package/dist/codegen/graphql/source-printer/graphql-type-source-printer.js +60 -0
- package/dist/codegen/graphql/source-printer/graphql-type-source-printer.js.map +1 -0
- package/dist/codegen/graphql/source-printer/index.d.ts +5 -0
- package/dist/codegen/graphql/source-printer/index.js +12 -0
- package/dist/codegen/graphql/source-printer/index.js.map +1 -0
- package/dist/codegen/graphql/type/constants.d.ts +7 -0
- package/dist/codegen/graphql/type/constants.js +11 -0
- package/dist/codegen/graphql/type/constants.js.map +1 -0
- package/dist/codegen/graphql/type/ingest.d.ts +9 -0
- package/dist/codegen/graphql/type/ingest.js +131 -0
- package/dist/codegen/graphql/type/ingest.js.map +1 -0
- package/dist/codegen/graphql/union/interface.d.ts +4 -0
- package/dist/codegen/graphql/union/interface.js +30 -0
- package/dist/codegen/graphql/union/interface.js.map +1 -0
- package/dist/codegen/graphql/utils/index.d.ts +1 -0
- package/dist/codegen/graphql/utils/index.js +8 -0
- package/dist/codegen/graphql/utils/index.js.map +1 -0
- package/dist/codegen/graphql/utils/types.d.ts +10 -0
- package/dist/codegen/graphql/utils/types.js +45 -0
- package/dist/codegen/graphql/utils/types.js.map +1 -0
- package/dist/codegen/rest/source-printer/rest-adapter-source-printer.d.ts +15 -0
- package/dist/codegen/rest/source-printer/rest-adapter-source-printer.js +56 -0
- package/dist/codegen/rest/source-printer/rest-adapter-source-printer.js.map +1 -0
- package/dist/codegen/rest/source-printer/rest-source-printer.d.ts +15 -0
- package/dist/codegen/rest/source-printer/rest-source-printer.js +72 -0
- package/dist/codegen/rest/source-printer/rest-source-printer.js.map +1 -0
- package/dist/codegen/shape/shape-select-paginated.js +5 -8
- package/dist/codegen/shape/shape-select-paginated.js.map +1 -1
- package/dist/codegen/source-writer/file-system-source-writer.d.ts +14 -0
- package/dist/codegen/source-writer/file-system-source-writer.js +31 -0
- package/dist/codegen/source-writer/file-system-source-writer.js.map +1 -0
- package/dist/compiler/raml-compiler.d.ts +14 -0
- package/dist/compiler/raml-compiler.js +41 -0
- package/dist/compiler/raml-compiler.js.map +1 -0
- package/dist/interfaces/compiler.d.ts +4 -0
- package/dist/interfaces/compiler.js +3 -0
- package/dist/interfaces/compiler.js.map +1 -0
- package/dist/interfaces/index.d.ts +5 -0
- package/dist/interfaces/index.js +3 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/source-printers/graphql/graphql-adapter-printer.d.ts +7 -0
- package/dist/interfaces/source-printers/graphql/graphql-adapter-printer.js +3 -0
- package/dist/interfaces/source-printers/graphql/graphql-adapter-printer.js.map +1 -0
- package/dist/interfaces/source-printers/graphql/graphql-resource-printer.d.ts +7 -0
- package/dist/interfaces/source-printers/graphql/graphql-resource-printer.js +3 -0
- package/dist/interfaces/source-printers/graphql/graphql-resource-printer.js.map +1 -0
- package/dist/interfaces/source-printers/graphql/graphql-type-printer.d.ts +9 -0
- package/dist/interfaces/source-printers/graphql/graphql-type-printer.js +3 -0
- package/dist/interfaces/source-printers/graphql/graphql-type-printer.js.map +1 -0
- package/dist/interfaces/source-printers/index.d.ts +5 -0
- package/dist/interfaces/source-printers/index.js +3 -0
- package/dist/interfaces/source-printers/index.js.map +1 -0
- package/dist/interfaces/source-printers/rest/rest-adapter-printer.d.ts +5 -0
- package/dist/interfaces/source-printers/rest/rest-adapter-printer.js +3 -0
- package/dist/interfaces/source-printers/rest/rest-adapter-printer.js.map +1 -0
- package/dist/interfaces/source-printers/source-printer.d.ts +6 -0
- package/dist/interfaces/source-printers/source-printer.js +3 -0
- package/dist/interfaces/source-printers/source-printer.js.map +1 -0
- package/dist/interfaces/source-writer.d.ts +5 -0
- package/dist/interfaces/source-writer.js +3 -0
- package/dist/interfaces/source-writer.js.map +1 -0
- package/package.json +6 -5
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { EnumTypeDefinitionNode } from '@luvio/graphql-parser';
|
|
2
|
+
import type { ImportContext } from '../../../utils/imports';
|
|
3
|
+
import type { GraphQLCodegenMetadata } from '../source-printer/graphql-source-printer';
|
|
4
|
+
export declare function generateInterface(name: string, def: EnumTypeDefinitionNode, _importContext: ImportContext, _metadata: GraphQLCodegenMetadata): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateInterface = void 0;
|
|
7
|
+
const deindent_1 = __importDefault(require("../../../utils/deindent"));
|
|
8
|
+
const interface_1 = require("../type/interface");
|
|
9
|
+
function generateInterface(name, def, _importContext, _metadata) {
|
|
10
|
+
return generateEnumDefinitionNode(name, def);
|
|
11
|
+
}
|
|
12
|
+
exports.generateInterface = generateInterface;
|
|
13
|
+
function generateEnumDefinitionNode(name, def) {
|
|
14
|
+
const { values } = def;
|
|
15
|
+
if (values === undefined) {
|
|
16
|
+
return (0, deindent_1.default) `
|
|
17
|
+
enum ${interface_1.TYPE_INTERFACE_IDENTIFIER} {}
|
|
18
|
+
`;
|
|
19
|
+
}
|
|
20
|
+
const rendered = values.map((value) => {
|
|
21
|
+
const { value: enumName } = value.name;
|
|
22
|
+
return (0, deindent_1.default) `
|
|
23
|
+
${enumName} = '${enumName}'
|
|
24
|
+
`;
|
|
25
|
+
});
|
|
26
|
+
return (0, deindent_1.default) `
|
|
27
|
+
export enum ${interface_1.TYPE_INTERFACE_IDENTIFIER} {
|
|
28
|
+
${rendered.join(',\n')}
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../../src/codegen/graphql/enum/interface.ts"],"names":[],"mappings":";;;;;;AACA,uEAA+C;AAG/C,iDAA8D;AAE9D,SAAgB,iBAAiB,CAC7B,IAAY,EACZ,GAA2B,EAC3B,cAA6B,EAC7B,SAAiC;IAEjC,OAAO,0BAA0B,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACjD,CAAC;AAPD,8CAOC;AAED,SAAS,0BAA0B,CAAC,IAAY,EAAE,GAA2B;IACzE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IACvB,IAAI,MAAM,KAAK,SAAS,EAAE;QACtB,OAAO,IAAA,kBAAQ,EAAA;mBACJ,qCAAyB;SACnC,CAAC;KACL;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAClC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC;QACvC,OAAO,IAAA,kBAAQ,EAAA;cACT,QAAQ,OAAO,QAAQ;SAC5B,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,OAAO,IAAA,kBAAQ,EAAA;sBACG,qCAAyB;cACjC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;;KAE7B,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { GraphQLSchema, GraphQLScalarType } from '@luvio/graphql-parser';
|
|
2
|
+
interface LuvioGraphQLDSLParams {
|
|
3
|
+
schema: GraphQLSchema;
|
|
4
|
+
schemaName: string;
|
|
5
|
+
}
|
|
6
|
+
export interface LuvioGraphQLDSL {
|
|
7
|
+
schema: Readonly<GraphQLSchema>;
|
|
8
|
+
schemaName: Readonly<string>;
|
|
9
|
+
customScalars: GraphQLScalarType[];
|
|
10
|
+
}
|
|
11
|
+
export declare class GraphQLDSL implements LuvioGraphQLDSL {
|
|
12
|
+
schema: Readonly<GraphQLSchema>;
|
|
13
|
+
schemaName: Readonly<string>;
|
|
14
|
+
customScalars: GraphQLScalarType[];
|
|
15
|
+
constructor(luvioSchemaParams: Readonly<LuvioGraphQLDSLParams>);
|
|
16
|
+
private extractCustomScalars;
|
|
17
|
+
}
|
|
18
|
+
export declare function interpretGraphQLDSL(schemaString: string, schemaName: string): LuvioGraphQLDSL;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interpretGraphQLDSL = exports.GraphQLDSL = void 0;
|
|
4
|
+
const graphql_parser_1 = require("@luvio/graphql-parser");
|
|
5
|
+
class GraphQLDSL {
|
|
6
|
+
constructor(luvioSchemaParams) {
|
|
7
|
+
this.customScalars = [];
|
|
8
|
+
this.schemaName = luvioSchemaParams.schemaName;
|
|
9
|
+
this.schema = luvioSchemaParams.schema;
|
|
10
|
+
this.extractCustomScalars();
|
|
11
|
+
}
|
|
12
|
+
extractCustomScalars() {
|
|
13
|
+
Object.values(this.schema.getTypeMap()).forEach((def) => {
|
|
14
|
+
if ((0, graphql_parser_1.isScalarType)(def) && def.astNode !== undefined) {
|
|
15
|
+
this.customScalars.push(def);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.GraphQLDSL = GraphQLDSL;
|
|
21
|
+
function interpretGraphQLDSL(schemaString, schemaName) {
|
|
22
|
+
const schema = (0, graphql_parser_1.buildASTSchema)((0, graphql_parser_1.parse)(schemaString));
|
|
23
|
+
return new GraphQLDSL({
|
|
24
|
+
schema,
|
|
25
|
+
schemaName,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exports.interpretGraphQLDSL = interpretGraphQLDSL;
|
|
29
|
+
//# sourceMappingURL=graphql-dsl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-dsl.js","sourceRoot":"","sources":["../../../src/codegen/graphql/graphql-dsl.ts"],"names":[],"mappings":";;;AAAA,0DAA4E;AAc5E,MAAa,UAAU;IAOnB,YAAY,iBAAkD;QAF9D,kBAAa,GAAwB,EAAE,CAAC;QAGpC,IAAI,CAAC,UAAU,GAAG,iBAAiB,CAAC,UAAU,CAAC;QAC/C,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC;QAEvC,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAChC,CAAC;IAEO,oBAAoB;QACxB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACpD,IAAI,IAAA,6BAAY,EAAC,GAAG,CAAC,IAAI,GAAG,CAAC,OAAO,KAAK,SAAS,EAAE;gBAChD,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aAChC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AArBD,gCAqBC;AAED,SAAgB,mBAAmB,CAAC,YAAoB,EAAE,UAAkB;IACxE,MAAM,MAAM,GAAG,IAAA,+BAAc,EAAC,IAAA,sBAAK,EAAC,YAAY,CAAC,CAAC,CAAC;IACnD,OAAO,IAAI,UAAU,CAAC;QAClB,MAAM;QACN,UAAU;KACb,CAAC,CAAC;AACP,CAAC;AAND,kDAMC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LuvioGraphQLDSL } from '../graphql-dsl';
|
|
2
|
+
import type { GraphQLAdapterPrinter } from '../../../interfaces';
|
|
3
|
+
import type { GraphQLCodegenMetadata } from './graphql-source-printer';
|
|
4
|
+
export declare class GraphQLAdapterSourcePrinter implements GraphQLAdapterPrinter {
|
|
5
|
+
generate(_graphqlDsl: LuvioGraphQLDSL, _metadata: GraphQLCodegenMetadata): {
|
|
6
|
+
[path: string]: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLAdapterSourcePrinter = void 0;
|
|
4
|
+
class GraphQLAdapterSourcePrinter {
|
|
5
|
+
generate(_graphqlDsl, _metadata) {
|
|
6
|
+
// TODO: Generate Adapter Code W-10674742
|
|
7
|
+
return {};
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.GraphQLAdapterSourcePrinter = GraphQLAdapterSourcePrinter;
|
|
11
|
+
//# sourceMappingURL=graphql-adapter-source-printer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-adapter-source-printer.js","sourceRoot":"","sources":["../../../../src/codegen/graphql/source-printer/graphql-adapter-source-printer.ts"],"names":[],"mappings":";;;AAIA,MAAa,2BAA2B;IACpC,QAAQ,CACJ,WAA4B,EAC5B,SAAiC;QAEjC,yCAAyC;QACzC,OAAO,EAAE,CAAC;IACd,CAAC;CACJ;AARD,kEAQC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LuvioGraphQLDSL } from '../graphql-dsl';
|
|
2
|
+
import type { GraphQLResourcePrinter } from '../../../interfaces';
|
|
3
|
+
import type { GraphQLCodegenMetadata } from './graphql-source-printer';
|
|
4
|
+
export declare class GraphQLResourceSourcePrinter implements GraphQLResourcePrinter {
|
|
5
|
+
generate(_graphqlDsl: LuvioGraphQLDSL, _metadata: GraphQLCodegenMetadata): {
|
|
6
|
+
[path: string]: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLResourceSourcePrinter = void 0;
|
|
4
|
+
class GraphQLResourceSourcePrinter {
|
|
5
|
+
generate(_graphqlDsl, _metadata) {
|
|
6
|
+
// TODO: Generate Resource Code W-10768414
|
|
7
|
+
return {};
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.GraphQLResourceSourcePrinter = GraphQLResourceSourcePrinter;
|
|
11
|
+
//# sourceMappingURL=graphql-resource-source-printer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-resource-source-printer.js","sourceRoot":"","sources":["../../../../src/codegen/graphql/source-printer/graphql-resource-source-printer.ts"],"names":[],"mappings":";;;AAIA,MAAa,4BAA4B;IACrC,QAAQ,CACJ,WAA4B,EAC5B,SAAiC;QAEjC,0CAA0C;QAC1C,OAAO,EAAE,CAAC;IACd,CAAC;CACJ;AARD,oEAQC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { SourcePrinter, GraphQLTypePrinter, GraphQLResourcePrinter, GraphQLAdapterPrinter } from '../../../interfaces';
|
|
3
|
+
import type { ModelInfo } from '../../../main';
|
|
4
|
+
import type { LuvioGraphQLDSL } from '../graphql-dsl';
|
|
5
|
+
import type path from 'path';
|
|
6
|
+
export interface GraphQLCodegenMetadata {
|
|
7
|
+
scalarToPrimitiveMap: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export declare class GraphQLSourcePrinter implements SourcePrinter {
|
|
10
|
+
private typePrinter;
|
|
11
|
+
private resourcePrinter;
|
|
12
|
+
private adapterPrinter;
|
|
13
|
+
private compilerBaseOutputDir;
|
|
14
|
+
constructor(typePrinter: GraphQLTypePrinter, resourcePrinter: GraphQLResourcePrinter, adapterPrinter: GraphQLAdapterPrinter, compilerBaseOutputDir: path.ParsedPath);
|
|
15
|
+
generateModules(modelInfo: ModelInfo): {
|
|
16
|
+
[path: string]: string;
|
|
17
|
+
};
|
|
18
|
+
calculateMetadata(graphqlDsl: LuvioGraphQLDSL): GraphQLCodegenMetadata;
|
|
19
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLSourcePrinter = void 0;
|
|
4
|
+
const DEFAULT_GRAPHQL_SCALAR_TO_PRIMITIVE_MAP = {
|
|
5
|
+
String: 'string',
|
|
6
|
+
ID: 'string',
|
|
7
|
+
Boolean: 'boolean',
|
|
8
|
+
Int: 'number',
|
|
9
|
+
Float: 'number',
|
|
10
|
+
};
|
|
11
|
+
class GraphQLSourcePrinter {
|
|
12
|
+
constructor(typePrinter, resourcePrinter, adapterPrinter, compilerBaseOutputDir) {
|
|
13
|
+
this.typePrinter = typePrinter;
|
|
14
|
+
this.resourcePrinter = resourcePrinter;
|
|
15
|
+
this.adapterPrinter = adapterPrinter;
|
|
16
|
+
this.compilerBaseOutputDir = compilerBaseOutputDir;
|
|
17
|
+
}
|
|
18
|
+
generateModules(modelInfo) {
|
|
19
|
+
const { resources } = modelInfo;
|
|
20
|
+
let modules = {};
|
|
21
|
+
for (const resource of resources) {
|
|
22
|
+
if (resource.resourceType === 'GraphQL') {
|
|
23
|
+
const { graphqlDsl } = resource.graphqlRepresentation;
|
|
24
|
+
const metadata = this.calculateMetadata(graphqlDsl);
|
|
25
|
+
modules = {
|
|
26
|
+
...this.typePrinter.generate(graphqlDsl, this.compilerBaseOutputDir, metadata),
|
|
27
|
+
...this.resourcePrinter.generate(graphqlDsl, metadata),
|
|
28
|
+
...this.adapterPrinter.generate(graphqlDsl, metadata),
|
|
29
|
+
...modules,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return modules;
|
|
34
|
+
}
|
|
35
|
+
calculateMetadata(graphqlDsl) {
|
|
36
|
+
const scalarToPrimitiveMap = DEFAULT_GRAPHQL_SCALAR_TO_PRIMITIVE_MAP;
|
|
37
|
+
graphqlDsl.customScalars.forEach((custom) => (scalarToPrimitiveMap[custom.name] = 'unknown'));
|
|
38
|
+
return {
|
|
39
|
+
scalarToPrimitiveMap,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.GraphQLSourcePrinter = GraphQLSourcePrinter;
|
|
44
|
+
//# sourceMappingURL=graphql-source-printer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-source-printer.js","sourceRoot":"","sources":["../../../../src/codegen/graphql/source-printer/graphql-source-printer.ts"],"names":[],"mappings":";;;AAUA,MAAM,uCAAuC,GAA2B;IACpE,MAAM,EAAE,QAAQ;IAChB,EAAE,EAAE,QAAQ;IACZ,OAAO,EAAE,SAAS;IAClB,GAAG,EAAE,QAAQ;IACb,KAAK,EAAE,QAAQ;CAClB,CAAC;AAOF,MAAa,oBAAoB;IAC7B,YACY,WAA+B,EAC/B,eAAuC,EACvC,cAAqC,EACrC,qBAAsC;QAHtC,gBAAW,GAAX,WAAW,CAAoB;QAC/B,oBAAe,GAAf,eAAe,CAAwB;QACvC,mBAAc,GAAd,cAAc,CAAuB;QACrC,0BAAqB,GAArB,qBAAqB,CAAiB;IAC/C,CAAC;IAEJ,eAAe,CAAC,SAAoB;QAChC,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;QAChC,IAAI,OAAO,GAA2B,EAAE,CAAC;QAEzC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;YAC9B,IAAI,QAAQ,CAAC,YAAY,KAAK,SAAS,EAAE;gBACrC,MAAM,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC,qBAAqB,CAAC;gBACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;gBACpD,OAAO,GAAG;oBACN,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,CAAC;oBAC9E,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC;oBACtD,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC;oBACrD,GAAG,OAAO;iBACb,CAAC;aACL;SACJ;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,iBAAiB,CAAC,UAA2B;QACzC,MAAM,oBAAoB,GAAG,uCAAuC,CAAC;QAErE,UAAU,CAAC,aAAa,CAAC,OAAO,CAC5B,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAC9D,CAAC;QAEF,OAAO;YACH,oBAAoB;SACvB,CAAC;IACN,CAAC;CACJ;AAtCD,oDAsCC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { GraphQLTypePrinter } from '../../../interfaces';
|
|
3
|
+
import type { ImportContext } from '../../../utils/imports';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import type { LuvioGraphQLDSL } from '../graphql-dsl';
|
|
6
|
+
import type { GraphQLCodegenMetadata } from './graphql-source-printer';
|
|
7
|
+
export declare const GRAPHQL_OUTPUT_DIRECTORY = "graphql";
|
|
8
|
+
export declare const GRAPHQL_OBJECT_TYPENAME = "typeName";
|
|
9
|
+
export declare type GraphQLTypeGenerationResult = Record<string, string>;
|
|
10
|
+
export declare class GraphQLTypeSourcePrinter implements GraphQLTypePrinter {
|
|
11
|
+
generate(graphqlDsl: LuvioGraphQLDSL, compilerBaseOutputDir: path.ParsedPath, metadata: GraphQLCodegenMetadata): GraphQLTypeGenerationResult;
|
|
12
|
+
createGraphQLTypeImportContext(compilerBaseOutputDir: path.ParsedPath, defName: string): {
|
|
13
|
+
relPath: string;
|
|
14
|
+
importContext: ImportContext;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GraphQLTypeSourcePrinter = exports.GRAPHQL_OBJECT_TYPENAME = exports.GRAPHQL_OUTPUT_DIRECTORY = void 0;
|
|
7
|
+
const imports_1 = require("../../../utils/imports");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const graphql_parser_1 = require("@luvio/graphql-parser");
|
|
10
|
+
const type_1 = require("../type");
|
|
11
|
+
const union_1 = require("../union");
|
|
12
|
+
const enum_1 = require("../enum");
|
|
13
|
+
exports.GRAPHQL_OUTPUT_DIRECTORY = 'graphql';
|
|
14
|
+
exports.GRAPHQL_OBJECT_TYPENAME = 'typeName';
|
|
15
|
+
const GRAPHQL_TYPES_DIRECTORY = 'types';
|
|
16
|
+
class GraphQLTypeSourcePrinter {
|
|
17
|
+
generate(graphqlDsl, compilerBaseOutputDir, metadata) {
|
|
18
|
+
const typeKeys = Object.keys(graphqlDsl.schema.getTypeMap());
|
|
19
|
+
const modules = {};
|
|
20
|
+
const { relPath } = this.createGraphQLTypeImportContext(compilerBaseOutputDir, 'type-util');
|
|
21
|
+
const typeUtil = (0, type_1.generateTypeUtil)();
|
|
22
|
+
modules[relPath] = typeUtil;
|
|
23
|
+
typeKeys.forEach((typeKey) => {
|
|
24
|
+
const typeDefinition = graphqlDsl.schema.getType(typeKey);
|
|
25
|
+
if (typeDefinition !== undefined &&
|
|
26
|
+
typeDefinition !== null &&
|
|
27
|
+
typeDefinition.astNode !== undefined &&
|
|
28
|
+
typeDefinition.astNode !== null) {
|
|
29
|
+
const kind = typeDefinition.astNode.kind;
|
|
30
|
+
const { relPath, importContext } = this.createGraphQLTypeImportContext(compilerBaseOutputDir, typeDefinition.name);
|
|
31
|
+
switch (kind) {
|
|
32
|
+
case graphql_parser_1.Kind.OBJECT_TYPE_DEFINITION:
|
|
33
|
+
case graphql_parser_1.Kind.INTERFACE_TYPE_DEFINITION:
|
|
34
|
+
modules[relPath] = (0, type_1.generateType)(graphqlDsl, typeDefinition.name, typeDefinition.astNode, importContext, metadata);
|
|
35
|
+
break;
|
|
36
|
+
case graphql_parser_1.Kind.UNION_TYPE_DEFINITION:
|
|
37
|
+
modules[relPath] = (0, union_1.generate)(typeDefinition.name, typeDefinition.astNode, importContext, metadata);
|
|
38
|
+
break;
|
|
39
|
+
case graphql_parser_1.Kind.ENUM_TYPE_DEFINITION:
|
|
40
|
+
modules[relPath] = (0, enum_1.generate)(typeDefinition.name, typeDefinition.astNode, importContext, metadata);
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
// not supported
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return modules;
|
|
49
|
+
}
|
|
50
|
+
createGraphQLTypeImportContext(compilerBaseOutputDir, defName) {
|
|
51
|
+
const graphqlRelPath = path_1.default.join(exports.GRAPHQL_OUTPUT_DIRECTORY, GRAPHQL_TYPES_DIRECTORY, `${defName}.ts`);
|
|
52
|
+
const shapeAbsPath = path_1.default.parse(path_1.default.resolve(path_1.default.format(compilerBaseOutputDir), graphqlRelPath));
|
|
53
|
+
return {
|
|
54
|
+
relPath: graphqlRelPath,
|
|
55
|
+
importContext: (0, imports_1.createImportContext)(shapeAbsPath, compilerBaseOutputDir),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.GraphQLTypeSourcePrinter = GraphQLTypeSourcePrinter;
|
|
60
|
+
//# sourceMappingURL=graphql-type-source-printer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-type-source-printer.js","sourceRoot":"","sources":["../../../../src/codegen/graphql/source-printer/graphql-type-source-printer.ts"],"names":[],"mappings":";;;;;;AAEA,oDAA6D;AAC7D,gDAAwB;AACxB,0DAA6C;AAE7C,kCAAyD;AACzD,oCAAyD;AACzD,kCAAuD;AAG1C,QAAA,wBAAwB,GAAG,SAAS,CAAC;AACrC,QAAA,uBAAuB,GAAG,UAAU,CAAC;AAClD,MAAM,uBAAuB,GAAG,OAAO,CAAC;AAIxC,MAAa,wBAAwB;IACjC,QAAQ,CACJ,UAA2B,EAC3B,qBAAsC,EACtC,QAAgC;QAEhC,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAC7D,MAAM,OAAO,GAAgC,EAAE,CAAC;QAEhD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,8BAA8B,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC;QAC5F,MAAM,QAAQ,GAAW,IAAA,uBAAgB,GAAE,CAAC;QAC5C,OAAO,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC;QAE5B,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YACzB,MAAM,cAAc,GAAG,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC1D,IACI,cAAc,KAAK,SAAS;gBAC5B,cAAc,KAAK,IAAI;gBACvB,cAAc,CAAC,OAAO,KAAK,SAA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C,CACnE,CAAC;QACF,OAAO;YACH,OAAO,EAAE,cAAc;YACvB,aAAa,EAAE,IAAA,6BAAmB,EAAC,YAAY,EAAE,qBAAqB,CAAC;SAC1E,CAAC;IACN,CAAC;CACJ;AAnFD,4DAmFC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GraphQLAdapterSourcePrinter } from './graphql-adapter-source-printer';
|
|
2
|
+
import { GraphQLResourceSourcePrinter } from './graphql-resource-source-printer';
|
|
3
|
+
import { GraphQLSourcePrinter } from './graphql-source-printer';
|
|
4
|
+
import { GraphQLTypeSourcePrinter } from './graphql-type-source-printer';
|
|
5
|
+
export { GraphQLSourcePrinter, GraphQLTypeSourcePrinter, GraphQLResourceSourcePrinter, GraphQLAdapterSourcePrinter, };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLAdapterSourcePrinter = exports.GraphQLResourceSourcePrinter = exports.GraphQLTypeSourcePrinter = exports.GraphQLSourcePrinter = void 0;
|
|
4
|
+
const graphql_adapter_source_printer_1 = require("./graphql-adapter-source-printer");
|
|
5
|
+
Object.defineProperty(exports, "GraphQLAdapterSourcePrinter", { enumerable: true, get: function () { return graphql_adapter_source_printer_1.GraphQLAdapterSourcePrinter; } });
|
|
6
|
+
const graphql_resource_source_printer_1 = require("./graphql-resource-source-printer");
|
|
7
|
+
Object.defineProperty(exports, "GraphQLResourceSourcePrinter", { enumerable: true, get: function () { return graphql_resource_source_printer_1.GraphQLResourceSourcePrinter; } });
|
|
8
|
+
const graphql_source_printer_1 = require("./graphql-source-printer");
|
|
9
|
+
Object.defineProperty(exports, "GraphQLSourcePrinter", { enumerable: true, get: function () { return graphql_source_printer_1.GraphQLSourcePrinter; } });
|
|
10
|
+
const graphql_type_source_printer_1 = require("./graphql-type-source-printer");
|
|
11
|
+
Object.defineProperty(exports, "GraphQLTypeSourcePrinter", { enumerable: true, get: function () { return graphql_type_source_printer_1.GraphQLTypeSourcePrinter; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/codegen/graphql/source-printer/index.ts"],"names":[],"mappings":";;;AAAA,qFAA+E;AAQ3E,4GARK,4DAA2B,OAQL;AAP/B,uFAAiF;AAM7E,6GANK,8DAA4B,OAML;AALhC,qEAAgE;AAG5D,qGAHK,6CAAoB,OAGL;AAFxB,+EAAyE;AAGrE,yGAHK,sDAAwB,OAGL"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const GRAPHQL_VARIABLES_IDENTIFIER = "GraphQLVariables";
|
|
2
|
+
export declare const GRAPHQL_STATE_INTERFACE_IDENTIFIER = "GraphQLState";
|
|
3
|
+
export declare const TIMESTAMP_IDENTIFIER = "timestamp";
|
|
4
|
+
export declare const CREATE_LINK_IDENTIFIER = "createLink";
|
|
5
|
+
export declare const TYPE_UTIL_IDENTIFIER = "type-util";
|
|
6
|
+
export declare const TYPE_INGEST_IDENTIFIER = "ingest";
|
|
7
|
+
export declare const KEY_BUILDER_IDENTIFIER = "keyBuilder";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KEY_BUILDER_IDENTIFIER = exports.TYPE_INGEST_IDENTIFIER = exports.TYPE_UTIL_IDENTIFIER = exports.CREATE_LINK_IDENTIFIER = exports.TIMESTAMP_IDENTIFIER = exports.GRAPHQL_STATE_INTERFACE_IDENTIFIER = exports.GRAPHQL_VARIABLES_IDENTIFIER = void 0;
|
|
4
|
+
exports.GRAPHQL_VARIABLES_IDENTIFIER = 'GraphQLVariables';
|
|
5
|
+
exports.GRAPHQL_STATE_INTERFACE_IDENTIFIER = 'GraphQLState';
|
|
6
|
+
exports.TIMESTAMP_IDENTIFIER = 'timestamp';
|
|
7
|
+
exports.CREATE_LINK_IDENTIFIER = 'createLink';
|
|
8
|
+
exports.TYPE_UTIL_IDENTIFIER = 'type-util';
|
|
9
|
+
exports.TYPE_INGEST_IDENTIFIER = 'ingest';
|
|
10
|
+
exports.KEY_BUILDER_IDENTIFIER = 'keyBuilder';
|
|
11
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/codegen/graphql/type/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,4BAA4B,GAAG,kBAAkB,CAAC;AAClD,QAAA,kCAAkC,GAAG,cAAc,CAAC;AACpD,QAAA,oBAAoB,GAAG,WAAW,CAAC;AACnC,QAAA,sBAAsB,GAAG,YAAY,CAAC;AACtC,QAAA,oBAAoB,GAAG,WAAW,CAAC;AACnC,QAAA,sBAAsB,GAAG,QAAQ,CAAC;AAClC,QAAA,sBAAsB,GAAG,YAAY,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FieldDefinitionNode, InterfaceTypeDefinitionNode, ListTypeNode, NamedTypeNode, ObjectTypeDefinitionNode, TypeNode } from '@luvio/graphql-parser';
|
|
2
|
+
import type { ImportContext } from '../../../utils/imports';
|
|
3
|
+
import type { NormalizableTypes } from '../utils';
|
|
4
|
+
import type { LuvioGraphQLDSL } from '../graphql-dsl';
|
|
5
|
+
export declare function ingestNamedType(field: FieldDefinitionNode, typeNode: NamedTypeNode, importContext: ImportContext, normalizableTypeMap: NormalizableTypes): string;
|
|
6
|
+
export declare function ingestListType(field: FieldDefinitionNode, typeNode: ListTypeNode, importContext: ImportContext, normalizableTypeMap: NormalizableTypes): string;
|
|
7
|
+
export declare function ingestType(field: FieldDefinitionNode, typeNode: TypeNode, importContext: ImportContext, normalizableTypeMap: NormalizableTypes): string;
|
|
8
|
+
export declare function generateIngestFromDef(graphqlDsl: LuvioGraphQLDSL, def: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode, importContext: ImportContext, normalizableTypeMap: NormalizableTypes): string;
|
|
9
|
+
export declare function generateIngest(graphqlDsl: LuvioGraphQLDSL, def: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode, importContext: ImportContext): string;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateIngest = exports.generateIngestFromDef = exports.ingestType = exports.ingestListType = exports.ingestNamedType = void 0;
|
|
7
|
+
const deindent_1 = __importDefault(require("../../../utils/deindent"));
|
|
8
|
+
const constants_1 = require("../../shared/constants");
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const constants_2 = require("./constants");
|
|
11
|
+
function ingestNamedType(field, typeNode, importContext, normalizableTypeMap) {
|
|
12
|
+
const typeName = (0, utils_1.resolveTypeName)(typeNode);
|
|
13
|
+
const { importGraphQLArtifact } = importContext;
|
|
14
|
+
// check for ingestable types - non-scalars
|
|
15
|
+
if (normalizableTypeMap[typeName] === undefined) {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
const typeNameIngestImport = importGraphQLArtifact(typeName, constants_2.TYPE_INGEST_IDENTIFIER);
|
|
19
|
+
return (0, deindent_1.default) `
|
|
20
|
+
if (data.${field.name.value} !== undefined && data.${field.name.value} !== null) {
|
|
21
|
+
data.${field.name.value} = ${typeNameIngestImport}({
|
|
22
|
+
...state,
|
|
23
|
+
path: {
|
|
24
|
+
parent: null,
|
|
25
|
+
propertyName: '${field.name.value}',
|
|
26
|
+
fullPath: key + '__${field.name.value}'
|
|
27
|
+
},
|
|
28
|
+
data: data.${field.name.value},
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
`;
|
|
32
|
+
}
|
|
33
|
+
exports.ingestNamedType = ingestNamedType;
|
|
34
|
+
function ingestListType(field, typeNode, importContext, normalizableTypeMap) {
|
|
35
|
+
const { importGraphQLArtifact } = importContext;
|
|
36
|
+
const fieldName = field.name.value;
|
|
37
|
+
const typeName = (0, utils_1.resolveTypeName)(typeNode);
|
|
38
|
+
const fullPathIdentifier = `fullPath__${fieldName}`;
|
|
39
|
+
const typeDefinition = normalizableTypeMap[typeName];
|
|
40
|
+
const dataIdentifier = `data.${fieldName}`;
|
|
41
|
+
const collectionIdentifier = `${fieldName}__items`;
|
|
42
|
+
// Non-normalizable types
|
|
43
|
+
if (typeDefinition === undefined) {
|
|
44
|
+
return (0, deindent_1.default) `
|
|
45
|
+
if (${dataIdentifier} !== undefined && ${dataIdentifier} !== null) {
|
|
46
|
+
const ${fullPathIdentifier} = key + '__${fieldName}';
|
|
47
|
+
store.publish(${fullPathIdentifier}, ${dataIdentifier})
|
|
48
|
+
${dataIdentifier} = {
|
|
49
|
+
__ref: ${fullPathIdentifier}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
`;
|
|
53
|
+
}
|
|
54
|
+
const typeNameIngestImport = importGraphQLArtifact(typeName, constants_2.TYPE_INGEST_IDENTIFIER);
|
|
55
|
+
return (0, deindent_1.default) `
|
|
56
|
+
if(${dataIdentifier} !== undefined && ${dataIdentifier} !== null) {
|
|
57
|
+
const ${collectionIdentifier}: ${constants_1.LUVIO_STORE_LINK_IMPORT}[] = [];
|
|
58
|
+
const ${fullPathIdentifier} = key + '__${fieldName}';
|
|
59
|
+
for(let i = 0, len = ${dataIdentifier}.length; i < len; i++) {
|
|
60
|
+
const item = ${dataIdentifier}[i];
|
|
61
|
+
// add TTL Info
|
|
62
|
+
${collectionIdentifier}[i] = ${typeNameIngestImport}({
|
|
63
|
+
...state,
|
|
64
|
+
path: {
|
|
65
|
+
parent: null,
|
|
66
|
+
propertyName: i,
|
|
67
|
+
fullPath: ${fullPathIdentifier} + i
|
|
68
|
+
},
|
|
69
|
+
data: item,
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
${constants_1.LUVIO_STORE_IDENTIFIER}.publish(${fullPathIdentifier}, ${collectionIdentifier})
|
|
73
|
+
${dataIdentifier} = {
|
|
74
|
+
__ref: ${fullPathIdentifier}
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
`;
|
|
78
|
+
}
|
|
79
|
+
exports.ingestListType = ingestListType;
|
|
80
|
+
function ingestType(field, typeNode, importContext, normalizableTypeMap) {
|
|
81
|
+
if (field === undefined) {
|
|
82
|
+
return '';
|
|
83
|
+
}
|
|
84
|
+
switch (typeNode.kind) {
|
|
85
|
+
case 'NamedType':
|
|
86
|
+
return ingestNamedType(field, typeNode, importContext, normalizableTypeMap);
|
|
87
|
+
case 'ListType':
|
|
88
|
+
return ingestListType(field, typeNode, importContext, normalizableTypeMap);
|
|
89
|
+
default:
|
|
90
|
+
return ingestType(field, typeNode.type, importContext, normalizableTypeMap);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.ingestType = ingestType;
|
|
94
|
+
function generateIngestFromDef(graphqlDsl, def, importContext, normalizableTypeMap) {
|
|
95
|
+
const { schema } = graphqlDsl;
|
|
96
|
+
const type = schema.getType(def.name.value);
|
|
97
|
+
const fieldMap = type.getFields();
|
|
98
|
+
const fieldList = Object.keys(fieldMap);
|
|
99
|
+
const statements = fieldList.map((fieldName) => {
|
|
100
|
+
var _a, _b;
|
|
101
|
+
const field = fieldMap[fieldName];
|
|
102
|
+
if (((_a = field.astNode) === null || _a === void 0 ? void 0 : _a.type) === undefined) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
return ingestType(field.astNode, (_b = field.astNode) === null || _b === void 0 ? void 0 : _b.type, importContext, normalizableTypeMap);
|
|
106
|
+
});
|
|
107
|
+
return statements.filter((statement) => statement !== '').join('\n');
|
|
108
|
+
}
|
|
109
|
+
exports.generateIngestFromDef = generateIngestFromDef;
|
|
110
|
+
function generateIngest(graphqlDsl, def, importContext) {
|
|
111
|
+
const { schema } = graphqlDsl;
|
|
112
|
+
const { importGraphQLArtifact } = importContext;
|
|
113
|
+
const normalizableTypeMap = (0, utils_1.getNormalizableTypeMap)(schema);
|
|
114
|
+
const createLink = importGraphQLArtifact(constants_2.TYPE_UTIL_IDENTIFIER, constants_2.CREATE_LINK_IDENTIFIER);
|
|
115
|
+
const graphQLStateInterface = importGraphQLArtifact(constants_2.TYPE_UTIL_IDENTIFIER, constants_2.GRAPHQL_STATE_INTERFACE_IDENTIFIER);
|
|
116
|
+
return (0, deindent_1.default) `
|
|
117
|
+
export function ingest<D>(state: ${graphQLStateInterface}<D>) {
|
|
118
|
+
const { path, ${constants_1.LUVIO_STORE_IDENTIFIER} } = state;
|
|
119
|
+
const data: any = state.data;
|
|
120
|
+
const key = ${constants_2.KEY_BUILDER_IDENTIFIER}(path, data as any);
|
|
121
|
+
// normalize
|
|
122
|
+
${generateIngestFromDef(graphqlDsl, def, importContext, normalizableTypeMap)};
|
|
123
|
+
|
|
124
|
+
// publish
|
|
125
|
+
${constants_1.LUVIO_STORE_IDENTIFIER}.publish(key, data);
|
|
126
|
+
return ${createLink}(key);
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
}
|
|
130
|
+
exports.generateIngest = generateIngest;
|
|
131
|
+
//# sourceMappingURL=ingest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest.js","sourceRoot":"","sources":["../../../../src/codegen/graphql/type/ingest.ts"],"names":[],"mappings":";;;;;;AASA,uEAA+C;AAE/C,sDAAyF;AAEzF,oCAAmE;AACnE,2CAMqB;AAGrB,SAAgB,eAAe,CAC3B,KAA0B,EAC1B,QAAuB,EACvB,aAA4B,EAC5B,mBAAsC;IAEtC,MAAM,QAAQ,GAAG,IAAA,uBAAe,EAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,EAAE,qBAAqB,EAAE,GAAG,aAAa,CAAC;IAChD,2CAA2C;IAC3C,IAAI,mBAAmB,CAAC,QAAQ,CAAC,K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,CAAC,SAAS,CAAC,CAAC;QAElC,IAAI,CAAA,MAAA,KAAK,CAAC,OAAO,0CAAE,IAAI,MAAK,SAAS,EAAE;YACnC,OAAO;SACV;QACD,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,MAAA,KAAK,CAAC,OAAO,0CAAE,IAAI,EAAE,aAAa,EAAE,mBAAmB,CAAC,CAAC;IAC9F,CAAC,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzE,CAAC;AAtBD,sDAsBC;AAED,SAAgB,cAAc,CAC1B,UAA2B,EAC3B,GAA2D,EAC3D,aAA4B;IAE5B,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;IAC9B,MAAM,EAAE,qBAAqB,EAAE,GAAG,aAAa,CAAC;IAChD,MAAM,mBAAmB,GAAG,IAAA,8BAAsB,EAAC,MAAM,CAAC,CAAC;IAC3D,MAAM,UAAU,GAAG,qBAAqB,CAAC,gCAAoB,EAAE,kCAAsB,CAAC,CAAC;IACvF,MAAM,qBAAqB,GAAG,qBAAqB,CAC/C,gCAAoB,EACpB,8CAAkC,CACrC,CAAC;IAEF,OAAO,IAAA,kBAAQ,EAAA;2CACwB,qBAAqB;4BACpC,kCAAsB;;0BAExB,kCAAsB;;cAElC,qBAAqB,CAAC,UAAU,EAAE,GAAG,EAAE,aAAa,EAAE,mBAAmB,CAAC;;;cAG1E,kCAAsB;qBACf,UAAU;;KAE1B,CAAC;AACN,CAAC;AA3BD,wCA2BC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { UnionTypeDefinitionNode } from '@luvio/graphql-parser';
|
|
2
|
+
import type { ImportContext } from '../../../utils/imports';
|
|
3
|
+
import type { GraphQLCodegenMetadata } from '../source-printer/graphql-source-printer';
|
|
4
|
+
export declare function generateInterface(name: string, def: UnionTypeDefinitionNode, importContext: ImportContext, metadata: GraphQLCodegenMetadata): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateInterface = void 0;
|
|
7
|
+
const deindent_1 = __importDefault(require("../../../utils/deindent"));
|
|
8
|
+
const interface_1 = require("../type/interface");
|
|
9
|
+
function generateInterface(name, def, importContext, metadata) {
|
|
10
|
+
return generateUnionDefinitionNode(name, def, importContext, metadata.scalarToPrimitiveMap);
|
|
11
|
+
}
|
|
12
|
+
exports.generateInterface = generateInterface;
|
|
13
|
+
function generateUnionDefinitionNode(name, def, importContext, scalarToPrimitiveMap) {
|
|
14
|
+
const { types } = def;
|
|
15
|
+
if (types === undefined) {
|
|
16
|
+
return (0, deindent_1.default) `
|
|
17
|
+
export type ${interface_1.TYPE_INTERFACE_IDENTIFIER} = never;
|
|
18
|
+
`;
|
|
19
|
+
}
|
|
20
|
+
const unions = types.map((type) => {
|
|
21
|
+
return (0, interface_1.generateTypeReference)(type, importContext, scalarToPrimitiveMap, {
|
|
22
|
+
required: true,
|
|
23
|
+
array: false,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
return (0, deindent_1.default) `
|
|
27
|
+
export type ${interface_1.TYPE_INTERFACE_IDENTIFIER} = ${unions.join(' | ')}
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../../src/codegen/graphql/union/interface.ts"],"names":[],"mappings":";;;;;;AACA,uEAA+C;AAG/C,iDAAqF;AAErF,SAAgB,iBAAiB,CAC7B,IAAY,EACZ,GAA4B,EAC5B,aAA4B,EAC5B,QAAgC;IAEhC,OAAO,2BAA2B,CAAC,IAAI,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ,CAAC,oBAAoB,CAAC,CAAC;AAChG,CAAC;AAPD,8CAOC;AAED,SAAS,2BAA2B,CAChC,IAAY,EACZ,GAA4B,EAC5B,aAA4B,EAC5B,oBAA4C;IAE5C,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IAEtB,IAAI,KAAK,KAAK,SAAS,EAAE;QACrB,OAAO,IAAA,kBAAQ,EAAA;0BACG,qCAAyB;SAC1C,CAAC;KACL;IAED,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC9B,OAAO,IAAA,iCAAqB,EAAC,IAAI,EAAE,aAAa,EAAE,oBAAoB,EAAE;YACpE,QAAQ,EAAE,IAAI;YACd,KAAK,EAAE,KAAK;SACf,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,OAAO,IAAA,kBAAQ,EAAA;sBACG,qCAAyB,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;KAClE,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { resolveTypeName, resolveFieldTypeName, getNormalizableTypeMap, NormalizableTypes, } from './types';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNormalizableTypeMap = exports.resolveFieldTypeName = exports.resolveTypeName = void 0;
|
|
4
|
+
var types_1 = require("./types");
|
|
5
|
+
Object.defineProperty(exports, "resolveTypeName", { enumerable: true, get: function () { return types_1.resolveTypeName; } });
|
|
6
|
+
Object.defineProperty(exports, "resolveFieldTypeName", { enumerable: true, get: function () { return types_1.resolveFieldTypeName; } });
|
|
7
|
+
Object.defineProperty(exports, "getNormalizableTypeMap", { enumerable: true, get: function () { return types_1.getNormalizableTypeMap; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/codegen/graphql/utils/index.ts"],"names":[],"mappings":";;;AAAA,iCAKiB;AAJb,wGAAA,eAAe,OAAA;AACf,6GAAA,oBAAoB,OAAA;AACpB,+GAAA,sBAAsB,OAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { GraphQLSchema, GraphQLInterfaceType, GraphQLObjectType, TypeNode } from '@luvio/graphql-parser';
|
|
2
|
+
export declare type NormalizableTypes = Record<string, GraphQLInterfaceType | GraphQLObjectType<any, any>>;
|
|
3
|
+
export declare function resolveTypeName(typeNode: TypeNode): string;
|
|
4
|
+
export declare function resolveFieldTypeName(schema: GraphQLSchema, field: any): string | null;
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param schema : GraphQLSchema
|
|
8
|
+
* @returns : NormalizableTypes Map
|
|
9
|
+
*/
|
|
10
|
+
export declare function getNormalizableTypeMap(schema: GraphQLSchema): NormalizableTypes;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNormalizableTypeMap = exports.resolveFieldTypeName = exports.resolveTypeName = void 0;
|
|
4
|
+
function resolveTypeName(typeNode) {
|
|
5
|
+
switch (typeNode.kind) {
|
|
6
|
+
case 'NamedType':
|
|
7
|
+
return typeNode.name.value;
|
|
8
|
+
default:
|
|
9
|
+
return resolveTypeName(typeNode.type);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.resolveTypeName = resolveTypeName;
|
|
13
|
+
function resolveFieldTypeName(schema, field) {
|
|
14
|
+
const typeName = resolveTypeName(field.astNode.type);
|
|
15
|
+
const type = schema.getType(typeName);
|
|
16
|
+
if (type === null || type === undefined) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return type.name;
|
|
20
|
+
}
|
|
21
|
+
exports.resolveFieldTypeName = resolveFieldTypeName;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param schema : GraphQLSchema
|
|
25
|
+
* @returns : NormalizableTypes Map
|
|
26
|
+
*/
|
|
27
|
+
function getNormalizableTypeMap(schema) {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
const typeMap = schema.getTypeMap();
|
|
30
|
+
const typeNames = Object.keys(typeMap);
|
|
31
|
+
const normalizableTypeMap = {};
|
|
32
|
+
for (const typeName of typeNames) {
|
|
33
|
+
const type = typeMap[typeName];
|
|
34
|
+
if (((_a = type.astNode) === null || _a === void 0 ? void 0 : _a.kind) === 'InterfaceTypeDefinition' ||
|
|
35
|
+
((_b = type.astNode) === null || _b === void 0 ? void 0 : _b.kind) === 'ObjectTypeDefinition') {
|
|
36
|
+
// Even though we are filtering the types based on kind
|
|
37
|
+
// TS still thinks we might be assigning other types like Scalar which aren't permitted
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
normalizableTypeMap[typeName] = type;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return normalizableTypeMap;
|
|
43
|
+
}
|
|
44
|
+
exports.getNormalizableTypeMap = getNormalizableTypeMap;
|
|
45
|
+
//# sourceMappingURL=types.js.map
|