@graphql-codegen/java-apollo-android 2.2.9 → 2.2.12-alpha-b9cc98b7a.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 (3) hide show
  1. package/index.js +33 -51
  2. package/index.mjs +33 -51
  3. package/package.json +3 -3
package/index.js CHANGED
@@ -223,15 +223,13 @@ class InputTypeVisitor extends BaseJavaVisitor {
223
223
  this._imports.add(Imports.Nonnull);
224
224
  return `@Nonnull ${typeToUse} ${name}`;
225
225
  }
226
- else if (wrapWith) {
226
+ if (wrapWith) {
227
227
  return typeof wrapWith === 'function' ? `${wrapWith(typeToUse)} ${name}` : `${wrapWith}<${typeToUse}> ${name}`;
228
228
  }
229
- else {
230
- if (applyNullable) {
231
- this._imports.add(Imports.Nullable);
232
- }
233
- return `${applyNullable ? '@Nullable ' : ''}${typeToUse} ${name}`;
229
+ if (applyNullable) {
230
+ this._imports.add(Imports.Nullable);
234
231
  }
232
+ return `${applyNullable ? '@Nullable ' : ''}${typeToUse} ${name}`;
235
233
  }
236
234
  buildFieldsMarshaller(field) {
237
235
  const isNonNull = field.type.kind === graphql.Kind.NON_NULL_TYPE;
@@ -258,11 +256,9 @@ class InputTypeVisitor extends BaseJavaVisitor {
258
256
  if (isNonNull) {
259
257
  return result;
260
258
  }
261
- else {
262
- return visitorPluginCommon.indentMultiline(`if(${field.name.value}.defined) {
259
+ return visitorPluginCommon.indentMultiline(`if(${field.name.value}.defined) {
263
260
  ${visitorPluginCommon.indentMultiline(result)}
264
261
  }`);
265
- }
266
262
  }
267
263
  buildMarshallerOverride(fields) {
268
264
  this._imports.add(Imports.Override);
@@ -427,15 +423,13 @@ class OperationVisitor extends BaseJavaVisitor {
427
423
  if (operation === 'query') {
428
424
  return this._schema.getQueryType();
429
425
  }
430
- else if (operation === 'mutation') {
426
+ if (operation === 'mutation') {
431
427
  return this._schema.getMutationType();
432
428
  }
433
- else if (operation === 'subscription') {
429
+ if (operation === 'subscription') {
434
430
  return this._schema.getSubscriptionType();
435
431
  }
436
- else {
437
- return null;
438
- }
432
+ return null;
439
433
  }
440
434
  createUniqueClassName(inUse, name, count = 0) {
441
435
  const possibleNewName = count === 0 ? name : `${name}${count}`;
@@ -822,25 +816,21 @@ ${childFields
822
816
  if (baseType.name === 'String') {
823
817
  return { fn: `readString` };
824
818
  }
825
- else if (baseType.name === 'Int') {
819
+ if (baseType.name === 'Int') {
826
820
  return { fn: `readInt` };
827
821
  }
828
- else if (baseType.name === 'Float') {
822
+ if (baseType.name === 'Float') {
829
823
  return { fn: `readDouble` };
830
824
  }
831
- else if (baseType.name === 'Boolean') {
825
+ if (baseType.name === 'Boolean') {
832
826
  return { fn: `readBoolean` };
833
827
  }
834
- else {
835
- return { fn: `readCustomType`, custom: true };
836
- }
828
+ return { fn: `readCustomType`, custom: true };
837
829
  }
838
- else if (graphql.isEnumType(baseType)) {
830
+ if (graphql.isEnumType(baseType)) {
839
831
  return { fn: `readString` };
840
832
  }
841
- else {
842
- return { fn: `readObject`, object: baseType.name };
843
- }
833
+ return { fn: `readObject`, object: baseType.name };
844
834
  }
845
835
  buildMapperClass(parentClassName, childFields) {
846
836
  const wrapList = (childField, rawType, edgeStr) => {
@@ -872,7 +862,7 @@ ${visitorPluginCommon.indentMultiline(inner, 2)}
872
862
  }
873
863
  });`;
874
864
  }
875
- else if (f.isList) {
865
+ if (f.isList) {
876
866
  const listReader = readerFn.object
877
867
  ? `return listItemReader.${readerFn.fn}(new ResponseReader.ObjectReader<Item>() {
878
868
  @Override
@@ -884,7 +874,7 @@ ${visitorPluginCommon.indentMultiline(inner, 2)}
884
874
  const wrappedList = wrapList(f, f.rawType, listReader);
885
875
  return `${varDec} reader.readList($responseFields[${index}], ${wrappedList});`;
886
876
  }
887
- else if (readerFn.object) {
877
+ if (readerFn.object) {
888
878
  return `${varDec} reader.readObject($responseFields[${index}], new ResponseReader.ObjectReader<${f.className}>() {
889
879
  @Override
890
880
  public ${f.className} read(ResponseReader reader) {
@@ -892,9 +882,7 @@ ${visitorPluginCommon.indentMultiline(inner, 2)}
892
882
  }
893
883
  });`;
894
884
  }
895
- else {
896
- return `${varDec} reader.${readerFn.fn}(${readerFn.custom ? '(ResponseField.CustomTypeField) ' : ''}$responseFields[${index}]);`;
897
- }
885
+ return `${varDec} reader.${readerFn.fn}(${readerFn.custom ? '(ResponseField.CustomTypeField) ' : ''}$responseFields[${index}]);`;
898
886
  });
899
887
  const mapperImpl = [
900
888
  ...mapperBody,
@@ -924,33 +912,29 @@ ${visitorPluginCommon.indentMultiline(inner, 2)}
924
912
  if (graphql.isListType(baseType)) {
925
913
  return { fn: `forList` };
926
914
  }
927
- else if (graphql.isNonNullType(baseType)) {
915
+ if (graphql.isNonNullType(baseType)) {
928
916
  return this._resolveResponseFieldMethodForBaseType(baseType.ofType);
929
917
  }
930
- else if (graphql.isScalarType(baseType)) {
918
+ if (graphql.isScalarType(baseType)) {
931
919
  if (baseType.name === 'String') {
932
920
  return { fn: `forString` };
933
921
  }
934
- else if (baseType.name === 'Int') {
922
+ if (baseType.name === 'Int') {
935
923
  return { fn: `forInt` };
936
924
  }
937
- else if (baseType.name === 'Float') {
925
+ if (baseType.name === 'Float') {
938
926
  return { fn: `forDouble` };
939
927
  }
940
- else if (baseType.name === 'Boolean') {
928
+ if (baseType.name === 'Boolean') {
941
929
  return { fn: `forBoolean` };
942
930
  }
943
- else {
944
- this._imports.add(`${this.config.typePackage}.CustomType`);
945
- return { fn: `forCustomType`, custom: true };
946
- }
931
+ this._imports.add(`${this.config.typePackage}.CustomType`);
932
+ return { fn: `forCustomType`, custom: true };
947
933
  }
948
- else if (graphql.isEnumType(baseType)) {
934
+ if (graphql.isEnumType(baseType)) {
949
935
  return { fn: `forEnum` };
950
936
  }
951
- else {
952
- return { fn: `forObject` };
953
- }
937
+ return { fn: `forObject` };
954
938
  }
955
939
  FragmentDefinition(node) {
956
940
  this.visitingFragment = true;
@@ -1109,13 +1093,13 @@ ${variables
1109
1093
  }
1110
1094
  return { name: 'writeCustom', checkNull: false, useMarshaller: false, castTo: 'ResponseField.CustomTypeField' };
1111
1095
  }
1112
- else if (graphql.isInputObjectType(schemaType)) {
1096
+ if (graphql.isInputObjectType(schemaType)) {
1113
1097
  return { name: 'writeObject', checkNull: true, useMarshaller: true };
1114
1098
  }
1115
- else if (graphql.isEnumType(schemaType)) {
1099
+ if (graphql.isEnumType(schemaType)) {
1116
1100
  return { name: 'writeString', checkNull: false, useMarshaller: false };
1117
1101
  }
1118
- else if (graphql.isObjectType(schemaType) || graphql.isInterfaceType(schemaType)) {
1102
+ if (graphql.isObjectType(schemaType) || graphql.isInterfaceType(schemaType)) {
1119
1103
  return { name: 'writeObject', checkNull: true, useMarshaller: true };
1120
1104
  }
1121
1105
  return { name: 'writeString', useMarshaller: false, checkNull: false };
@@ -1177,12 +1161,10 @@ class CustomTypeClassVisitor extends BaseJavaVisitor {
1177
1161
  importFrom: Imports[name] || null,
1178
1162
  };
1179
1163
  }
1180
- else {
1181
- return {
1182
- className: name.substring(lastIndex + 1),
1183
- importFrom: name,
1184
- };
1185
- }
1164
+ return {
1165
+ className: name.substring(lastIndex + 1),
1166
+ importFrom: name,
1167
+ };
1186
1168
  }
1187
1169
  additionalContent() {
1188
1170
  this._imports.add(Imports.ScalarType);
package/index.mjs CHANGED
@@ -217,15 +217,13 @@ class InputTypeVisitor extends BaseJavaVisitor {
217
217
  this._imports.add(Imports.Nonnull);
218
218
  return `@Nonnull ${typeToUse} ${name}`;
219
219
  }
220
- else if (wrapWith) {
220
+ if (wrapWith) {
221
221
  return typeof wrapWith === 'function' ? `${wrapWith(typeToUse)} ${name}` : `${wrapWith}<${typeToUse}> ${name}`;
222
222
  }
223
- else {
224
- if (applyNullable) {
225
- this._imports.add(Imports.Nullable);
226
- }
227
- return `${applyNullable ? '@Nullable ' : ''}${typeToUse} ${name}`;
223
+ if (applyNullable) {
224
+ this._imports.add(Imports.Nullable);
228
225
  }
226
+ return `${applyNullable ? '@Nullable ' : ''}${typeToUse} ${name}`;
229
227
  }
230
228
  buildFieldsMarshaller(field) {
231
229
  const isNonNull = field.type.kind === Kind.NON_NULL_TYPE;
@@ -252,11 +250,9 @@ class InputTypeVisitor extends BaseJavaVisitor {
252
250
  if (isNonNull) {
253
251
  return result;
254
252
  }
255
- else {
256
- return indentMultiline(`if(${field.name.value}.defined) {
253
+ return indentMultiline(`if(${field.name.value}.defined) {
257
254
  ${indentMultiline(result)}
258
255
  }`);
259
- }
260
256
  }
261
257
  buildMarshallerOverride(fields) {
262
258
  this._imports.add(Imports.Override);
@@ -421,15 +417,13 @@ class OperationVisitor extends BaseJavaVisitor {
421
417
  if (operation === 'query') {
422
418
  return this._schema.getQueryType();
423
419
  }
424
- else if (operation === 'mutation') {
420
+ if (operation === 'mutation') {
425
421
  return this._schema.getMutationType();
426
422
  }
427
- else if (operation === 'subscription') {
423
+ if (operation === 'subscription') {
428
424
  return this._schema.getSubscriptionType();
429
425
  }
430
- else {
431
- return null;
432
- }
426
+ return null;
433
427
  }
434
428
  createUniqueClassName(inUse, name, count = 0) {
435
429
  const possibleNewName = count === 0 ? name : `${name}${count}`;
@@ -816,25 +810,21 @@ ${childFields
816
810
  if (baseType.name === 'String') {
817
811
  return { fn: `readString` };
818
812
  }
819
- else if (baseType.name === 'Int') {
813
+ if (baseType.name === 'Int') {
820
814
  return { fn: `readInt` };
821
815
  }
822
- else if (baseType.name === 'Float') {
816
+ if (baseType.name === 'Float') {
823
817
  return { fn: `readDouble` };
824
818
  }
825
- else if (baseType.name === 'Boolean') {
819
+ if (baseType.name === 'Boolean') {
826
820
  return { fn: `readBoolean` };
827
821
  }
828
- else {
829
- return { fn: `readCustomType`, custom: true };
830
- }
822
+ return { fn: `readCustomType`, custom: true };
831
823
  }
832
- else if (isEnumType(baseType)) {
824
+ if (isEnumType(baseType)) {
833
825
  return { fn: `readString` };
834
826
  }
835
- else {
836
- return { fn: `readObject`, object: baseType.name };
837
- }
827
+ return { fn: `readObject`, object: baseType.name };
838
828
  }
839
829
  buildMapperClass(parentClassName, childFields) {
840
830
  const wrapList = (childField, rawType, edgeStr) => {
@@ -866,7 +856,7 @@ ${indentMultiline(inner, 2)}
866
856
  }
867
857
  });`;
868
858
  }
869
- else if (f.isList) {
859
+ if (f.isList) {
870
860
  const listReader = readerFn.object
871
861
  ? `return listItemReader.${readerFn.fn}(new ResponseReader.ObjectReader<Item>() {
872
862
  @Override
@@ -878,7 +868,7 @@ ${indentMultiline(inner, 2)}
878
868
  const wrappedList = wrapList(f, f.rawType, listReader);
879
869
  return `${varDec} reader.readList($responseFields[${index}], ${wrappedList});`;
880
870
  }
881
- else if (readerFn.object) {
871
+ if (readerFn.object) {
882
872
  return `${varDec} reader.readObject($responseFields[${index}], new ResponseReader.ObjectReader<${f.className}>() {
883
873
  @Override
884
874
  public ${f.className} read(ResponseReader reader) {
@@ -886,9 +876,7 @@ ${indentMultiline(inner, 2)}
886
876
  }
887
877
  });`;
888
878
  }
889
- else {
890
- return `${varDec} reader.${readerFn.fn}(${readerFn.custom ? '(ResponseField.CustomTypeField) ' : ''}$responseFields[${index}]);`;
891
- }
879
+ return `${varDec} reader.${readerFn.fn}(${readerFn.custom ? '(ResponseField.CustomTypeField) ' : ''}$responseFields[${index}]);`;
892
880
  });
893
881
  const mapperImpl = [
894
882
  ...mapperBody,
@@ -918,33 +906,29 @@ ${indentMultiline(inner, 2)}
918
906
  if (isListType(baseType)) {
919
907
  return { fn: `forList` };
920
908
  }
921
- else if (isNonNullType(baseType)) {
909
+ if (isNonNullType(baseType)) {
922
910
  return this._resolveResponseFieldMethodForBaseType(baseType.ofType);
923
911
  }
924
- else if (isScalarType(baseType)) {
912
+ if (isScalarType(baseType)) {
925
913
  if (baseType.name === 'String') {
926
914
  return { fn: `forString` };
927
915
  }
928
- else if (baseType.name === 'Int') {
916
+ if (baseType.name === 'Int') {
929
917
  return { fn: `forInt` };
930
918
  }
931
- else if (baseType.name === 'Float') {
919
+ if (baseType.name === 'Float') {
932
920
  return { fn: `forDouble` };
933
921
  }
934
- else if (baseType.name === 'Boolean') {
922
+ if (baseType.name === 'Boolean') {
935
923
  return { fn: `forBoolean` };
936
924
  }
937
- else {
938
- this._imports.add(`${this.config.typePackage}.CustomType`);
939
- return { fn: `forCustomType`, custom: true };
940
- }
925
+ this._imports.add(`${this.config.typePackage}.CustomType`);
926
+ return { fn: `forCustomType`, custom: true };
941
927
  }
942
- else if (isEnumType(baseType)) {
928
+ if (isEnumType(baseType)) {
943
929
  return { fn: `forEnum` };
944
930
  }
945
- else {
946
- return { fn: `forObject` };
947
- }
931
+ return { fn: `forObject` };
948
932
  }
949
933
  FragmentDefinition(node) {
950
934
  this.visitingFragment = true;
@@ -1103,13 +1087,13 @@ ${variables
1103
1087
  }
1104
1088
  return { name: 'writeCustom', checkNull: false, useMarshaller: false, castTo: 'ResponseField.CustomTypeField' };
1105
1089
  }
1106
- else if (isInputObjectType(schemaType)) {
1090
+ if (isInputObjectType(schemaType)) {
1107
1091
  return { name: 'writeObject', checkNull: true, useMarshaller: true };
1108
1092
  }
1109
- else if (isEnumType(schemaType)) {
1093
+ if (isEnumType(schemaType)) {
1110
1094
  return { name: 'writeString', checkNull: false, useMarshaller: false };
1111
1095
  }
1112
- else if (isObjectType(schemaType) || isInterfaceType(schemaType)) {
1096
+ if (isObjectType(schemaType) || isInterfaceType(schemaType)) {
1113
1097
  return { name: 'writeObject', checkNull: true, useMarshaller: true };
1114
1098
  }
1115
1099
  return { name: 'writeString', useMarshaller: false, checkNull: false };
@@ -1171,12 +1155,10 @@ class CustomTypeClassVisitor extends BaseJavaVisitor {
1171
1155
  importFrom: Imports[name] || null,
1172
1156
  };
1173
1157
  }
1174
- else {
1175
- return {
1176
- className: name.substring(lastIndex + 1),
1177
- importFrom: name,
1178
- };
1179
- }
1158
+ return {
1159
+ className: name.substring(lastIndex + 1),
1160
+ importFrom: name,
1161
+ };
1180
1162
  }
1181
1163
  additionalContent() {
1182
1164
  this._imports.add(Imports.ScalarType);
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@graphql-codegen/java-apollo-android",
3
- "version": "2.2.9",
3
+ "version": "2.2.12-alpha-b9cc98b7a.0",
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": "^2.1.16",
9
+ "@graphql-codegen/java-common": "^2.1.19-alpha-b9cc98b7a.0",
10
10
  "@graphql-codegen/plugin-helpers": "^2.4.0",
11
- "@graphql-codegen/visitor-plugin-common": "2.7.5",
11
+ "@graphql-codegen/visitor-plugin-common": "2.9.0-alpha-b9cc98b7a.0",
12
12
  "auto-bind": "~4.0.0",
13
13
  "change-case-all": "1.0.14",
14
14
  "pluralize": "^8.0.0",