@graphql-codegen/kotlin 2.2.15 → 2.3.0-alpha-29eb1293b.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/cjs/config.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.plugin = void 0;
4
+ const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
5
+ const visitor_js_1 = require("./visitor.js");
6
+ const java_common_1 = require("@graphql-codegen/java-common");
7
+ const path_1 = require("path");
8
+ const plugin = async (schema, documents, config, { outputFile }) => {
9
+ const relevantPath = (0, path_1.dirname)((0, path_1.normalize)(outputFile));
10
+ const defaultPackageName = (0, java_common_1.buildPackageNameFromPath)(relevantPath);
11
+ const visitor = new visitor_js_1.KotlinResolversVisitor(config, schema, defaultPackageName);
12
+ const astNode = (0, plugin_helpers_1.getCachedDocumentNodeFromSchema)(schema);
13
+ const visitorResult = (0, plugin_helpers_1.oldVisit)(astNode, { leave: visitor });
14
+ const packageName = visitor.getPackageName();
15
+ const blockContent = visitorResult.definitions.filter(d => typeof d === 'string').join('\n\n');
16
+ return [packageName, blockContent].join('\n');
17
+ };
18
+ exports.plugin = plugin;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,28 +1,24 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const pluginHelpers = require('@graphql-codegen/plugin-helpers');
6
- const visitorPluginCommon = require('@graphql-codegen/visitor-plugin-common');
7
- const graphql = require('graphql');
8
- const javaCommon = require('@graphql-codegen/java-common');
9
- const path = require('path');
10
-
11
- const KOTLIN_SCALARS = {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KotlinResolversVisitor = exports.KOTLIN_SCALARS = void 0;
4
+ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
5
+ const graphql_1 = require("graphql");
6
+ const java_common_1 = require("@graphql-codegen/java-common");
7
+ exports.KOTLIN_SCALARS = {
12
8
  ID: 'Any',
13
9
  String: 'String',
14
10
  Boolean: 'Boolean',
15
11
  Int: 'Int',
16
12
  Float: 'Float',
17
13
  };
18
- class KotlinResolversVisitor extends visitorPluginCommon.BaseVisitor {
14
+ class KotlinResolversVisitor extends visitor_plugin_common_1.BaseVisitor {
19
15
  constructor(rawConfig, _schema, defaultPackageName) {
20
16
  super(rawConfig, {
21
17
  enumValues: rawConfig.enumValues || {},
22
18
  listType: rawConfig.listType || 'Iterable',
23
19
  withTypes: rawConfig.withTypes || false,
24
20
  package: rawConfig.package || defaultPackageName,
25
- scalars: visitorPluginCommon.buildScalarsFromConfig(_schema, rawConfig, KOTLIN_SCALARS),
21
+ scalars: (0, visitor_plugin_common_1.buildScalarsFromConfig)(_schema, rawConfig, exports.KOTLIN_SCALARS),
26
22
  omitJvmStatic: rawConfig.omitJvmStatic || false,
27
23
  });
28
24
  this._schema = _schema;
@@ -40,13 +36,13 @@ class KotlinResolversVisitor extends visitorPluginCommon.BaseVisitor {
40
36
  }
41
37
  EnumValueDefinition(node) {
42
38
  return (enumName) => {
43
- return visitorPluginCommon.indent(`${this.convertName(node, { useTypesPrefix: false, transformUnderscore: true })}("${this.getEnumValue(enumName, node.name.value)}")`);
39
+ return (0, visitor_plugin_common_1.indent)(`${this.convertName(node, { useTypesPrefix: false, transformUnderscore: true })}("${this.getEnumValue(enumName, node.name.value)}")`);
44
40
  };
45
41
  }
46
42
  EnumTypeDefinition(node) {
47
- const comment = visitorPluginCommon.transformComment(node.description, 0);
43
+ const comment = (0, visitor_plugin_common_1.transformComment)(node.description, 0);
48
44
  const enumName = this.convertName(node.name);
49
- const enumValues = visitorPluginCommon.indentMultiline(node.values.map(enumValue => enumValue(node.name.value)).join(',\n') + ';', 2);
45
+ const enumValues = (0, visitor_plugin_common_1.indentMultiline)(node.values.map(enumValue => enumValue(node.name.value)).join(',\n') + ';', 2);
50
46
  return `${comment}enum class ${enumName}(val label: String) {
51
47
  ${enumValues}
52
48
 
@@ -59,13 +55,13 @@ ${enumValues}
59
55
  }`;
60
56
  }
61
57
  resolveInputFieldType(typeNode) {
62
- const innerType = visitorPluginCommon.getBaseTypeNode(typeNode);
58
+ const innerType = (0, visitor_plugin_common_1.getBaseTypeNode)(typeNode);
63
59
  const schemaType = this._schema.getType(innerType.name.value);
64
- const isArray = typeNode.kind === graphql.Kind.LIST_TYPE ||
65
- (typeNode.kind === graphql.Kind.NON_NULL_TYPE && typeNode.type.kind === graphql.Kind.LIST_TYPE);
60
+ const isArray = typeNode.kind === graphql_1.Kind.LIST_TYPE ||
61
+ (typeNode.kind === graphql_1.Kind.NON_NULL_TYPE && typeNode.type.kind === graphql_1.Kind.LIST_TYPE);
66
62
  let result = null;
67
- const nullable = typeNode.kind !== graphql.Kind.NON_NULL_TYPE;
68
- if (graphql.isScalarType(schemaType)) {
63
+ const nullable = typeNode.kind !== graphql_1.Kind.NON_NULL_TYPE;
64
+ if ((0, graphql_1.isScalarType)(schemaType)) {
69
65
  if (this.config.scalars[schemaType.name]) {
70
66
  result = {
71
67
  baseType: this.scalars[schemaType.name],
@@ -79,7 +75,7 @@ ${enumValues}
79
75
  result = { isArray, baseType: 'Any', typeName: 'Any', isScalar: true, nullable };
80
76
  }
81
77
  }
82
- else if (graphql.isInputObjectType(schemaType)) {
78
+ else if ((0, graphql_1.isInputObjectType)(schemaType)) {
83
79
  const convertedName = this.convertName(schemaType.name);
84
80
  const typeName = convertedName.endsWith('Input') ? convertedName : `${convertedName}Input`;
85
81
  result = {
@@ -90,7 +86,7 @@ ${enumValues}
90
86
  nullable,
91
87
  };
92
88
  }
93
- else if (graphql.isEnumType(schemaType) || graphql.isObjectType(schemaType)) {
89
+ else if ((0, graphql_1.isEnumType)(schemaType) || (0, graphql_1.isObjectType)(schemaType)) {
94
90
  result = {
95
91
  isArray,
96
92
  baseType: this.convertName(schemaType.name),
@@ -103,7 +99,7 @@ ${enumValues}
103
99
  result = { isArray, baseType: 'Any', typeName: 'Any', isScalar: true, nullable };
104
100
  }
105
101
  if (result) {
106
- result.typeName = javaCommon.wrapTypeWithModifiers(result.typeName, typeNode, this.config.listType);
102
+ result.typeName = (0, java_common_1.wrapTypeWithModifiers)(result.typeName, typeNode, this.config.listType);
107
103
  }
108
104
  return result;
109
105
  }
@@ -113,7 +109,7 @@ ${enumValues}
113
109
  const typeToUse = this.resolveInputFieldType(arg.type);
114
110
  const initialValue = this.initialValue(typeToUse.typeName, arg.defaultValue);
115
111
  const initial = initialValue ? ` = ${initialValue}` : typeToUse.nullable ? ' = null' : '';
116
- return visitorPluginCommon.indent(`val ${arg.name.value}: ${typeToUse.typeName}${typeToUse.nullable ? '?' : ''}${initial}`, 2);
112
+ return (0, visitor_plugin_common_1.indent)(`val ${arg.name.value}: ${typeToUse.typeName}${typeToUse.nullable ? '?' : ''}${initial}`, 2);
117
113
  })
118
114
  .join(',\n');
119
115
  let suppress = '';
@@ -124,17 +120,17 @@ ${enumValues}
124
120
  const fallback = initialValue ? ` ?: ${initialValue}` : '';
125
121
  if (typeToUse.isArray && !typeToUse.isScalar) {
126
122
  suppress = '@Suppress("UNCHECKED_CAST")\n ';
127
- return visitorPluginCommon.indent(`args["${arg.name.value}"]${typeToUse.nullable || fallback ? '?' : '!!'}.let { ${arg.name.value} -> (${arg.name.value} as List<Map<String, Any>>).map { ${typeToUse.baseType}(it) } }${fallback}`, 3);
123
+ return (0, visitor_plugin_common_1.indent)(`args["${arg.name.value}"]${typeToUse.nullable || fallback ? '?' : '!!'}.let { ${arg.name.value} -> (${arg.name.value} as List<Map<String, Any>>).map { ${typeToUse.baseType}(it) } }${fallback}`, 3);
128
124
  }
129
125
  if (typeToUse.isScalar) {
130
- return visitorPluginCommon.indent(`args["${arg.name.value}"] as ${typeToUse.typeName}${typeToUse.nullable || fallback ? '?' : ''}${fallback}`, 3);
126
+ return (0, visitor_plugin_common_1.indent)(`args["${arg.name.value}"] as ${typeToUse.typeName}${typeToUse.nullable || fallback ? '?' : ''}${fallback}`, 3);
131
127
  }
132
128
  if (typeToUse.nullable || fallback) {
133
129
  suppress = '@Suppress("UNCHECKED_CAST")\n ';
134
- return visitorPluginCommon.indent(`args["${arg.name.value}"]?.let { ${typeToUse.typeName}(it as Map<String, Any>) }${fallback}`, 3);
130
+ return (0, visitor_plugin_common_1.indent)(`args["${arg.name.value}"]?.let { ${typeToUse.typeName}(it as Map<String, Any>) }${fallback}`, 3);
135
131
  }
136
132
  suppress = '@Suppress("UNCHECKED_CAST")\n ';
137
- return visitorPluginCommon.indent(`${typeToUse.typeName}(args["${arg.name.value}"] as Map<String, Any>)`, 3);
133
+ return (0, visitor_plugin_common_1.indent)(`${typeToUse.typeName}(args["${arg.name.value}"] as Map<String, Any>)`, 3);
138
134
  })
139
135
  .join(',\n');
140
136
  // language=kotlin
@@ -153,7 +149,7 @@ ${ctorSet}
153
149
  return '';
154
150
  }
155
151
  const typeToUse = this.resolveInputFieldType(arg.type);
156
- return visitorPluginCommon.indent(`val ${arg.name.value}: ${typeToUse.typeName}${typeToUse.nullable ? '?' : ''}`, 2);
152
+ return (0, visitor_plugin_common_1.indent)(`val ${arg.name.value}: ${typeToUse.typeName}${typeToUse.nullable ? '?' : ''}`, 2);
157
153
  })
158
154
  .join(',\n');
159
155
  // language=kotlin
@@ -223,16 +219,4 @@ ${classMembers}
223
219
  return types.join('\n');
224
220
  }
225
221
  }
