@graphql-codegen/java-apollo-android 2.3.6 → 3.0.0-alpha-20230524083052-08ce957b4
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/base-java-visitor.js +4 -4
- package/cjs/custom-type-class.js +2 -2
- package/cjs/field-arguments.js +7 -3
- package/cjs/input-type-visitor.js +13 -7
- package/cjs/operation-visitor.js +59 -22
- package/cjs/plugin.js +5 -4
- package/cjs/preset.js +6 -3
- package/cjs/types.js +0 -2
- package/cjs/visitor-config.js +0 -2
- package/esm/base-java-visitor.js +4 -4
- package/esm/custom-type-class.js +2 -2
- package/esm/field-arguments.js +7 -3
- package/esm/input-type-visitor.js +13 -7
- package/esm/operation-visitor.js +59 -22
- package/esm/plugin.js +5 -4
- package/esm/preset.js +6 -3
- package/esm/types.js +0 -1
- package/esm/visitor-config.js +0 -1
- package/package.json +8 -5
- package/typings/base-java-visitor.d.cts +2 -2
- package/typings/base-java-visitor.d.ts +2 -2
- package/typings/custom-type-class.d.cts +1 -1
- package/typings/custom-type-class.d.ts +1 -1
- package/typings/input-type-visitor.d.cts +2 -2
- package/typings/input-type-visitor.d.ts +2 -2
- package/typings/operation-visitor.d.cts +3 -3
- package/typings/operation-visitor.d.ts +3 -3
- package/typings/types.d.cts +2 -2
- package/typings/types.d.ts +2 -2
package/cjs/base-java-visitor.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
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
4
|
const graphql_1 = require("graphql");
|
|
5
|
+
const java_common_1 = require("@graphql-codegen/java-common");
|
|
6
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
7
|
+
const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
|
|
8
|
+
const imports_js_1 = require("./imports.js");
|
|
9
9
|
exports.SCALAR_TO_WRITER_METHOD = {
|
|
10
10
|
ID: 'writeString',
|
|
11
11
|
String: 'writeString',
|
package/cjs/custom-type-class.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CustomTypeClassVisitor = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
|
-
const
|
|
5
|
+
const java_common_1 = require("@graphql-codegen/java-common");
|
|
6
6
|
const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
|
|
7
|
+
const base_java_visitor_js_1 = require("./base-java-visitor.js");
|
|
7
8
|
const imports_js_1 = require("./imports.js");
|
|
8
|
-
const java_common_1 = require("@graphql-codegen/java-common");
|
|
9
9
|
const filteredScalars = ['String', 'Float', 'Int', 'Boolean'];
|
|
10
10
|
class CustomTypeClassVisitor extends base_java_visitor_js_1.BaseJavaVisitor {
|
|
11
11
|
constructor(schema, rawConfig) {
|
package/cjs/field-arguments.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.visitFieldArguments = void 0;
|
|
4
|
-
const imports_js_1 = require("./imports.js");
|
|
5
4
|
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
5
|
+
const imports_js_1 = require("./imports.js");
|
|
6
6
|
function visitFieldArguments(selection, imports) {
|
|
7
7
|
if (!selection.arguments || selection.arguments.length === 0) {
|
|
8
8
|
return 'null';
|
|
@@ -13,13 +13,17 @@ function visitFieldArguments(selection, imports) {
|
|
|
13
13
|
return (0, plugin_helpers_1.oldVisit)(selection, {
|
|
14
14
|
leave: {
|
|
15
15
|
Field: (node) => {
|
|
16
|
-
return (`new UnmodifiableMapBuilder<String, Object>(${node.arguments.length})` +
|
|
16
|
+
return (`new UnmodifiableMapBuilder<String, Object>(${node.arguments.length})` +
|
|
17
|
+
node.arguments.join('') +
|
|
18
|
+
'.build()');
|
|
17
19
|
},
|
|
18
20
|
Argument: (node) => {
|
|
19
21
|
return `.put("${node.name.value}", ${node.value})`;
|
|
20
22
|
},
|
|
21
23
|
ObjectValue: (node) => {
|
|
22
|
-
return `new UnmodifiableMapBuilder<String, Object>(${node.fields.length})` +
|
|
24
|
+
return (`new UnmodifiableMapBuilder<String, Object>(${node.fields.length})` +
|
|
25
|
+
node.fields.join('') +
|
|
26
|
+
'.build()');
|
|
23
27
|
},
|
|
24
28
|
ObjectField: (node) => {
|
|
25
29
|
return `.put("${node.name.value}", ${node.value})`;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
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
4
|
const graphql_1 = require("graphql");
|
|
7
|
-
const
|
|
5
|
+
const java_common_1 = require("@graphql-codegen/java-common");
|
|
6
|
+
const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
|
|
8
7
|
const base_java_visitor_js_1 = require("./base-java-visitor.js");
|
|
8
|
+
const imports_js_1 = require("./imports.js");
|
|
9
9
|
class InputTypeVisitor extends base_java_visitor_js_1.BaseJavaVisitor {
|
|
10
10
|
constructor(_schema, rawConfig) {
|
|
11
11
|
super(_schema, rawConfig, {
|
|
@@ -21,7 +21,9 @@ class InputTypeVisitor extends base_java_visitor_js_1.BaseJavaVisitor {
|
|
|
21
21
|
const actualType = type.isNonNull ? type.typeToUse : `Input<${type.typeToUse}>`;
|
|
22
22
|
const annotations = type.isNonNull ? [type.annotation] : [];
|
|
23
23
|
this._imports.add(imports_js_1.Imports[type.annotation]);
|
|
24
|
-
cls.addClassMember(field.name.value, actualType, null, annotations, 'private', {
|
|
24
|
+
cls.addClassMember(field.name.value, actualType, null, annotations, 'private', {
|
|
25
|
+
final: true,
|
|
26
|
+
});
|
|
25
27
|
cls.addClassMethod(field.name.value, actualType, `return this.${field.name.value};`, [], [type.annotation], 'public');
|
|
26
28
|
});
|
|
27
29
|
}
|
|
@@ -68,7 +70,9 @@ class InputTypeVisitor extends base_java_visitor_js_1.BaseJavaVisitor {
|
|
|
68
70
|
return `@Nonnull ${typeToUse} ${name}`;
|
|
69
71
|
}
|
|
70
72
|
if (wrapWith) {
|
|
71
|
-
return typeof wrapWith === 'function'
|
|
73
|
+
return typeof wrapWith === 'function'
|
|
74
|
+
? `${wrapWith(typeToUse)} ${name}`
|
|
75
|
+
: `${wrapWith}<${typeToUse}> ${name}`;
|
|
72
76
|
}
|
|
73
77
|
if (applyNullable) {
|
|
74
78
|
this._imports.add(imports_js_1.Imports.Nullable);
|
|
@@ -126,7 +130,7 @@ ${allMarshallers.join('\n')}
|
|
|
126
130
|
.map(field => {
|
|
127
131
|
const isArray = field.type.kind === graphql_1.Kind.LIST_TYPE ||
|
|
128
132
|
(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 =>
|
|
133
|
+
const fieldType = this.getFieldWithTypePrefix(field, v => !isArray ? `Input<${v}>` : `Input<List<${v}>>`);
|
|
130
134
|
const isNonNull = field.type.kind === graphql_1.Kind.NON_NULL_TYPE;
|
|
131
135
|
return `private ${fieldType}${isNonNull ? '' : ' = Input.absent()'};`;
|
|
132
136
|
})
|
|
@@ -176,7 +180,9 @@ ${nonNullFields.join('\n')}
|
|
|
176
180
|
.implements(['InputType']);
|
|
177
181
|
this.addInputMembers(cls, node.fields);
|
|
178
182
|
this.addInputCtor(cls, className, node.fields);
|
|
179
|
-
cls.addClassMethod('builder', 'Builder', 'return new Builder();', [], [], 'public', {
|
|
183
|
+
cls.addClassMethod('builder', 'Builder', 'return new Builder();', [], [], 'public', {
|
|
184
|
+
static: true,
|
|
185
|
+
});
|
|
180
186
|
const marshallerOverride = this.buildMarshallerOverride(node.fields);
|
|
181
187
|
const builderClass = this.buildBuilderNestedClass(className, node.fields);
|
|
182
188
|
const classBlock = [marshallerOverride, '', builderClass].join('\n');
|
package/cjs/operation-visitor.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OperationVisitor = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
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 java_common_1 = require("@graphql-codegen/java-common");
|
|
8
|
-
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
9
|
-
const graphql_1 = require("graphql");
|
|
10
|
-
const imports_js_1 = require("./imports.js");
|
|
11
5
|
const crypto_1 = require("crypto");
|
|
6
|
+
const change_case_all_1 = require("change-case-all");
|
|
7
|
+
const graphql_1 = require("graphql");
|
|
12
8
|
const pluralize_1 = tslib_1.__importDefault(require("pluralize"));
|
|
9
|
+
const java_common_1 = require("@graphql-codegen/java-common");
|
|
10
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
11
|
+
const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
|
|
12
|
+
const base_java_visitor_js_1 = require("./base-java-visitor.js");
|
|
13
13
|
const field_arguments_js_1 = require("./field-arguments.js");
|
|
14
|
-
const
|
|
14
|
+
const imports_js_1 = require("./imports.js");
|
|
15
15
|
class OperationVisitor extends base_java_visitor_js_1.BaseJavaVisitor {
|
|
16
16
|
constructor(_schema, rawConfig, _availableFragments) {
|
|
17
17
|
super(_schema, rawConfig, {
|
|
@@ -105,7 +105,9 @@ class OperationVisitor extends base_java_visitor_js_1.BaseJavaVisitor {
|
|
|
105
105
|
if (selection.kind === graphql_1.Kind.FIELD) {
|
|
106
106
|
this._imports.add(imports_js_1.Imports.ResponseField);
|
|
107
107
|
const field = fields[selection.name.value];
|
|
108
|
-
const isObject = selection.selectionSet &&
|
|
108
|
+
const isObject = selection.selectionSet &&
|
|
109
|
+
selection.selectionSet.selections &&
|
|
110
|
+
selection.selectionSet.selections.length > 0;
|
|
109
111
|
const isNonNull = (0, graphql_1.isNonNullType)(field.type);
|
|
110
112
|
const fieldAnnotation = isNonNull ? 'Nonnull' : 'Nullable';
|
|
111
113
|
this._imports.add(imports_js_1.Imports[fieldAnnotation]);
|
|
@@ -252,7 +254,9 @@ class OperationVisitor extends base_java_visitor_js_1.BaseJavaVisitor {
|
|
|
252
254
|
})), [], 'public');
|
|
253
255
|
for (const spread of childFragmentSpread) {
|
|
254
256
|
const fragmentVarName = (0, change_case_all_1.camelCase)(spread.name);
|
|
255
|
-
fragmentsClass.addClassMember(fragmentVarName, spread.name, null, ['Nonnull'], 'private', {
|
|
257
|
+
fragmentsClass.addClassMember(fragmentVarName, spread.name, null, ['Nonnull'], 'private', {
|
|
258
|
+
final: true,
|
|
259
|
+
});
|
|
256
260
|
fragmentsClass.addClassMethod(fragmentVarName, spread.name, `return this.${fragmentVarName};`, [], ['Nonnull'], 'public', {}, []);
|
|
257
261
|
fragmentMapperClass.addClassMember(`${fragmentVarName}FieldMapper`, `${spread.name}.Mapper`, `new ${spread.name}.Mapper()`, [], 'private', { final: true });
|
|
258
262
|
}
|
|
@@ -302,7 +306,9 @@ ${childFragmentSpread
|
|
|
302
306
|
`, [], [], 'public');
|
|
303
307
|
fragmentsClass.addClassMember('$toString', 'String', null, [], 'private', { volatile: true });
|
|
304
308
|
fragmentsClass.addClassMember('$hashCode', 'int', null, [], 'private', { volatile: true });
|
|
305
|
-
fragmentsClass.addClassMember('$hashCodeMemoized', 'boolean', null, [], 'private', {
|
|
309
|
+
fragmentsClass.addClassMember('$hashCodeMemoized', 'boolean', null, [], 'private', {
|
|
310
|
+
volatile: true,
|
|
311
|
+
});
|
|
306
312
|
fragmentsClass.addClassMethod('toString', 'String', `if ($toString == null) {
|
|
307
313
|
$toString = "${fragmentsClassName}{"
|
|
308
314
|
${childFragmentSpread
|
|
@@ -378,7 +384,9 @@ ${childFragmentSpread
|
|
|
378
384
|
// Add Ctor
|
|
379
385
|
this._imports.add(imports_js_1.Imports.Utils);
|
|
380
386
|
cls.addClassMethod(className, null, childFields
|
|
381
|
-
.map(c => `this.${c.fieldName} = ${c.isNonNull
|
|
387
|
+
.map(c => `this.${c.fieldName} = ${c.isNonNull
|
|
388
|
+
? `Utils.checkNotNull(${c.fieldName}, "${c.fieldName} == null")`
|
|
389
|
+
: c.fieldName};`)
|
|
382
390
|
.join('\n'), childFields.map(c => ({
|
|
383
391
|
name: c.fieldName,
|
|
384
392
|
type: this.getListTypeWrapped(c.className, c.rawType),
|
|
@@ -480,7 +488,9 @@ ${childFields
|
|
|
480
488
|
if ((0, graphql_1.isListType)(rawType)) {
|
|
481
489
|
const typeStr = this.getListTypeWrapped(childField.className, rawType.ofType);
|
|
482
490
|
const innerContent = wrapList(childField, rawType.ofType, edgeStr);
|
|
483
|
-
const inner = (0, graphql_1.isListType)(rawType.ofType)
|
|
491
|
+
const inner = (0, graphql_1.isListType)(rawType.ofType)
|
|
492
|
+
? `return listItemReader.readList(${innerContent});`
|
|
493
|
+
: innerContent;
|
|
484
494
|
return `new ResponseReader.ListReader<${typeStr}>() {
|
|
485
495
|
@Override
|
|
486
496
|
public ${typeStr} read(ResponseReader.ListItemReader listItemReader) {
|
|
@@ -602,7 +612,9 @@ ${(0, visitor_plugin_common_1.indentMultiline)(inner, 2)}
|
|
|
602
612
|
static: true,
|
|
603
613
|
final: true,
|
|
604
614
|
});
|
|
605
|
-
const possibleTypes = (0, graphql_1.isObjectType)(schemaType)
|
|
615
|
+
const possibleTypes = (0, graphql_1.isObjectType)(schemaType)
|
|
616
|
+
? [schemaType.name]
|
|
617
|
+
: this.getImplementingTypes(schemaType);
|
|
606
618
|
rootCls.addClassMember('POSSIBLE_TYPES', 'List<String>', `Collections.unmodifiableList(Arrays.asList(${possibleTypes.map(t => `"${t}"`).join(', ')}))`, [], 'public', { static: true, final: true });
|
|
607
619
|
Object.keys(dataClasses)
|
|
608
620
|
.filter(name => name !== className)
|
|
@@ -615,7 +627,9 @@ ${(0, visitor_plugin_common_1.indentMultiline)(inner, 2)}
|
|
|
615
627
|
this.visitingFragment = false;
|
|
616
628
|
const operationType = (0, change_case_all_1.pascalCase)(node.operation);
|
|
617
629
|
const operationSchemaType = this.getRootType(node.operation);
|
|
618
|
-
const className = node.name.value.endsWith(operationType)
|
|
630
|
+
const className = node.name.value.endsWith(operationType)
|
|
631
|
+
? operationType
|
|
632
|
+
: `${node.name.value}${operationType}`;
|
|
619
633
|
this._imports.add(imports_js_1.Imports[operationType]);
|
|
620
634
|
this._imports.add(imports_js_1.Imports.String);
|
|
621
635
|
this._imports.add(imports_js_1.Imports.Override);
|
|
@@ -633,8 +647,14 @@ ${(0, visitor_plugin_common_1.indentMultiline)(inner, 2)}
|
|
|
633
647
|
cls.implements([
|
|
634
648
|
`${operationType}<${className}.Data, ${className}.Data, ${node.variableDefinitions.length === 0 ? 'Operation' : className}.Variables>`,
|
|
635
649
|
]);
|
|
636
|
-
cls.addClassMember('OPERATION_DEFINITION', 'String', `"${printed}"`, [], 'public', {
|
|
637
|
-
|
|
650
|
+
cls.addClassMember('OPERATION_DEFINITION', 'String', `"${printed}"`, [], 'public', {
|
|
651
|
+
static: true,
|
|
652
|
+
final: true,
|
|
653
|
+
});
|
|
654
|
+
cls.addClassMember('QUERY_DOCUMENT', 'String', 'OPERATION_DEFINITION', [], 'public', {
|
|
655
|
+
static: true,
|
|
656
|
+
final: true,
|
|
657
|
+
});
|
|
638
658
|
cls.addClassMember('OPERATION_NAME', 'OperationName', `new OperationName() {
|
|
639
659
|
@Override
|
|
640
660
|
public String name() {
|
|
@@ -642,7 +662,9 @@ ${(0, visitor_plugin_common_1.indentMultiline)(inner, 2)}
|
|
|
642
662
|
}
|
|
643
663
|
}`, [], 'public', { static: true, final: true });
|
|
644
664
|
cls.addClassMember('variables', `${node.variableDefinitions.length === 0 ? 'Operation' : className}.Variables`, null, [], 'private', { final: true });
|
|
645
|
-
cls.addClassMethod('queryDocument', `String`, `return QUERY_DOCUMENT;`, [], [], 'public', {}, [
|
|
665
|
+
cls.addClassMethod('queryDocument', `String`, `return QUERY_DOCUMENT;`, [], [], 'public', {}, [
|
|
666
|
+
'Override',
|
|
667
|
+
]);
|
|
646
668
|
cls.addClassMethod('wrapData', `${className}.Data`, `return data;`, [
|
|
647
669
|
{
|
|
648
670
|
name: 'data',
|
|
@@ -652,7 +674,9 @@ ${(0, visitor_plugin_common_1.indentMultiline)(inner, 2)}
|
|
|
652
674
|
cls.addClassMethod('variables', `${node.variableDefinitions.length === 0 ? 'Operation' : className}.Variables`, `return variables;`, [], [], 'public', {}, ['Override']);
|
|
653
675
|
cls.addClassMethod('responseFieldMapper', `ResponseFieldMapper<${className}.Data>`, `return new Data.Mapper();`, [], [], 'public', {}, ['Override']);
|
|
654
676
|
cls.addClassMethod('builder', `Builder`, `return new Builder();`, [], [], 'public', { static: true }, []);
|
|
655
|
-
cls.addClassMethod('name', `OperationName`, `return OPERATION_NAME;`, [], [], 'public', {}, [
|
|
677
|
+
cls.addClassMethod('name', `OperationName`, `return OPERATION_NAME;`, [], [], 'public', {}, [
|
|
678
|
+
'Override',
|
|
679
|
+
]);
|
|
656
680
|
cls.addClassMethod('operationId', `String`, `return "${(0, crypto_1.createHash)('md5').update(printed).digest('hex')}";`, [], [], 'public', {}, []);
|
|
657
681
|
this.addCtor(className, node, cls);
|
|
658
682
|
this._imports.add(imports_js_1.Imports.Operation);
|
|
@@ -689,7 +713,11 @@ ${(0, visitor_plugin_common_1.indentMultiline)(inner, 2)}
|
|
|
689
713
|
const javaClass = this.getJavaClass(schemaType);
|
|
690
714
|
const annotation = (0, graphql_1.isNonNullType)(variable.type) ? 'Nullable' : 'Nonnull';
|
|
691
715
|
this._imports.add(imports_js_1.Imports[annotation]);
|
|
692
|
-
ctorArgs.push({
|
|
716
|
+
ctorArgs.push({
|
|
717
|
+
name: variable.variable.name.value,
|
|
718
|
+
type: javaClass,
|
|
719
|
+
annotations: [annotation],
|
|
720
|
+
});
|
|
693
721
|
cls.addClassMember(variable.variable.name.value, javaClass, null, [annotation], 'private');
|
|
694
722
|
cls.addClassMethod(variable.variable.name.value, javaClass, `return ${variable.variable.name.value};`, [], [], 'public');
|
|
695
723
|
});
|
|
@@ -719,7 +747,9 @@ ${variables
|
|
|
719
747
|
this._imports.add(imports_js_1.Imports.InputFieldMarshaller);
|
|
720
748
|
this._imports.add(imports_js_1.Imports.InputFieldWriter);
|
|
721
749
|
this._imports.add(imports_js_1.Imports.IOException);
|
|
722
|
-
cls.addClassMethod('marshaller', 'InputFieldMarshaller', marshallerImpl, [], [], 'public', {}, [
|
|
750
|
+
cls.addClassMethod('marshaller', 'InputFieldMarshaller', marshallerImpl, [], [], 'public', {}, [
|
|
751
|
+
'Override',
|
|
752
|
+
]);
|
|
723
753
|
return cls;
|
|
724
754
|
}
|
|
725
755
|
_getWriterMethodByType(schemaType, idAsString = false) {
|
|
@@ -731,7 +761,12 @@ ${variables
|
|
|
731
761
|
useMarshaller: false,
|
|
732
762
|
};
|
|
733
763
|
}
|
|
734
|
-
return {
|
|
764
|
+
return {
|
|
765
|
+
name: 'writeCustom',
|
|
766
|
+
checkNull: false,
|
|
767
|
+
useMarshaller: false,
|
|
768
|
+
castTo: 'ResponseField.CustomTypeField',
|
|
769
|
+
};
|
|
735
770
|
}
|
|
736
771
|
if ((0, graphql_1.isInputObjectType)(schemaType)) {
|
|
737
772
|
return { name: 'writeObject', checkNull: true, useMarshaller: true };
|
|
@@ -772,7 +807,9 @@ ${variables
|
|
|
772
807
|
const nonNullChecks = variables
|
|
773
808
|
.filter(f => (0, graphql_1.isNonNullType)(f))
|
|
774
809
|
.map(f => `Utils.checkNotNull(${f.variable.name.value}, "${f.variable.name.value} == null");`);
|
|
775
|
-
const returnStatement = `return new ${parentClassName}(${variables
|
|
810
|
+
const returnStatement = `return new ${parentClassName}(${variables
|
|
811
|
+
.map(v => v.variable.name.value)
|
|
812
|
+
.join(', ')});`;
|
|
776
813
|
cls.addClassMethod('build', parentClassName, `${[...nonNullChecks, returnStatement].join('\n')}`, [], [], 'public');
|
|
777
814
|
return cls;
|
|
778
815
|
}
|
package/cjs/plugin.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.plugin = void 0;
|
|
4
|
-
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
5
4
|
const graphql_1 = require("graphql");
|
|
5
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
6
|
+
const custom_type_class_js_1 = require("./custom-type-class.js");
|
|
7
|
+
const file_type_js_1 = require("./file-type.js");
|
|
6
8
|
const input_type_visitor_js_1 = require("./input-type-visitor.js");
|
|
7
9
|
const operation_visitor_js_1 = require("./operation-visitor.js");
|
|
8
|
-
const file_type_js_1 = require("./file-type.js");
|
|
9
|
-
const custom_type_class_js_1 = require("./custom-type-class.js");
|
|
10
10
|
const plugin = (schema, documents, config) => {
|
|
11
11
|
const allAst = (0, graphql_1.concatAST)(documents.map(v => v.document));
|
|
12
12
|
const allFragments = [
|
|
@@ -42,7 +42,8 @@ const plugin = (schema, documents, config) => {
|
|
|
42
42
|
const imports = visitor.getImports();
|
|
43
43
|
return {
|
|
44
44
|
prepend: [`package ${visitor.getPackage()};\n`, ...imports],
|
|
45
|
-
content: '\n' +
|
|
45
|
+
content: '\n' +
|
|
46
|
+
[...visitResult.definitions.filter(a => a && typeof a === 'string'), additionalContent].join('\n'),
|
|
46
47
|
};
|
|
47
48
|
};
|
|
48
49
|
exports.plugin = plugin;
|
package/cjs/preset.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.preset = void 0;
|
|
4
|
-
const graphql_1 = require("graphql");
|
|
5
4
|
const path_1 = require("path");
|
|
6
|
-
const file_type_js_1 = require("./file-type.js");
|
|
7
5
|
const change_case_all_1 = require("change-case-all");
|
|
6
|
+
const graphql_1 = require("graphql");
|
|
7
|
+
const file_type_js_1 = require("./file-type.js");
|
|
8
8
|
const packageNameToDirectory = (packageName) => {
|
|
9
9
|
return `./${packageName.split('.').join('/')}/`;
|
|
10
10
|
};
|
|
@@ -19,7 +19,10 @@ exports.preset = {
|
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
21
|
});
|
|
22
|
-
const inputTypesDocumentNode = {
|
|
22
|
+
const inputTypesDocumentNode = {
|
|
23
|
+
kind: graphql_1.Kind.DOCUMENT,
|
|
24
|
+
definitions: inputTypesAst,
|
|
25
|
+
};
|
|
23
26
|
const allAst = (0, graphql_1.concatAST)(options.documents.map(v => v.document));
|
|
24
27
|
const operationsAst = allAst.definitions.filter(d => d.kind === graphql_1.Kind.OPERATION_DEFINITION);
|
|
25
28
|
const fragments = allAst.definitions.filter(d => d.kind === graphql_1.Kind.FRAGMENT_DEFINITION);
|
package/cjs/types.js
CHANGED
package/cjs/visitor-config.js
CHANGED
package/esm/base-java-visitor.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BaseVisitor, getBaseTypeNode, buildScalars } from '@graphql-codegen/visitor-plugin-common';
|
|
3
|
-
import { getBaseType } from '@graphql-codegen/plugin-helpers';
|
|
1
|
+
import { GraphQLObjectType, isInputObjectType, isListType, isNonNullType, isScalarType, Kind, } from 'graphql';
|
|
4
2
|
import { JAVA_SCALARS } from '@graphql-codegen/java-common';
|
|
5
|
-
import {
|
|
3
|
+
import { getBaseType } from '@graphql-codegen/plugin-helpers';
|
|
4
|
+
import { BaseVisitor, buildScalars, getBaseTypeNode } from '@graphql-codegen/visitor-plugin-common';
|
|
5
|
+
import { Imports } from './imports.js';
|
|
6
6
|
export const SCALAR_TO_WRITER_METHOD = {
|
|
7
7
|
ID: 'writeString',
|
|
8
8
|
String: 'writeString',
|
package/esm/custom-type-class.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isScalarType } from 'graphql';
|
|
2
|
-
import {
|
|
2
|
+
import { JavaDeclarationBlock } from '@graphql-codegen/java-common';
|
|
3
3
|
import { indentMultiline } from '@graphql-codegen/visitor-plugin-common';
|
|
4
|
+
import { BaseJavaVisitor } from './base-java-visitor.js';
|
|
4
5
|
import { Imports } from './imports.js';
|
|
5
|
-
import { JavaDeclarationBlock } from '@graphql-codegen/java-common';
|
|
6
6
|
const filteredScalars = ['String', 'Float', 'Int', 'Boolean'];
|
|
7
7
|
export class CustomTypeClassVisitor extends BaseJavaVisitor {
|
|
8
8
|
constructor(schema, rawConfig) {
|
package/esm/field-arguments.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Imports } from './imports.js';
|
|
2
1
|
import { oldVisit } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import { Imports } from './imports.js';
|
|
3
3
|
export function visitFieldArguments(selection, imports) {
|
|
4
4
|
if (!selection.arguments || selection.arguments.length === 0) {
|
|
5
5
|
return 'null';
|
|
@@ -10,13 +10,17 @@ export function visitFieldArguments(selection, imports) {
|
|
|
10
10
|
return oldVisit(selection, {
|
|
11
11
|
leave: {
|
|
12
12
|
Field: (node) => {
|
|
13
|
-
return (`new UnmodifiableMapBuilder<String, Object>(${node.arguments.length})` +
|
|
13
|
+
return (`new UnmodifiableMapBuilder<String, Object>(${node.arguments.length})` +
|
|
14
|
+
node.arguments.join('') +
|
|
15
|
+
'.build()');
|
|
14
16
|
},
|
|
15
17
|
Argument: (node) => {
|
|
16
18
|
return `.put("${node.name.value}", ${node.value})`;
|
|
17
19
|
},
|
|
18
20
|
ObjectValue: (node) => {
|
|
19
|
-
return `new UnmodifiableMapBuilder<String, Object>(${node.fields.length})` +
|
|
21
|
+
return (`new UnmodifiableMapBuilder<String, Object>(${node.fields.length})` +
|
|
22
|
+
node.fields.join('') +
|
|
23
|
+
'.build()');
|
|
20
24
|
},
|
|
21
25
|
ObjectField: (node) => {
|
|
22
26
|
return `.put("${node.name.value}", ${node.value})`;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isEnumType, isInputObjectType, isScalarType, Kind, } from 'graphql';
|
|
2
2
|
import { JavaDeclarationBlock } from '@graphql-codegen/java-common';
|
|
3
|
-
import {
|
|
4
|
-
import { Imports } from './imports.js';
|
|
3
|
+
import { getBaseTypeNode, indent, indentMultiline } from '@graphql-codegen/visitor-plugin-common';
|
|
5
4
|
import { BaseJavaVisitor, SCALAR_TO_WRITER_METHOD } from './base-java-visitor.js';
|
|
5
|
+
import { Imports } from './imports.js';
|
|
6
6
|
export class InputTypeVisitor extends BaseJavaVisitor {
|
|
7
7
|
constructor(_schema, rawConfig) {
|
|
8
8
|
super(_schema, rawConfig, {
|
|
@@ -18,7 +18,9 @@ export class InputTypeVisitor extends BaseJavaVisitor {
|
|
|
18
18
|
const actualType = type.isNonNull ? type.typeToUse : `Input<${type.typeToUse}>`;
|
|
19
19
|
const annotations = type.isNonNull ? [type.annotation] : [];
|
|
20
20
|
this._imports.add(Imports[type.annotation]);
|
|
21
|
-
cls.addClassMember(field.name.value, actualType, null, annotations, 'private', {
|
|
21
|
+
cls.addClassMember(field.name.value, actualType, null, annotations, 'private', {
|
|
22
|
+
final: true,
|
|
23
|
+
});
|
|
22
24
|
cls.addClassMethod(field.name.value, actualType, `return this.${field.name.value};`, [], [type.annotation], 'public');
|
|
23
25
|
});
|
|
24
26
|
}
|
|
@@ -65,7 +67,9 @@ export class InputTypeVisitor extends BaseJavaVisitor {
|
|
|
65
67
|
return `@Nonnull ${typeToUse} ${name}`;
|
|
66
68
|
}
|
|
67
69
|
if (wrapWith) {
|
|
68
|
-
return typeof wrapWith === 'function'
|
|
70
|
+
return typeof wrapWith === 'function'
|
|
71
|
+
? `${wrapWith(typeToUse)} ${name}`
|
|
72
|
+
: `${wrapWith}<${typeToUse}> ${name}`;
|
|
69
73
|
}
|
|
70
74
|
if (applyNullable) {
|
|
71
75
|
this._imports.add(Imports.Nullable);
|
|
@@ -123,7 +127,7 @@ ${allMarshallers.join('\n')}
|
|
|
123
127
|
.map(field => {
|
|
124
128
|
const isArray = field.type.kind === Kind.LIST_TYPE ||
|
|
125
129
|
(field.type.kind === Kind.NON_NULL_TYPE && field.type.type.kind === Kind.LIST_TYPE);
|
|
126
|
-
const fieldType = this.getFieldWithTypePrefix(field, v =>
|
|
130
|
+
const fieldType = this.getFieldWithTypePrefix(field, v => !isArray ? `Input<${v}>` : `Input<List<${v}>>`);
|
|
127
131
|
const isNonNull = field.type.kind === Kind.NON_NULL_TYPE;
|
|
128
132
|
return `private ${fieldType}${isNonNull ? '' : ' = Input.absent()'};`;
|
|
129
133
|
})
|
|
@@ -173,7 +177,9 @@ ${nonNullFields.join('\n')}
|
|
|
173
177
|
.implements(['InputType']);
|
|
174
178
|
this.addInputMembers(cls, node.fields);
|
|
175
179
|
this.addInputCtor(cls, className, node.fields);
|
|
176
|
-
cls.addClassMethod('builder', 'Builder', 'return new Builder();', [], [], 'public', {
|
|
180
|
+
cls.addClassMethod('builder', 'Builder', 'return new Builder();', [], [], 'public', {
|
|
181
|
+
static: true,
|
|
182
|
+
});
|
|
177
183
|
const marshallerOverride = this.buildMarshallerOverride(node.fields);
|
|
178
184
|
const builderClass = this.buildBuilderNestedClass(className, node.fields);
|
|
179
185
|
const classBlock = [marshallerOverride, '', builderClass].join('\n');
|
package/esm/operation-visitor.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { BaseJavaVisitor, SCALAR_TO_WRITER_METHOD } from './base-java-visitor.js';
|
|
2
|
-
import { indent, indentMultiline, getBaseTypeNode } from '@graphql-codegen/visitor-plugin-common';
|
|
3
|
-
import { buildPackageNameFromPath, JavaDeclarationBlock } from '@graphql-codegen/java-common';
|
|
4
|
-
import { getBaseType } from '@graphql-codegen/plugin-helpers';
|
|
5
|
-
import { print, Kind, isNonNullType, isScalarType, isEnumType, isUnionType, isInterfaceType, isObjectType, isInputObjectType, GraphQLString, isListType, } from 'graphql';
|
|
6
|
-
import { Imports } from './imports.js';
|
|
7
1
|
import { createHash } from 'crypto';
|
|
2
|
+
import { camelCase, pascalCase } from 'change-case-all';
|
|
3
|
+
import { GraphQLString, isEnumType, isInputObjectType, isInterfaceType, isListType, isNonNullType, isObjectType, isScalarType, isUnionType, Kind, print, } from 'graphql';
|
|
8
4
|
import pluralize from 'pluralize';
|
|
5
|
+
import { buildPackageNameFromPath, JavaDeclarationBlock } from '@graphql-codegen/java-common';
|
|
6
|
+
import { getBaseType } from '@graphql-codegen/plugin-helpers';
|
|
7
|
+
import { getBaseTypeNode, indent, indentMultiline, } from '@graphql-codegen/visitor-plugin-common';
|
|
8
|
+
import { BaseJavaVisitor, SCALAR_TO_WRITER_METHOD } from './base-java-visitor.js';
|
|
9
9
|
import { visitFieldArguments } from './field-arguments.js';
|
|
10
|
-
import {
|
|
10
|
+
import { Imports } from './imports.js';
|
|
11
11
|
export class OperationVisitor extends BaseJavaVisitor {
|
|
12
12
|
constructor(_schema, rawConfig, _availableFragments) {
|
|
13
13
|
super(_schema, rawConfig, {
|
|
@@ -101,7 +101,9 @@ export class OperationVisitor extends BaseJavaVisitor {
|
|
|
101
101
|
if (selection.kind === Kind.FIELD) {
|
|
102
102
|
this._imports.add(Imports.ResponseField);
|
|
103
103
|
const field = fields[selection.name.value];
|
|
104
|
-
const isObject = selection.selectionSet &&
|
|
104
|
+
const isObject = selection.selectionSet &&
|
|
105
|
+
selection.selectionSet.selections &&
|
|
106
|
+
selection.selectionSet.selections.length > 0;
|
|
105
107
|
const isNonNull = isNonNullType(field.type);
|
|
106
108
|
const fieldAnnotation = isNonNull ? 'Nonnull' : 'Nullable';
|
|
107
109
|
this._imports.add(Imports[fieldAnnotation]);
|
|
@@ -248,7 +250,9 @@ export class OperationVisitor extends BaseJavaVisitor {
|
|
|
248
250
|
})), [], 'public');
|
|
249
251
|
for (const spread of childFragmentSpread) {
|
|
250
252
|
const fragmentVarName = camelCase(spread.name);
|
|
251
|
-
fragmentsClass.addClassMember(fragmentVarName, spread.name, null, ['Nonnull'], 'private', {
|
|
253
|
+
fragmentsClass.addClassMember(fragmentVarName, spread.name, null, ['Nonnull'], 'private', {
|
|
254
|
+
final: true,
|
|
255
|
+
});
|
|
252
256
|
fragmentsClass.addClassMethod(fragmentVarName, spread.name, `return this.${fragmentVarName};`, [], ['Nonnull'], 'public', {}, []);
|
|
253
257
|
fragmentMapperClass.addClassMember(`${fragmentVarName}FieldMapper`, `${spread.name}.Mapper`, `new ${spread.name}.Mapper()`, [], 'private', { final: true });
|
|
254
258
|
}
|
|
@@ -298,7 +302,9 @@ ${childFragmentSpread
|
|
|
298
302
|
`, [], [], 'public');
|
|
299
303
|
fragmentsClass.addClassMember('$toString', 'String', null, [], 'private', { volatile: true });
|
|
300
304
|
fragmentsClass.addClassMember('$hashCode', 'int', null, [], 'private', { volatile: true });
|
|
301
|
-
fragmentsClass.addClassMember('$hashCodeMemoized', 'boolean', null, [], 'private', {
|
|
305
|
+
fragmentsClass.addClassMember('$hashCodeMemoized', 'boolean', null, [], 'private', {
|
|
306
|
+
volatile: true,
|
|
307
|
+
});
|
|
302
308
|
fragmentsClass.addClassMethod('toString', 'String', `if ($toString == null) {
|
|
303
309
|
$toString = "${fragmentsClassName}{"
|
|
304
310
|
${childFragmentSpread
|
|
@@ -374,7 +380,9 @@ ${childFragmentSpread
|
|
|
374
380
|
// Add Ctor
|
|
375
381
|
this._imports.add(Imports.Utils);
|
|
376
382
|
cls.addClassMethod(className, null, childFields
|
|
377
|
-
.map(c => `this.${c.fieldName} = ${c.isNonNull
|
|
383
|
+
.map(c => `this.${c.fieldName} = ${c.isNonNull
|
|
384
|
+
? `Utils.checkNotNull(${c.fieldName}, "${c.fieldName} == null")`
|
|
385
|
+
: c.fieldName};`)
|
|
378
386
|
.join('\n'), childFields.map(c => ({
|
|
379
387
|
name: c.fieldName,
|
|
380
388
|
type: this.getListTypeWrapped(c.className, c.rawType),
|
|
@@ -476,7 +484,9 @@ ${childFields
|
|
|
476
484
|
if (isListType(rawType)) {
|
|
477
485
|
const typeStr = this.getListTypeWrapped(childField.className, rawType.ofType);
|
|
478
486
|
const innerContent = wrapList(childField, rawType.ofType, edgeStr);
|
|
479
|
-
const inner = isListType(rawType.ofType)
|
|
487
|
+
const inner = isListType(rawType.ofType)
|
|
488
|
+
? `return listItemReader.readList(${innerContent});`
|
|
489
|
+
: innerContent;
|
|
480
490
|
return `new ResponseReader.ListReader<${typeStr}>() {
|
|
481
491
|
@Override
|
|
482
492
|
public ${typeStr} read(ResponseReader.ListItemReader listItemReader) {
|
|
@@ -598,7 +608,9 @@ ${indentMultiline(inner, 2)}
|
|
|
598
608
|
static: true,
|
|
599
609
|
final: true,
|
|
600
610
|
});
|
|
601
|
-
const possibleTypes = isObjectType(schemaType)
|
|
611
|
+
const possibleTypes = isObjectType(schemaType)
|
|
612
|
+
? [schemaType.name]
|
|
613
|
+
: this.getImplementingTypes(schemaType);
|
|
602
614
|
rootCls.addClassMember('POSSIBLE_TYPES', 'List<String>', `Collections.unmodifiableList(Arrays.asList(${possibleTypes.map(t => `"${t}"`).join(', ')}))`, [], 'public', { static: true, final: true });
|
|
603
615
|
Object.keys(dataClasses)
|
|
604
616
|
.filter(name => name !== className)
|
|
@@ -611,7 +623,9 @@ ${indentMultiline(inner, 2)}
|
|
|
611
623
|
this.visitingFragment = false;
|
|
612
624
|
const operationType = pascalCase(node.operation);
|
|
613
625
|
const operationSchemaType = this.getRootType(node.operation);
|
|
614
|
-
const className = node.name.value.endsWith(operationType)
|
|
626
|
+
const className = node.name.value.endsWith(operationType)
|
|
627
|
+
? operationType
|
|
628
|
+
: `${node.name.value}${operationType}`;
|
|
615
629
|
this._imports.add(Imports[operationType]);
|
|
616
630
|
this._imports.add(Imports.String);
|
|
617
631
|
this._imports.add(Imports.Override);
|
|
@@ -629,8 +643,14 @@ ${indentMultiline(inner, 2)}
|
|
|
629
643
|
cls.implements([
|
|
630
644
|
`${operationType}<${className}.Data, ${className}.Data, ${node.variableDefinitions.length === 0 ? 'Operation' : className}.Variables>`,
|
|
631
645
|
]);
|
|
632
|
-
cls.addClassMember('OPERATION_DEFINITION', 'String', `"${printed}"`, [], 'public', {
|
|
633
|
-
|
|
646
|
+
cls.addClassMember('OPERATION_DEFINITION', 'String', `"${printed}"`, [], 'public', {
|
|
647
|
+
static: true,
|
|
648
|
+
final: true,
|
|
649
|
+
});
|
|
650
|
+
cls.addClassMember('QUERY_DOCUMENT', 'String', 'OPERATION_DEFINITION', [], 'public', {
|
|
651
|
+
static: true,
|
|
652
|
+
final: true,
|
|
653
|
+
});
|
|
634
654
|
cls.addClassMember('OPERATION_NAME', 'OperationName', `new OperationName() {
|
|
635
655
|
@Override
|
|
636
656
|
public String name() {
|
|
@@ -638,7 +658,9 @@ ${indentMultiline(inner, 2)}
|
|
|
638
658
|
}
|
|
639
659
|
}`, [], 'public', { static: true, final: true });
|
|
640
660
|
cls.addClassMember('variables', `${node.variableDefinitions.length === 0 ? 'Operation' : className}.Variables`, null, [], 'private', { final: true });
|
|
641
|
-
cls.addClassMethod('queryDocument', `String`, `return QUERY_DOCUMENT;`, [], [], 'public', {}, [
|
|
661
|
+
cls.addClassMethod('queryDocument', `String`, `return QUERY_DOCUMENT;`, [], [], 'public', {}, [
|
|
662
|
+
'Override',
|
|
663
|
+
]);
|
|
642
664
|
cls.addClassMethod('wrapData', `${className}.Data`, `return data;`, [
|
|
643
665
|
{
|
|
644
666
|
name: 'data',
|
|
@@ -648,7 +670,9 @@ ${indentMultiline(inner, 2)}
|
|
|
648
670
|
cls.addClassMethod('variables', `${node.variableDefinitions.length === 0 ? 'Operation' : className}.Variables`, `return variables;`, [], [], 'public', {}, ['Override']);
|
|
649
671
|
cls.addClassMethod('responseFieldMapper', `ResponseFieldMapper<${className}.Data>`, `return new Data.Mapper();`, [], [], 'public', {}, ['Override']);
|
|
650
672
|
cls.addClassMethod('builder', `Builder`, `return new Builder();`, [], [], 'public', { static: true }, []);
|
|
651
|
-
cls.addClassMethod('name', `OperationName`, `return OPERATION_NAME;`, [], [], 'public', {}, [
|
|
673
|
+
cls.addClassMethod('name', `OperationName`, `return OPERATION_NAME;`, [], [], 'public', {}, [
|
|
674
|
+
'Override',
|
|
675
|
+
]);
|
|
652
676
|
cls.addClassMethod('operationId', `String`, `return "${createHash('md5').update(printed).digest('hex')}";`, [], [], 'public', {}, []);
|
|
653
677
|
this.addCtor(className, node, cls);
|
|
654
678
|
this._imports.add(Imports.Operation);
|
|
@@ -685,7 +709,11 @@ ${indentMultiline(inner, 2)}
|
|
|
685
709
|
const javaClass = this.getJavaClass(schemaType);
|
|
686
710
|
const annotation = isNonNullType(variable.type) ? 'Nullable' : 'Nonnull';
|
|
687
711
|
this._imports.add(Imports[annotation]);
|
|
688
|
-
ctorArgs.push({
|
|
712
|
+
ctorArgs.push({
|
|
713
|
+
name: variable.variable.name.value,
|
|
714
|
+
type: javaClass,
|
|
715
|
+
annotations: [annotation],
|
|
716
|
+
});
|
|
689
717
|
cls.addClassMember(variable.variable.name.value, javaClass, null, [annotation], 'private');
|
|
690
718
|
cls.addClassMethod(variable.variable.name.value, javaClass, `return ${variable.variable.name.value};`, [], [], 'public');
|
|
691
719
|
});
|
|
@@ -715,7 +743,9 @@ ${variables
|
|
|
715
743
|
this._imports.add(Imports.InputFieldMarshaller);
|
|
716
744
|
this._imports.add(Imports.InputFieldWriter);
|
|
717
745
|
this._imports.add(Imports.IOException);
|
|
718
|
-
cls.addClassMethod('marshaller', 'InputFieldMarshaller', marshallerImpl, [], [], 'public', {}, [
|
|
746
|
+
cls.addClassMethod('marshaller', 'InputFieldMarshaller', marshallerImpl, [], [], 'public', {}, [
|
|
747
|
+
'Override',
|
|
748
|
+
]);
|
|
719
749
|
return cls;
|
|
720
750
|
}
|
|
721
751
|
_getWriterMethodByType(schemaType, idAsString = false) {
|
|
@@ -727,7 +757,12 @@ ${variables
|
|
|
727
757
|
useMarshaller: false,
|
|
728
758
|
};
|
|
729
759
|
}
|
|
730
|
-
return {
|
|
760
|
+
return {
|
|
761
|
+
name: 'writeCustom',
|
|
762
|
+
checkNull: false,
|
|
763
|
+
useMarshaller: false,
|
|
764
|
+
castTo: 'ResponseField.CustomTypeField',
|
|
765
|
+
};
|
|
731
766
|
}
|
|
732
767
|
if (isInputObjectType(schemaType)) {
|
|
733
768
|
return { name: 'writeObject', checkNull: true, useMarshaller: true };
|
|
@@ -768,7 +803,9 @@ ${variables
|
|
|
768
803
|
const nonNullChecks = variables
|
|
769
804
|
.filter(f => isNonNullType(f))
|
|
770
805
|
.map(f => `Utils.checkNotNull(${f.variable.name.value}, "${f.variable.name.value} == null");`);
|
|
771
|
-
const returnStatement = `return new ${parentClassName}(${variables
|
|
806
|
+
const returnStatement = `return new ${parentClassName}(${variables
|
|
807
|
+
.map(v => v.variable.name.value)
|
|
808
|
+
.join(', ')});`;
|
|
772
809
|
cls.addClassMethod('build', parentClassName, `${[...nonNullChecks, returnStatement].join('\n')}`, [], [], 'public');
|
|
773
810
|
return cls;
|
|
774
811
|
}
|
package/esm/plugin.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { oldVisit } from '@graphql-codegen/plugin-helpers';
|
|
2
1
|
import { concatAST, Kind } from 'graphql';
|
|
2
|
+
import { oldVisit } from '@graphql-codegen/plugin-helpers';
|
|
3
|
+
import { CustomTypeClassVisitor } from './custom-type-class.js';
|
|
4
|
+
import { FileType } from './file-type.js';
|
|
3
5
|
import { InputTypeVisitor } from './input-type-visitor.js';
|
|
4
6
|
import { OperationVisitor } from './operation-visitor.js';
|
|
5
|
-
import { FileType } from './file-type.js';
|
|
6
|
-
import { CustomTypeClassVisitor } from './custom-type-class.js';
|
|
7
7
|
export const plugin = (schema, documents, config) => {
|
|
8
8
|
const allAst = concatAST(documents.map(v => v.document));
|
|
9
9
|
const allFragments = [
|
|
@@ -39,6 +39,7 @@ export const plugin = (schema, documents, config) => {
|
|
|
39
39
|
const imports = visitor.getImports();
|
|
40
40
|
return {
|
|
41
41
|
prepend: [`package ${visitor.getPackage()};\n`, ...imports],
|
|
42
|
-
content: '\n' +
|
|
42
|
+
content: '\n' +
|
|
43
|
+
[...visitResult.definitions.filter(a => a && typeof a === 'string'), additionalContent].join('\n'),
|
|
43
44
|
};
|
|
44
45
|
};
|
package/esm/preset.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { visit, concatAST, Kind, } from 'graphql';
|
|
2
1
|
import { join } from 'path';
|
|
3
|
-
import { FileType } from './file-type.js';
|
|
4
2
|
import { pascalCase } from 'change-case-all';
|
|
3
|
+
import { concatAST, Kind, visit, } from 'graphql';
|
|
4
|
+
import { FileType } from './file-type.js';
|
|
5
5
|
const packageNameToDirectory = (packageName) => {
|
|
6
6
|
return `./${packageName.split('.').join('/')}/`;
|
|
7
7
|
};
|
|
@@ -16,7 +16,10 @@ export const preset = {
|
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
18
|
});
|
|
19
|
-
const inputTypesDocumentNode = {
|
|
19
|
+
const inputTypesDocumentNode = {
|
|
20
|
+
kind: Kind.DOCUMENT,
|
|
21
|
+
definitions: inputTypesAst,
|
|
22
|
+
};
|
|
20
23
|
const allAst = concatAST(options.documents.map(v => v.document));
|
|
21
24
|
const operationsAst = allAst.definitions.filter(d => d.kind === Kind.OPERATION_DEFINITION);
|
|
22
25
|
const fragments = allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION);
|
package/esm/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/visitor-config.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/java-apollo-android",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha-20230524083052-08ce957b4",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating Java classes for Apollo-Android",
|
|
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": "
|
|
10
|
-
"@graphql-codegen/plugin-helpers": "^
|
|
9
|
+
"@graphql-codegen/java-common": "3.0.0-alpha-20230524083052-08ce957b4",
|
|
10
|
+
"@graphql-codegen/plugin-helpers": "^3.0.0",
|
|
11
11
|
"@graphql-codegen/visitor-plugin-common": "2.13.1",
|
|
12
12
|
"auto-bind": "~4.0.0",
|
|
13
|
-
"change-case-all": "1.0.
|
|
13
|
+
"change-case-all": "1.0.15",
|
|
14
14
|
"pluralize": "^8.0.0",
|
|
15
15
|
"tslib": "~2.4.0"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "https://github.com/dotansimha/graphql-code-generator.git",
|
|
19
|
+
"url": "https://github.com/dotansimha/graphql-code-generator-community.git",
|
|
20
20
|
"directory": "packages/plugins/java/apollo-android"
|
|
21
21
|
},
|
|
22
22
|
"license": "MIT",
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">= 16.0.0"
|
|
25
|
+
},
|
|
23
26
|
"main": "cjs/index.js",
|
|
24
27
|
"module": "esm/index.js",
|
|
25
28
|
"typings": "typings/index.d.ts",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { GraphQLInterfaceType, GraphQLNamedType, GraphQLOutputType, GraphQLSchema, TypeNode } from 'graphql';
|
|
1
2
|
import { BaseVisitor } from '@graphql-codegen/visitor-plugin-common';
|
|
2
3
|
import { JavaApolloAndroidPluginConfig } from './plugin.cjs';
|
|
3
|
-
import { GraphQLSchema, GraphQLNamedType, GraphQLOutputType, TypeNode, GraphQLInterfaceType } from 'graphql';
|
|
4
|
-
import { VisitorConfig } from './visitor-config.cjs';
|
|
5
4
|
import { ImportsSet, TransformedType } from './types.cjs';
|
|
5
|
+
import { VisitorConfig } from './visitor-config.cjs';
|
|
6
6
|
export declare const SCALAR_TO_WRITER_METHOD: {
|
|
7
7
|
ID: string;
|
|
8
8
|
String: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { GraphQLInterfaceType, GraphQLNamedType, GraphQLOutputType, GraphQLSchema, TypeNode } from 'graphql';
|
|
1
2
|
import { BaseVisitor } from '@graphql-codegen/visitor-plugin-common';
|
|
2
3
|
import { JavaApolloAndroidPluginConfig } from './plugin.js';
|
|
3
|
-
import { GraphQLSchema, GraphQLNamedType, GraphQLOutputType, TypeNode, GraphQLInterfaceType } from 'graphql';
|
|
4
|
-
import { VisitorConfig } from './visitor-config.js';
|
|
5
4
|
import { ImportsSet, TransformedType } from './types.js';
|
|
5
|
+
import { VisitorConfig } from './visitor-config.js';
|
|
6
6
|
export declare const SCALAR_TO_WRITER_METHOD: {
|
|
7
7
|
ID: string;
|
|
8
8
|
String: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
2
|
import { BaseJavaVisitor } from './base-java-visitor.cjs';
|
|
3
|
-
import { VisitorConfig } from './visitor-config.cjs';
|
|
4
3
|
import { JavaApolloAndroidPluginConfig } from './plugin.cjs';
|
|
4
|
+
import { VisitorConfig } from './visitor-config.cjs';
|
|
5
5
|
export declare class CustomTypeClassVisitor extends BaseJavaVisitor<VisitorConfig> {
|
|
6
6
|
constructor(schema: GraphQLSchema, rawConfig: JavaApolloAndroidPluginConfig);
|
|
7
7
|
private extract;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
2
|
import { BaseJavaVisitor } from './base-java-visitor.js';
|
|
3
|
-
import { VisitorConfig } from './visitor-config.js';
|
|
4
3
|
import { JavaApolloAndroidPluginConfig } from './plugin.js';
|
|
4
|
+
import { VisitorConfig } from './visitor-config.js';
|
|
5
5
|
export declare class CustomTypeClassVisitor extends BaseJavaVisitor<VisitorConfig> {
|
|
6
6
|
constructor(schema: GraphQLSchema, rawConfig: JavaApolloAndroidPluginConfig);
|
|
7
7
|
private extract;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { InputObjectTypeDefinitionNode, GraphQLSchema, InputValueDefinitionNode, VariableDefinitionNode } from 'graphql';
|
|
1
|
+
import { GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, VariableDefinitionNode } from 'graphql';
|
|
3
2
|
import { BaseJavaVisitor } from './base-java-visitor.cjs';
|
|
3
|
+
import { JavaApolloAndroidPluginConfig } from './plugin.cjs';
|
|
4
4
|
import { VisitorConfig } from './visitor-config.cjs';
|
|
5
5
|
export declare class InputTypeVisitor extends BaseJavaVisitor<VisitorConfig> {
|
|
6
6
|
constructor(_schema: GraphQLSchema, rawConfig: JavaApolloAndroidPluginConfig);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { InputObjectTypeDefinitionNode, GraphQLSchema, InputValueDefinitionNode, VariableDefinitionNode } from 'graphql';
|
|
1
|
+
import { GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, VariableDefinitionNode } from 'graphql';
|
|
3
2
|
import { BaseJavaVisitor } from './base-java-visitor.js';
|
|
3
|
+
import { JavaApolloAndroidPluginConfig } from './plugin.js';
|
|
4
4
|
import { VisitorConfig } from './visitor-config.js';
|
|
5
5
|
export declare class InputTypeVisitor extends BaseJavaVisitor<VisitorConfig> {
|
|
6
6
|
constructor(_schema: GraphQLSchema, rawConfig: JavaApolloAndroidPluginConfig);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
|
|
1
|
+
import { FragmentDefinitionNode, GraphQLNamedType, GraphQLOutputType, GraphQLSchema, OperationDefinitionNode, SelectionNode } from 'graphql';
|
|
3
2
|
import { JavaDeclarationBlock } from '@graphql-codegen/java-common';
|
|
4
|
-
import {
|
|
3
|
+
import { LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
|
|
4
|
+
import { BaseJavaVisitor } from './base-java-visitor.cjs';
|
|
5
5
|
import { JavaApolloAndroidPluginConfig } from './plugin.cjs';
|
|
6
6
|
import { VisitorConfig } from './visitor-config.cjs';
|
|
7
7
|
export interface ChildField {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
|
|
1
|
+
import { FragmentDefinitionNode, GraphQLNamedType, GraphQLOutputType, GraphQLSchema, OperationDefinitionNode, SelectionNode } from 'graphql';
|
|
3
2
|
import { JavaDeclarationBlock } from '@graphql-codegen/java-common';
|
|
4
|
-
import {
|
|
3
|
+
import { LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
|
|
4
|
+
import { BaseJavaVisitor } from './base-java-visitor.js';
|
|
5
5
|
import { JavaApolloAndroidPluginConfig } from './plugin.js';
|
|
6
6
|
import { VisitorConfig } from './visitor-config.js';
|
|
7
7
|
export interface ChildField {
|
package/typings/types.d.cts
CHANGED
package/typings/types.d.ts
CHANGED