apollo-conn-gen 0.1.1 → 0.1.3

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.
@@ -1,4 +1,4 @@
1
- import { Factory, Type } from './internal.js';
1
+ import { Factory, Type, T } from './internal.js';
2
2
  import { trace } from '../log/trace.js';
3
3
  export class Response extends Type {
4
4
  schema;
@@ -38,8 +38,16 @@ export class Response extends Type {
38
38
  }
39
39
  select(context, writer, selection) {
40
40
  trace(context, '-> [res:select]', `-> in: ${this.parent.name}`);
41
- if (this.response) {
42
- this.response.select(context, writer, selection);
41
+ const response = this.response;
42
+ if (response) {
43
+ if (T.isScalar(response)) {
44
+ // best attempt to just copy the value that comes out of the service. most likely the
45
+ // value will have to be replaced by a GQL type. In fact, we could potentially use SYN_ here but
46
+ // it will have to do for now.
47
+ writer.append(' '.repeat(context.indent)).append('$\n');
48
+ }
49
+ else
50
+ response.select(context, writer, selection);
43
51
  }
44
52
  trace(context, '<- [res:select]', `-> out: ${this.parent.name}`);
45
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/oas/nodes/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,IAAI,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAIxC,MAAM,OAAO,QAAS,SAAQ,IAAI;IACzB,MAAM,CAAe;IACrB,QAAQ,CAAS;IAExB,YAAY,MAAa,EAAE,IAAY,EAAE,MAAoB,EAAE,QAAgB;QAC7E,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,OAAmB;Q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AAC;IAEM,MAAM,CAAC,OAAmB,EAAE,MAAc,EAAE,SAAmB;QACpE,KAAK,CAAC,OAAO,EAAE,iBAAiB,EAAE,UAAU,IAAI,CAAC,MAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAEjE,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QACnD,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,iBAAiB,EAAE,WAAW,IAAI,CAAC,MAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACpE,CAAC;CACF","sourcesContent":["import { Factory, IType, Type } from './internal.js';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\n\nexport class Response extends Type {\n public schema: SchemaObject;\n public response?: IType;\n\n constructor(parent: IType, name: string, schema: SchemaObject, response?: IType) {\n super(parent, name);\n this.schema = schema;\n this.response = response;\n }\n\n get id(): string {\n return 'res:' + this.name;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n trace(context, '-> [res:visit]', this.name + ' already visited.');\n return;\n }\n\n context.enter(this);\n trace(context, '-> [res:visit]', 'in ' + this.name);\n\n this.response = Factory.fromSchema(this, this.schema);\n trace(context, ' [res:visit]', 'array type: ' + this.response.id);\n this.visited = true;\n\n trace(context, '<- [res:visit]', 'out ' + this.name);\n context.leave(this);\n }\n\n public forPrompt(context: OasContext): string {\n return 'Response';\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n context.enter(this);\n trace(context, '-> [res:generate]', `-> in: ${this.parent!.name}`);\n\n if (this.response) {\n this.response.generate(context, writer, selection);\n }\n\n trace(context, '<- [res:generate]', `-> out: ${this.parent!.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]): void {\n trace(context, '-> [res:select]', `-> in: ${this.parent!.name}`);\n\n if (this.response) {\n this.response.select(context, writer, selection);\n }\n\n trace(context, '<- [res:select]', `-> out: ${this.parent!.name}`);\n }\n}\n"]}
1
+ {"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/oas/nodes/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,IAAI,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAIxC,MAAM,OAAO,QAAS,SAAQ,IAAI;IACzB,MAAM,CAAe;IACrB,QAAQ,CAAS;IAExB,YAAY,MAAa,EAAE,IAAY,EAAE,MAAoB,EAAE,QAAgB;QAC7E,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,OAAmB;QAC9B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC,CAAC;YAClE,OAAO;QACT,CAAC;QAED,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpB,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACtD,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACpE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QAEpB,KAAK,CAAC,OAAO,EAAE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QACrD,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,iBAAiB,EAAE,WAAW,IAAI,CAAC,MAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACpE,CAAC;CACF","sourcesContent":["import { Factory, IType, Type, T } from './internal.js';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\n\nexport class Response extends Type {\n public schema: SchemaObject;\n public response?: IType;\n\n constructor(parent: IType, name: string, schema: SchemaObject, response?: IType) {\n super(parent, name);\n this.schema = schema;\n this.response = response;\n }\n\n get id(): string {\n return 'res:' + this.name;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n trace(context, '-> [res:visit]', this.name + ' already visited.');\n return;\n }\n\n context.enter(this);\n trace(context, '-> [res:visit]', 'in ' + this.name);\n\n this.response = Factory.fromSchema(this, this.schema);\n trace(context, ' [res:visit]', 'array type: ' + this.response.id);\n this.visited = true;\n\n trace(context, '<- [res:visit]', 'out ' + this.name);\n context.leave(this);\n }\n\n public forPrompt(context: OasContext): string {\n return 'Response';\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n context.enter(this);\n trace(context, '-> [res:generate]', `-> in: ${this.parent!.name}`);\n\n if (this.response) {\n this.response.generate(context, writer, selection);\n }\n\n trace(context, '<- [res:generate]', `-> out: ${this.parent!.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]): void {\n trace(context, '-> [res:select]', `-> in: ${this.parent!.name}`);\n\n const response = this.response;\n if (response) {\n if (T.isScalar(response)) {\n // best attempt to just copy the value that comes out of the service. most likely the\n // value will have to be replaced by a GQL type. In fact, we could potentially use SYN_ here but\n // it will have to do for now.\n writer.append(' '.repeat(context.indent)).append('$\\n');\n } else response.select(context, writer, selection);\n }\n\n trace(context, '<- [res:select]', `-> out: ${this.parent!.name}`);\n }\n}\n"]}
@@ -4,4 +4,5 @@ export declare class T {
4
4
  static isPropScalar(type: IType): boolean;
5
5
  static traverse(node: IType, callback: (node: IType) => void): void;
6
6
  static isMutationType(type: IType): boolean;
7
+ static isScalar(type: IType): boolean;
7
8
  }
@@ -1,8 +1,9 @@
1
- import { CircularRef, En, Obj, PropArray, PropScalar } from './internal.js';
1
+ import { CircularRef, En, Obj, PropArray, PropScalar, Scalar } from './internal.js';
2
2
  import _ from 'lodash';
3
3
  export class T {
4
4
  static isLeaf(type) {
5
- return (type instanceof PropScalar ||
5
+ return (type instanceof Scalar ||
6
+ type instanceof PropScalar ||
6
7
  type instanceof En ||
7
8
  type instanceof CircularRef ||
8
9
  (type instanceof PropArray && type.items instanceof PropScalar) ||
@@ -26,5 +27,8 @@ export class T {
26
27
  type.id.startsWith('patch:') ||
27
28
  type.id.startsWith('del:'));
28
29
  }
30
+ static isScalar(type) {
31
+ return type.id.startsWith('scalar:');
32
+ }
29
33
  }
30
34
  //# sourceMappingURL=typeUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typeUtils.js","sourceRoot":"","sources":["../../../src/oas/nodes/typeUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG5E,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,MAAM,OAAO,CAAC;IACL,MAAM,CAAC,MAAM,CAAC,IAAW;QAC9B,OAAO,CACL,IAAI,YAAY,UAAU;YAC1B,IAAI,YAAY,EAAE;YAClB,IAAI,YAAY,WAAW;YAC3B,CAAC,IAAI,YAAY,SAAS,IAAI,IAAI,CAAC,KAAK,YAAY,UAAU,CAAC;YAC/D,CAAC,IAAI,YAAY,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAC/C,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,IAAW;QACpC,OAAO,IAAI,YAAY,UAAU,CAAC;IACpC,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,IAAW,EAAE,QAA+B;QACjE,MAAM,YAAY,GAAG,CAAC,CAAQ,EAAQ,EAAE;YACtC,QAAQ,CAAC,CAAC,CAAC,CAAC;YAEZ,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;gBAC3B,YAAY,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;QACH,CAAC,CAAC;QAEF,YAAY,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,IAAW;QAC/B,OAAO,CACL,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;YAC3B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;YAC1B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;YAC5B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAC3B,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { CircularRef, En, Obj, PropArray, PropScalar } from './internal.js';\n\nimport { IType } from './internal.js';\nimport _ from 'lodash';\n\nexport class T {\n public static isLeaf(type: IType): boolean {\n return (\n type instanceof PropScalar ||\n type instanceof En ||\n type instanceof CircularRef ||\n (type instanceof PropArray && type.items instanceof PropScalar) ||\n (type instanceof Obj && _.isEmpty(type.props))\n );\n }\n\n public static isPropScalar(type: IType): boolean {\n return type instanceof PropScalar;\n }\n\n public static traverse(node: IType, callback: (node: IType) => void): void {\n const traverseNode = (n: IType): void => {\n callback(n);\n\n for (const c of n.children) {\n traverseNode(c);\n }\n };\n\n traverseNode(node);\n }\n\n static isMutationType(type: IType): boolean {\n return (\n type.id.startsWith('post:') ||\n type.id.startsWith('put:') ||\n type.id.startsWith('patch:') ||\n type.id.startsWith('del:')\n );\n }\n}\n"]}
1
+ {"version":3,"file":"typeUtils.js","sourceRoot":"","sources":["../../../src/oas/nodes/typeUtils.ts"],"names":[],"mappings":"AAAA,OAAO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OAAO,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { CircularRef, En, Obj, PropArray, PropScalar, Scalar } from './internal.js';\n\nimport { IType } from './internal.js';\nimport _ from 'lodash';\n\nexport class T {\n public static isLeaf(type: IType): boolean {\n return (\n type instanceof Scalar ||\n type instanceof PropScalar ||\n type instanceof En ||\n type instanceof CircularRef ||\n (type instanceof PropArray && type.items instanceof PropScalar) ||\n (type instanceof Obj && _.isEmpty(type.props))\n );\n }\n\n public static isPropScalar(type: IType): boolean {\n return type instanceof PropScalar;\n }\n\n public static traverse(node: IType, callback: (node: IType) => void): void {\n const traverseNode = (n: IType): void => {\n callback(n);\n\n for (const c of n.children) {\n traverseNode(c);\n }\n };\n\n traverseNode(node);\n }\n\n static isMutationType(type: IType): boolean {\n return (\n type.id.startsWith('post:') ||\n type.id.startsWith('put:') ||\n type.id.startsWith('patch:') ||\n type.id.startsWith('del:')\n );\n }\n\n static isScalar(type: IType): boolean {\n return type.id.startsWith('scalar:');\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apollo-conn-gen",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Library to generate Apollo connector schemas from OpenAPI specs or JSON payloads. Also includes a CLI to generate connectors from the command line.",
5
5
  "author": "Fernando @ Apollo",
6
6
  "license": "MIT",