226
-
227
- const plugin = async (schema, documents, config, { outputFile }) => {
228
- const relevantPath = path.dirname(path.normalize(outputFile));
229
- const defaultPackageName = javaCommon.buildPackageNameFromPath(relevantPath);
230
- const visitor = new KotlinResolversVisitor(config, schema, defaultPackageName);
231
- const astNode = pluginHelpers.getCachedDocumentNodeFromSchema(schema);
232
- const visitorResult = pluginHelpers.oldVisit(astNode, { leave: visitor });
233
- const packageName = visitor.getPackageName();
234
- const blockContent = visitorResult.definitions.filter(d => typeof d === 'string').join('\n\n');
235
- return [packageName, blockContent].join('\n');
236
- };
237
-
238
- exports.plugin = plugin;
222
+ exports.KotlinResolversVisitor = KotlinResolversVisitor;
package/esm/config.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/index.js ADDED
@@ -0,0 +1,14 @@
1
+ import { getCachedDocumentNodeFromSchema, oldVisit } from '@graphql-codegen/plugin-helpers';
2
+ import { KotlinResolversVisitor } from './visitor.js';
3
+ import { buildPackageNameFromPath } from '@graphql-codegen/java-common';
4
+ import { dirname, normalize } from 'path';
5
+ export const plugin = async (schema, documents, config, { outputFile }) => {
6
+ const relevantPath = dirname(normalize(outputFile));
7
+ const defaultPackageName = buildPackageNameFromPath(relevantPath);
8
+ const visitor = new KotlinResolversVisitor(config, schema, defaultPackageName);
9
+ const astNode = getCachedDocumentNodeFromSchema(schema);
10
+ const visitorResult = oldVisit(astNode, { leave: visitor });
11
+ const packageName = visitor.getPackageName();
12
+ const blockContent = visitorResult.definitions.filter(d => typeof d === 'string').join('\n\n');
13
+ return [packageName, blockContent].join('\n');
14
+ };
@@ -1,17 +1,14 @@
1
- import { getCachedDocumentNodeFromSchema, oldVisit } from '@graphql-codegen/plugin-helpers';
2
- import { BaseVisitor, buildScalarsFromConfig, indent, transformComment, indentMultiline, getBaseTypeNode } from '@graphql-codegen/visitor-plugin-common';
3
- import { Kind, isScalarType, isInputObjectType, isEnumType, isObjectType } from 'graphql';
4
- import { wrapTypeWithModifiers, buildPackageNameFromPath } from '@graphql-codegen/java-common';
5
- import { dirname, normalize } from 'path';
6
-
7
- const KOTLIN_SCALARS = {
1
+ import { BaseVisitor, indent, indentMultiline, transformComment, getBaseTypeNode, buildScalarsFromConfig, } from '@graphql-codegen/visitor-plugin-common';
2
+ import { isEnumType, isInputObjectType, isObjectType, isScalarType, Kind, } from 'graphql';
3
+ import { wrapTypeWithModifiers } from '@graphql-codegen/java-common';
4
+ export const KOTLIN_SCALARS = {
8
5
  ID: 'Any',
9
6
  String: 'String',
10
7
  Boolean: 'Boolean',
11
8
  Int: 'Int',
12
9
  Float: 'Float',
13
10
  };
14
- class KotlinResolversVisitor extends BaseVisitor {
11
+ export class KotlinResolversVisitor extends BaseVisitor {
15
12
  constructor(rawConfig, _schema, defaultPackageName) {
16
13
  super(rawConfig, {
17
14
  enumValues: rawConfig.enumValues || {},
@@ -219,16 +216,3 @@ ${classMembers}
219
216
  return types.join('\n');
220
217
  }
221
218
  }
222
-
223
- const plugin = async (schema, documents, config, { outputFile }) => {
224
- const relevantPath = dirname(normalize(outputFile));
225
- const defaultPackageName = buildPackageNameFromPath(relevantPath);
226
- const visitor = new KotlinResolversVisitor(config, schema, defaultPackageName);
227
- const astNode = getCachedDocumentNodeFromSchema(schema);
228
- const visitorResult = oldVisit(astNode, { leave: visitor });
229
- const packageName = visitor.getPackageName();
230
- const blockContent = visitorResult.definitions.filter(d => typeof d === 'string').join('\n\n');
231
- return [packageName, blockContent].join('\n');
232
- };
233
-
234
- export { plugin };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@graphql-codegen/kotlin",
3
- "version": "2.2.15",
3
+ "version": "2.3.0-alpha-29eb1293b.0",
4
4
  "description": "GraphQL Code Generator plugin for generating Kotlin code based on a GraphQL schema",
5
5
  "peerDependencies": {
6
6
  "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
7
7
  },
8
8
  "dependencies": {
9
- "@graphql-codegen/java-common": "^2.1.21",
10
- "@graphql-codegen/plugin-helpers": "^2.4.0",
11
- "@graphql-codegen/visitor-plugin-common": "2.10.0",
9
+ "@graphql-codegen/java-common": "^2.2.0-alpha-29eb1293b.0",
10
+ "@graphql-codegen/plugin-helpers": "^2.5.0-alpha-29eb1293b.0",
11
+ "@graphql-codegen/visitor-plugin-common": "2.11.0-alpha-29eb1293b.0",
12
12
  "tslib": "~2.4.0"
13
13
  },
14
14
  "repository": {
@@ -17,21 +17,28 @@
17
17
  "directory": "packages/plugins/java/kotlin"
18
18
  },
19
19
  "license": "MIT",
20
- "main": "index.js",
21
- "module": "index.mjs",
22
- "typings": "index.d.ts",
20
+ "main": "cjs/index.js",
21
+ "module": "esm/index.js",
22
+ "typings": "typings/index.d.ts",
23
23
  "typescript": {
24
- "definition": "index.d.ts"
24
+ "definition": "typings/index.d.ts"
25
25
  },
26
+ "type": "module",
26
27
  "exports": {
27
- "./package.json": "./package.json",
28
28
  ".": {
29
- "require": "./index.js",
30
- "import": "./index.mjs"
29
+ "require": {
30
+ "types": "./typings/index.d.ts",
31
+ "default": "./cjs/index.js"
32
+ },
33
+ "import": {
34
+ "types": "./typings/index.d.ts",
35
+ "default": "./esm/index.js"
36
+ },
37
+ "default": {
38
+ "types": "./typings/index.d.ts",
39
+ "default": "./esm/index.js"
40
+ }
31
41
  },
32
- "./*": {
33
- "require": "./*.js",
34
- "import": "./*.mjs"
35
- }
42
+ "./package.json": "./package.json"
36
43
  }
37
- }
44
+ }
File without changes
@@ -1,3 +1,3 @@
1
1
  import { PluginFunction } from '@graphql-codegen/plugin-helpers';
2
- import { KotlinResolversPluginRawConfig } from './config';
2
+ import { KotlinResolversPluginRawConfig } from './config.js';
3
3
  export declare const plugin: PluginFunction<KotlinResolversPluginRawConfig>;
@@ -1,5 +1,5 @@
1
1
  import { BaseVisitor, EnumValuesMap, ParsedConfig } from '@graphql-codegen/visitor-plugin-common';
2
- import { KotlinResolversPluginRawConfig } from './config';
2
+ import { KotlinResolversPluginRawConfig } from './config.js';
3
3
  import { EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, ObjectTypeDefinitionNode, TypeNode, ValueNode } from 'graphql';
4
4
  export declare const KOTLIN_SCALARS: {
5
5
  ID: string;