@graphql-codegen/java-apollo-android 2.2.13 → 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.
Files changed (40) hide show
  1. package/cjs/base-java-visitor.js +114 -0
  2. package/cjs/custom-type-class.js +69 -0
  3. package/cjs/field-arguments.js +36 -0
  4. package/cjs/file-type.js +10 -0
  5. package/cjs/imports.js +45 -0
  6. package/cjs/index.js +5 -0
  7. package/cjs/input-type-visitor.js +187 -0
  8. package/cjs/operation-visitor.js +780 -0
  9. package/cjs/package.json +1 -0
  10. package/cjs/plugin.js +48 -0
  11. package/cjs/preset.js +95 -0
  12. package/cjs/types.js +2 -0
  13. package/cjs/visitor-config.js +2 -0
  14. package/esm/base-java-visitor.js +110 -0
  15. package/esm/custom-type-class.js +65 -0
  16. package/esm/field-arguments.js +32 -0
  17. package/esm/file-type.js +7 -0
  18. package/esm/imports.js +42 -0
  19. package/esm/index.js +2 -0
  20. package/esm/input-type-visitor.js +183 -0
  21. package/{index.mjs → esm/operation-visitor.js} +8 -565
  22. package/esm/plugin.js +44 -0
  23. package/esm/preset.js +92 -0
  24. package/esm/types.js +1 -0
  25. package/esm/visitor-config.js +1 -0
  26. package/package.json +23 -16
  27. package/{base-java-visitor.d.ts → typings/base-java-visitor.d.ts} +3 -3
  28. package/{custom-type-class.d.ts → typings/custom-type-class.d.ts} +3 -3
  29. package/{field-arguments.d.ts → typings/field-arguments.d.ts} +1 -1
  30. package/{file-type.d.ts → typings/file-type.d.ts} +0 -0
  31. package/{imports.d.ts → typings/imports.d.ts} +0 -0
  32. package/typings/index.d.ts +2 -0
  33. package/{input-type-visitor.d.ts → typings/input-type-visitor.d.ts} +3 -3
  34. package/{operation-visitor.d.ts → typings/operation-visitor.d.ts} +3 -3
  35. package/{plugin.d.ts → typings/plugin.d.ts} +1 -1
  36. package/{preset.d.ts → typings/preset.d.ts} +0 -0
  37. package/{types.d.ts → typings/types.d.ts} +0 -0
  38. package/{visitor-config.d.ts → typings/visitor-config.d.ts} +0 -0
  39. package/index.d.ts +0 -2
  40. package/index.js +0 -1339
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseJavaVisitor = exports.SCALAR_TO_WRITER_METHOD = void 0;
4
+ const imports_js_1 = require("./imports.js");
5
+ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
6
+ const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
7
+ const java_common_1 = require("@graphql-codegen/java-common");
8
+ const graphql_1 = require("graphql");
9
+ exports.SCALAR_TO_WRITER_METHOD = {
10
+ ID: 'writeString',
11
+ String: 'writeString',
12
+ Int: 'writeInt',
13
+ Boolean: 'writeBoolean',
14
+ Float: 'writeDouble',
15
+ };
16
+ function isTypeNode(type) {
17
+ return type && !!type.kind;
18
+ }
19
+ class BaseJavaVisitor extends visitor_plugin_common_1.BaseVisitor {
20
+ constructor(_schema, rawConfig, additionalConfig) {
21
+ super(rawConfig, {
22
+ ...additionalConfig,
23
+ scalars: (0, visitor_plugin_common_1.buildScalars)(_schema, { ID: 'String' }, java_common_1.JAVA_SCALARS),
24
+ });
25
+ this._schema = _schema;
26
+ this._imports = new Set();
27
+ }
28
+ getPackage() {
29
+ return '';
30
+ }
31
+ additionalContent() {
32
+ return '';
33
+ }
34
+ getImports() {
35
+ return Array.from(this._imports).map(imp => `import ${imp};`);
36
+ }
37
+ getImplementingTypes(node) {
38
+ const allTypesMap = this._schema.getTypeMap();
39
+ const implementingTypes = [];
40
+ for (const graphqlType of Object.values(allTypesMap)) {
41
+ if (graphqlType instanceof graphql_1.GraphQLObjectType) {
42
+ const allInterfaces = graphqlType.getInterfaces();
43
+ if (allInterfaces.find(int => int.name === node.name)) {
44
+ implementingTypes.push(graphqlType.name);
45
+ }
46
+ }
47
+ }
48
+ return implementingTypes;
49
+ }
50
+ transformType(type) {
51
+ let schemaType;
52
+ let isNonNull;
53
+ if (isTypeNode(type)) {
54
+ const baseTypeNode = (0, visitor_plugin_common_1.getBaseTypeNode)(type);
55
+ schemaType = this._schema.getType(baseTypeNode.name.value);
56
+ isNonNull = type.kind === graphql_1.Kind.NON_NULL_TYPE;
57
+ }
58
+ else {
59
+ schemaType = this._schema.getType((0, plugin_helpers_1.getBaseType)(type).name);
60
+ isNonNull = (0, graphql_1.isNonNullType)(type);
61
+ }
62
+ const javaType = this.getJavaClass(schemaType);
63
+ const annotation = isNonNull ? 'Nonnull' : 'Nullable';
64
+ const typeToUse = isTypeNode(type)
65
+ ? this.getListTypeNodeWrapped(javaType, type)
66
+ : this.getListTypeWrapped(javaType, type);
67
+ return {
68
+ baseType: schemaType.name,
69
+ javaType,
70
+ isNonNull,
71
+ annotation,
72
+ typeToUse,
73
+ };
74
+ }
75
+ // Replaces a GraphQL type with a Java class
76
+ getJavaClass(schemaType) {
77
+ let typeToUse = schemaType.name;
78
+ if ((0, graphql_1.isScalarType)(schemaType)) {
79
+ const scalar = this.scalars[schemaType.name] || 'Object';
80
+ if (imports_js_1.Imports[scalar]) {
81
+ this._imports.add(imports_js_1.Imports[scalar]);
82
+ }
83
+ typeToUse = scalar;
84
+ }
85
+ else if ((0, graphql_1.isInputObjectType)(schemaType)) {
86
+ // Make sure to import it if it's in use
87
+ this._imports.add(`${this.config.typePackage}.${schemaType.name}`);
88
+ }
89
+ return typeToUse;
90
+ }
91
+ getListTypeWrapped(toWrap, type) {
92
+ if ((0, graphql_1.isNonNullType)(type)) {
93
+ return this.getListTypeWrapped(toWrap, type.ofType);
94
+ }
95
+ if ((0, graphql_1.isListType)(type)) {
96
+ const child = this.getListTypeWrapped(toWrap, type.ofType);
97
+ this._imports.add(imports_js_1.Imports.List);
98
+ return `List<${child}>`;
99
+ }
100
+ return toWrap;
101
+ }
102
+ getListTypeNodeWrapped(toWrap, type) {
103
+ if (type.kind === graphql_1.Kind.NON_NULL_TYPE) {
104
+ return this.getListTypeNodeWrapped(toWrap, type.type);
105
+ }
106
+ if (type.kind === graphql_1.Kind.LIST_TYPE) {
107
+ const child = this.getListTypeNodeWrapped(toWrap, type.type);
108
+ this._imports.add(imports_js_1.Imports.List);
109
+ return `List<${child}>`;
110
+ }
111
+ return toWrap;
112
+ }
113
+ }
114
+ exports.BaseJavaVisitor = BaseJavaVisitor;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomTypeClassVisitor = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const base_java_visitor_js_1 = require("./base-java-visitor.js");
6
+ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
7
+ const imports_js_1 = require("./imports.js");
8
+ const java_common_1 = require("@graphql-codegen/java-common");
9
+ const filteredScalars = ['String', 'Float', 'Int', 'Boolean'];
10
+ class CustomTypeClassVisitor extends base_java_visitor_js_1.BaseJavaVisitor {
11
+ constructor(schema, rawConfig) {
12
+ super(schema, rawConfig, {
13
+ typePackage: rawConfig.typePackage || 'type',
14
+ });
15
+ }
16
+ extract(name) {
17
+ const lastIndex = name.lastIndexOf('.');
18
+ if (lastIndex === -1) {
19
+ return {
20
+ className: name,
21
+ importFrom: imports_js_1.Imports[name] || null,
22
+ };
23
+ }
24
+ return {
25
+ className: name.substring(lastIndex + 1),
26
+ importFrom: name,
27
+ };
28
+ }
29
+ additionalContent() {
30
+ this._imports.add(imports_js_1.Imports.ScalarType);
31
+ this._imports.add(imports_js_1.Imports.Class);
32
+ this._imports.add(imports_js_1.Imports.Override);
33
+ this._imports.add(imports_js_1.Imports.Generated);
34
+ const allTypes = this._schema.getTypeMap();
35
+ const enumValues = Object.keys(allTypes)
36
+ .filter(t => (0, graphql_1.isScalarType)(allTypes[t]) && !filteredScalars.includes(t))
37
+ .map(t => allTypes[t])
38
+ .map(scalarType => {
39
+ const uppercaseName = scalarType.name.toUpperCase();
40
+ const javaType = this.extract(this.scalars[scalarType.name] || 'String');
41
+ if (javaType.importFrom) {
42
+ this._imports.add(javaType.importFrom);
43
+ }
44
+ return (0, visitor_plugin_common_1.indentMultiline)(`${uppercaseName} {
45
+ @Override
46
+ public String typeName() {
47
+ return "${scalarType.name}";
48
+ }
49
+
50
+ @Override
51
+ public Class javaType() {
52
+ return ${javaType.className}.class;
53
+ }
54
+ }`);
55
+ })
56
+ .join(',\n\n');
57
+ return new java_common_1.JavaDeclarationBlock()
58
+ .annotate([`Generated("Apollo GraphQL")`])
59
+ .access('public')
60
+ .asKind('enum')
61
+ .withName('CustomType')
62
+ .implements(['ScalarType'])
63
+ .withBlock(enumValues).string;
64
+ }
65
+ getPackage() {
66
+ return this.config.typePackage;
67
+ }
68
+ }
69
+ exports.CustomTypeClassVisitor = CustomTypeClassVisitor;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.visitFieldArguments = void 0;
4
+ const imports_js_1 = require("./imports.js");
5
+ const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
6
+ function visitFieldArguments(selection, imports) {
7
+ if (!selection.arguments || selection.arguments.length === 0) {
8
+ return 'null';
9
+ }
10
+ imports.add(imports_js_1.Imports.UnmodifiableMapBuilder);
11
+ imports.add(imports_js_1.Imports.String);
12
+ imports.add(imports_js_1.Imports.Object);
13
+ return (0, plugin_helpers_1.oldVisit)(selection, {
14
+ leave: {
15
+ Field: (node) => {
16
+ return (`new UnmodifiableMapBuilder<String, Object>(${node.arguments.length})` + node.arguments.join('') + '.build()');
17
+ },
18
+ Argument: (node) => {
19
+ return `.put("${node.name.value}", ${node.value})`;
20
+ },
21
+ ObjectValue: (node) => {
22
+ return `new UnmodifiableMapBuilder<String, Object>(${node.fields.length})` + node.fields.join('') + '.build()';
23
+ },
24
+ ObjectField: (node) => {
25
+ return `.put("${node.name.value}", ${node.value})`;
26
+ },
27
+ Variable: (node) => {
28
+ return `new UnmodifiableMapBuilder<String, Object>(2).put("kind", "Variable").put("variableName", "${node.name.value}").build()`;
29
+ },
30
+ StringValue: (node) => `"${node.value}"`,
31
+ IntValue: (node) => `"${node.value}"`,
32
+ FloatValue: (node) => `"${node.value}"`,
33
+ },
34
+ });
35
+ }
36
+ exports.visitFieldArguments = visitFieldArguments;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileType = void 0;
4
+ var FileType;
5
+ (function (FileType) {
6
+ FileType[FileType["INPUT_TYPE"] = 0] = "INPUT_TYPE";
7
+ FileType[FileType["OPERATION"] = 1] = "OPERATION";
8
+ FileType[FileType["FRAGMENT"] = 2] = "FRAGMENT";
9
+ FileType[FileType["CUSTOM_TYPES"] = 3] = "CUSTOM_TYPES";
10
+ })(FileType = exports.FileType || (exports.FileType = {}));
package/cjs/imports.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Imports = void 0;
4
+ exports.Imports = {
5
+ // Primitives
6
+ String: 'java.lang.String',
7
+ Boolean: 'java.lang.Boolean',
8
+ Integer: 'java.lang.Integer',
9
+ Object: 'java.lang.Object',
10
+ Float: 'java.lang.Float',
11
+ Long: 'java.lang.Long',
12
+ // Java Base
13
+ Class: 'java.lang.Class',
14
+ Arrays: 'java.util.Arrays',
15
+ List: 'java.util.List',
16
+ IOException: 'java.io.IOException',
17
+ Collections: 'java.util.Collections',
18
+ LinkedHashMap: 'java.util.LinkedHashMap',
19
+ Map: 'java.util.Map',
20
+ // Annotations
21
+ Nonnull: 'javax.annotation.Nonnull',
22
+ Nullable: 'javax.annotation.Nullable',
23
+ Override: 'java.lang.Override',
24
+ Generated: 'javax.annotation.Generated',
25
+ // Apollo Android
26
+ ScalarType: 'com.apollographql.apollo.api.ScalarType',
27
+ GraphqlFragment: 'com.apollographql.apollo.api.GraphqlFragment',
28
+ Operation: 'com.apollographql.apollo.api.Operation',
29
+ OperationName: 'com.apollographql.apollo.api.OperationName',
30
+ Mutation: 'com.apollographql.apollo.api.Mutation',
31
+ Query: 'com.apollographql.apollo.api.Query',
32
+ Subscription: 'com.apollographql.apollo.api.Subscription',
33
+ ResponseField: 'com.apollographql.apollo.api.ResponseField',
34
+ ResponseFieldMapper: 'com.apollographql.apollo.api.ResponseFieldMapper',
35
+ ResponseFieldMarshaller: 'com.apollographql.apollo.api.ResponseFieldMarshaller',
36
+ ResponseReader: 'com.apollographql.apollo.api.ResponseReader',
37
+ ResponseWriter: 'com.apollographql.apollo.api.ResponseWriter',
38
+ FragmentResponseFieldMapper: 'com.apollographql.apollo.api.FragmentResponseFieldMapper',
39
+ UnmodifiableMapBuilder: 'com.apollographql.apollo.api.internal.UnmodifiableMapBuilder',
40
+ Utils: 'com.apollographql.apollo.api.internal.Utils',
41
+ InputType: 'com.apollographql.apollo.api.InputType',
42
+ Input: 'com.apollographql.apollo.api.Input',
43
+ InputFieldMarshaller: 'com.apollographql.apollo.api.InputFieldMarshaller',
44
+ InputFieldWriter: 'com.apollographql.apollo.api.InputFieldWriter',
45
+ };
package/cjs/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./plugin.js"), exports);
5
+ tslib_1.__exportStar(require("./preset.js"), exports);
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InputTypeVisitor = void 0;
4
+ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
5
+ const java_common_1 = require("@graphql-codegen/java-common");
6
+ const graphql_1 = require("graphql");
7
+ const imports_js_1 = require("./imports.js");
8
+ const base_java_visitor_js_1 = require("./base-java-visitor.js");
9
+ class InputTypeVisitor extends base_java_visitor_js_1.BaseJavaVisitor {
10
+ constructor(_schema, rawConfig) {
11
+ super(_schema, rawConfig, {
12
+ typePackage: rawConfig.typePackage || 'type',
13
+ });
14
+ }
15
+ getPackage() {
16
+ return this.config.typePackage;
17
+ }
18
+ addInputMembers(cls, fields) {
19
+ fields.forEach(field => {
20
+ const type = this.transformType(field.type);
21
+ const actualType = type.isNonNull ? type.typeToUse : `Input<${type.typeToUse}>`;
22
+ const annotations = type.isNonNull ? [type.annotation] : [];
23
+ this._imports.add(imports_js_1.Imports[type.annotation]);
24
+ cls.addClassMember(field.name.value, actualType, null, annotations, 'private', { final: true });
25
+ cls.addClassMethod(field.name.value, actualType, `return this.${field.name.value};`, [], [type.annotation], 'public');
26
+ });
27
+ }
28
+ addInputCtor(cls, className, fields) {
29
+ const impl = fields.map(field => `this.${field.name.value} = ${field.name.value};`).join('\n');
30
+ cls.addClassMethod(className, null, impl, fields.map(f => {
31
+ const type = this.transformType(f.type);
32
+ const actualType = type.isNonNull ? type.typeToUse : `Input<${type.typeToUse}>`;
33
+ this._imports.add(imports_js_1.Imports[type.annotation]);
34
+ return {
35
+ name: f.name.value,
36
+ type: actualType,
37
+ annotations: type.isNonNull ? [type.annotation] : [],
38
+ };
39
+ }), [], 'public');
40
+ }
41
+ getFieldWriterCall(field, listItemCall = false) {
42
+ const baseType = (0, visitor_plugin_common_1.getBaseTypeNode)(field.type);
43
+ const schemaType = this._schema.getType(baseType.name.value);
44
+ const isNonNull = field.type.kind === graphql_1.Kind.NON_NULL_TYPE;
45
+ let writerMethod = null;
46
+ if ((0, graphql_1.isScalarType)(schemaType)) {
47
+ writerMethod = base_java_visitor_js_1.SCALAR_TO_WRITER_METHOD[schemaType.name] || 'writeCustom';
48
+ }
49
+ else if ((0, graphql_1.isInputObjectType)(schemaType)) {
50
+ return listItemCall
51
+ ? `writeObject($item.marshaller())`
52
+ : `writeObject("${field.name.value}", ${field.name.value}.value != null ? ${field.name.value}.value.marshaller() : null)`;
53
+ }
54
+ else if ((0, graphql_1.isEnumType)(schemaType)) {
55
+ writerMethod = 'writeString';
56
+ }
57
+ return listItemCall
58
+ ? `${writerMethod}($item)`
59
+ : `${writerMethod}("${field.name.value}", ${field.name.value}${isNonNull ? '' : '.value'})`;
60
+ }
61
+ getFieldWithTypePrefix(field, wrapWith = null, applyNullable = false) {
62
+ this._imports.add(imports_js_1.Imports.Input);
63
+ const typeToUse = this.getJavaClass(this._schema.getType((0, visitor_plugin_common_1.getBaseTypeNode)(field.type).name.value));
64
+ const isNonNull = field.type.kind === graphql_1.Kind.NON_NULL_TYPE;
65
+ const name = field.kind === graphql_1.Kind.INPUT_VALUE_DEFINITION ? field.name.value : field.variable.name.value;
66
+ if (isNonNull) {
67
+ this._imports.add(imports_js_1.Imports.Nonnull);
68
+ return `@Nonnull ${typeToUse} ${name}`;
69
+ }
70
+ if (wrapWith) {
71
+ return typeof wrapWith === 'function' ? `${wrapWith(typeToUse)} ${name}` : `${wrapWith}<${typeToUse}> ${name}`;
72
+ }
73
+ if (applyNullable) {
74
+ this._imports.add(imports_js_1.Imports.Nullable);
75
+ }
76
+ return `${applyNullable ? '@Nullable ' : ''}${typeToUse} ${name}`;
77
+ }
78
+ buildFieldsMarshaller(field) {
79
+ const isNonNull = field.type.kind === graphql_1.Kind.NON_NULL_TYPE;
80
+ const isArray = field.type.kind === graphql_1.Kind.LIST_TYPE ||
81
+ (field.type.kind === graphql_1.Kind.NON_NULL_TYPE && field.type.type.kind === graphql_1.Kind.LIST_TYPE);
82
+ const call = this.getFieldWriterCall(field, isArray);
83
+ const baseTypeNode = (0, visitor_plugin_common_1.getBaseTypeNode)(field.type);
84
+ const listItemType = this.getJavaClass(this._schema.getType(baseTypeNode.name.value));
85
+ let result = '';
86
+ // TODO: Refactor
87
+ if (isArray) {
88
+ result = `writer.writeList("${field.name.value}", ${field.name.value}.value != null ? new InputFieldWriter.ListWriter() {
89
+ @Override
90
+ public void write(InputFieldWriter.ListItemWriter listItemWriter) throws IOException {
91
+ for (${listItemType} $item : ${field.name.value}.value) {
92
+ listItemWriter.${call};
93
+ }
94
+ }
95
+ } : null);`;
96
+ }
97
+ else {
98
+ result = (0, visitor_plugin_common_1.indent)(`writer.${call};`);
99
+ }
100
+ if (isNonNull) {
101
+ return result;
102
+ }
103
+ return (0, visitor_plugin_common_1.indentMultiline)(`if(${field.name.value}.defined) {
104
+ ${(0, visitor_plugin_common_1.indentMultiline)(result)}
105
+ }`);
106
+ }
107
+ buildMarshallerOverride(fields) {
108
+ this._imports.add(imports_js_1.Imports.Override);
109
+ this._imports.add(imports_js_1.Imports.IOException);
110
+ this._imports.add(imports_js_1.Imports.InputFieldWriter);
111
+ this._imports.add(imports_js_1.Imports.InputFieldMarshaller);
112
+ const allMarshallers = fields.map(field => (0, visitor_plugin_common_1.indentMultiline)(this.buildFieldsMarshaller(field), 2));
113
+ return (0, visitor_plugin_common_1.indentMultiline)(`@Override
114
+ public InputFieldMarshaller marshaller() {
115
+ return new InputFieldMarshaller() {
116
+ @Override
117
+ public void marshal(InputFieldWriter writer) throws IOException {
118
+ ${allMarshallers.join('\n')}
119
+ }
120
+ };
121
+ }`);
122
+ }
123
+ buildBuilderNestedClass(className, fields) {
124
+ const builderClassName = 'Builder';
125
+ const privateFields = fields
126
+ .map(field => {
127
+ const isArray = field.type.kind === graphql_1.Kind.LIST_TYPE ||
128
+ (field.type.kind === graphql_1.Kind.NON_NULL_TYPE && field.type.type.kind === graphql_1.Kind.LIST_TYPE);
129
+ const fieldType = this.getFieldWithTypePrefix(field, v => (!isArray ? `Input<${v}>` : `Input<List<${v}>>`));
130
+ const isNonNull = field.type.kind === graphql_1.Kind.NON_NULL_TYPE;
131
+ return `private ${fieldType}${isNonNull ? '' : ' = Input.absent()'};`;
132
+ })
133
+ .map(s => (0, visitor_plugin_common_1.indent)(s));
134
+ const setters = fields
135
+ .map(field => {
136
+ const isArray = field.type.kind === graphql_1.Kind.LIST_TYPE ||
137
+ (field.type.kind === graphql_1.Kind.NON_NULL_TYPE && field.type.type.kind === graphql_1.Kind.LIST_TYPE);
138
+ const fieldType = this.getFieldWithTypePrefix(field, isArray ? 'List' : null);
139
+ const isNonNull = field.type.kind === graphql_1.Kind.NON_NULL_TYPE;
140
+ return `\npublic ${builderClassName} ${field.name.value}(${isNonNull ? '' : '@Nullable '}${fieldType}) {
141
+ this.${field.name.value} = ${isNonNull ? field.name.value : `Input.fromNullable(${field.name.value})`};
142
+ return this;
143
+ }`;
144
+ })
145
+ .map(s => (0, visitor_plugin_common_1.indentMultiline)(s));
146
+ const nonNullFields = fields
147
+ .filter(f => f.type.kind === graphql_1.Kind.NON_NULL_TYPE)
148
+ .map(nnField => {
149
+ this._imports.add(imports_js_1.Imports.Utils);
150
+ return (0, visitor_plugin_common_1.indent)(`Utils.checkNotNull(${nnField.name.value}, "${nnField.name.value} == null");`, 1);
151
+ });
152
+ const ctor = '\n' + (0, visitor_plugin_common_1.indent)(`${builderClassName}() {}`);
153
+ const buildFn = (0, visitor_plugin_common_1.indentMultiline)(`public ${className} build() {
154
+ ${nonNullFields.join('\n')}
155
+ return new ${className}(${fields.map(f => f.name.value).join(', ')});
156
+ }`);
157
+ const body = [...privateFields, ctor, ...setters, '', buildFn].join('\n');
158
+ return (0, visitor_plugin_common_1.indentMultiline)(new java_common_1.JavaDeclarationBlock()
159
+ .withName(builderClassName)
160
+ .access('public')
161
+ .final()
162
+ .static()
163
+ .withBlock(body)
164
+ .asKind('class').string);
165
+ }
166
+ InputObjectTypeDefinition(node) {
167
+ const className = node.name.value;
168
+ this._imports.add(imports_js_1.Imports.InputType);
169
+ this._imports.add(imports_js_1.Imports.Generated);
170
+ const cls = new java_common_1.JavaDeclarationBlock()
171
+ .annotate([`Generated("Apollo GraphQL")`])
172
+ .access('public')
173
+ .final()
174
+ .asKind('class')
175
+ .withName(className)
176
+ .implements(['InputType']);
177
+ this.addInputMembers(cls, node.fields);
178
+ this.addInputCtor(cls, className, node.fields);
179
+ cls.addClassMethod('builder', 'Builder', 'return new Builder();', [], [], 'public', { static: true });
180
+ const marshallerOverride = this.buildMarshallerOverride(node.fields);
181
+ const builderClass = this.buildBuilderNestedClass(className, node.fields);
182
+ const classBlock = [marshallerOverride, '', builderClass].join('\n');
183
+ cls.withBlock(classBlock);
184
+ return cls.string;
185
+ }
186
+ }
187
+ exports.InputTypeVisitor = InputTypeVisitor;