From 968a7550e2b3299b7d589d52ea263b327f1af57b Mon Sep 17 00:00:00 2001 From: Tyler Roach Date: Wed, 16 Aug 2023 16:17:23 -0400 Subject: [PATCH 01/30] Android CSS and LL support --- .../src/configs/java-config.ts | 33 +++- .../src/languages/java-declaration-block.ts | 3 +- .../appsync-modelgen-plugin/src/preset.ts | 77 +++++++-- .../src/visitors/appsync-java-visitor.ts | 153 +++++++++++++++++- 4 files changed, 243 insertions(+), 23 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/configs/java-config.ts b/packages/appsync-modelgen-plugin/src/configs/java-config.ts index be19d1313..ef6a585a0 100644 --- a/packages/appsync-modelgen-plugin/src/configs/java-config.ts +++ b/packages/appsync-modelgen-plugin/src/configs/java-config.ts @@ -1,7 +1,10 @@ import { CodeGenConnectionType } from '../utils/process-connections'; -// Name of the Generated Java Package -export const GENERATED_PACKAGE_NAME = 'com.amplifyframework.datastore.generated.model'; +// Name of the Generated Java Package for DataStore category +export const GENERATED_DATASTORE_PACKAGE_NAME = 'com.amplifyframework.datastore.generated.model'; + +// Name of the Generated Java Package for API category +export const GENERATED_API_PACKAGE_NAME = 'com.amplifyframework.api.generated.model'; // Name of the Class Loader package export const LOADER_CLASS_NAME = 'AmplifyModelProvider'; @@ -10,6 +13,8 @@ const JAVA_UTIL_PACKAGES = ['java.util.List', 'java.util.UUID', 'java.util.Objec const ANDROIDX_CORE_PACKAGES = ['androidx.core.util.ObjectsCompat']; +const ANDROIDX_ANNOTATION_PACKAGES = ['androidx.annotation.NonNull', 'androidx.annotation.Nullable'] + const AMPLIFY_FRAMEWORK_PACKAGES = [ 'com.amplifyframework.core.model.Model', 'com.amplifyframework.core.model.annotations.Index', @@ -83,3 +88,27 @@ export const CONNECTION_RELATIONSHIP_IMPORTS: { [key in CodeGenConnectionType]: }; export const CUSTOM_PRIMARY_KEY_IMPORT_PACKAGE = 'com.amplifyframework.core.model.ModelIdentifier'; + +export const LAZY_MODEL_IMPORT_PACKAGE = 'com.amplifyframework.core.model.LazyModel' + +export const CONNECTION_RELATIONSHIP_LAZY_LOAD_IMPORTS: { [key in CodeGenConnectionType]: string } = { + BELONGS_TO: LAZY_MODEL_IMPORT_PACKAGE, + HAS_MANY: 'com.amplifyframework.core.model.LazyList', + HAS_ONE: LAZY_MODEL_IMPORT_PACKAGE, +}; + +export const MODEL_PATH_IMPORT_PACKAGES = [ + 'com.amplifyframework.core.model.ModelPath', + 'com.amplifyframework.core.model.PropertyPath' +] + +export function getModelPathClassImports(): string[] { + return [ + ...ANDROIDX_ANNOTATION_PACKAGES, + '', + ...MODEL_PATH_IMPORT_PACKAGES, + '', + ]; +} + +export const MODEL_PATH_CLASS_IMPORT_PACKAGES = getModelPathClassImports(); diff --git a/packages/appsync-modelgen-plugin/src/languages/java-declaration-block.ts b/packages/appsync-modelgen-plugin/src/languages/java-declaration-block.ts index dc140e7fc..9659d5c8a 100644 --- a/packages/appsync-modelgen-plugin/src/languages/java-declaration-block.ts +++ b/packages/appsync-modelgen-plugin/src/languages/java-declaration-block.ts @@ -3,7 +3,7 @@ import { StringValueNode, NameNode } from 'graphql'; import stripIndent from 'strip-indent'; // Todo: PR to @graphql-codegen/java-common to support method exceptions and comment -export type Access = 'private' | 'public' | 'protected'; +export type Access = 'private' | 'public' | 'protected' | ''; export type Kind = 'class' | 'interface' | 'enum'; export type MemberFlags = { transient?: boolean; @@ -143,6 +143,7 @@ export class JavaDeclarationBlock { method.flags.final ? 'final' : null, method.flags.transient ? 'transient' : null, method.flags.volatile ? 'volatile' : null, + method.flags.synchronized ? 'synchronized' : null, ...(method.returnTypeAnnotations || []).map(annotation => `@${annotation}`), method.returnType, method.name, diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index 8d1f69d52..e41a1efab 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -2,7 +2,7 @@ import { Types } from '@graphql-codegen/plugin-helpers'; import { Kind, TypeDefinitionNode } from 'graphql'; import { join } from 'path'; import { JAVA_SCALAR_MAP, SWIFT_SCALAR_MAP, TYPESCRIPT_SCALAR_MAP, DART_SCALAR_MAP, METADATA_SCALAR_MAP } from './scalars'; -import { LOADER_CLASS_NAME, GENERATED_PACKAGE_NAME } from './configs/java-config'; +import { LOADER_CLASS_NAME, GENERATED_API_PACKAGE_NAME, GENERATED_DATASTORE_PACKAGE_NAME } from './configs/java-config'; import { graphqlName, toUpper } from 'graphql-transformer-common'; const APPSYNC_DATA_STORE_CODEGEN_TARGETS = ['java', 'swift', 'javascript', 'typescript', 'dart']; @@ -33,29 +33,80 @@ const generateJavaPreset = ( models: TypeDefinitionNode[], ): Types.GenerateOptions[] => { const config: Types.GenerateOptions[] = []; - const modelFolder = options.config.overrideOutputDir ? [options.config.overrideOutputDir] : [options.baseOutputDir, ...GENERATED_PACKAGE_NAME.split('.')]; + const dataStoreModelFolder = options.config.overrideOutputDir ? [options.config.overrideOutputDir] : [options.baseOutputDir, ...GENERATED_DATASTORE_PACKAGE_NAME.split('.')]; models.forEach(model => { + + // Android splits models into 2 different packages.. 1 for DataStore and 1 for API + // generateModelsForLazyLoadAndCustomSelectionSet is used to decide whether or not we create the codegen for the API category + + // Model const modelName = model.name.value; config.push({ ...options, - filename: join(...modelFolder, `${modelName}.java`), + filename: join(...dataStoreModelFolder, `${modelName}.java`), config: { ...options.config, + generateModelsForLazyLoadAndCustomSelectionSet: false, // override value to output DataStore models scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, selectedType: modelName, }, }); - }); - // Class loader - config.push({ - ...options, - filename: join(...modelFolder, `${LOADER_CLASS_NAME}.java`), - config: { - ...options.config, - scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, - generate: 'loader', - }, + // Class loader + config.push({ + ...options, + filename: join(...dataStoreModelFolder, `${LOADER_CLASS_NAME}.java`), + config: { + ...options.config, + generateModelsForLazyLoadAndCustomSelectionSet: false, // override value to output DataStore models + scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, + generate: 'loader', + }, + }); + + if (options.config.generateModelsForLazyLoadAndCustomSelectionSet) { + + // If an overrideOutputDir is provided, we palce all API codegen in an 'api' folder to prevent collisions with DataStore models + const apiModelFolder = options.config.overrideOutputDir ? + [options.config.overrideOutputDir, "api"] : + [options.baseOutputDir, ...GENERATED_API_PACKAGE_NAME.split('.')]; + + // Model + const modelName = model.name.value; + config.push({ + ...options, + filename: join(...apiModelFolder, `${modelName}.java`), + config: { + ...options.config, + scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, + selectedType: modelName, + }, + }); + + // ModelPath + const modelPathName = modelName + "Path"; + config.push({ + ...options, + filename: join(...apiModelFolder, `${modelPathName}.java`), + config: { + ...options.config, + scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, + generate: 'metadata', + selectedType: modelName, + }, + }); + + // Class loader + config.push({ + ...options, + filename: join(...apiModelFolder, `${LOADER_CLASS_NAME}.java`), + config: { + ...options.config, + scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, + generate: 'loader', + }, + }); + } }); return config; diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index d9d5541ee..c4d5a69c0 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -3,17 +3,28 @@ import { camelCase, constantCase, pascalCase } from 'change-case'; import dedent from 'ts-dedent'; import { MODEL_CLASS_IMPORT_PACKAGES, - GENERATED_PACKAGE_NAME, + MODEL_PATH_CLASS_IMPORT_PACKAGES, + GENERATED_API_PACKAGE_NAME, + GENERATED_DATASTORE_PACKAGE_NAME, LOADER_CLASS_NAME, LOADER_IMPORT_PACKAGES, CONNECTION_RELATIONSHIP_IMPORTS, + CONNECTION_RELATIONSHIP_LAZY_LOAD_IMPORTS, NON_MODEL_CLASS_IMPORT_PACKAGES, MODEL_AUTH_CLASS_IMPORT_PACKAGES, CUSTOM_PRIMARY_KEY_IMPORT_PACKAGE, } from '../configs/java-config'; import { JAVA_TYPE_IMPORT_MAP } from '../scalars'; import { JavaDeclarationBlock } from '../languages/java-declaration-block'; -import { AppSyncModelVisitor, CodeGenField, CodeGenModel, CodeGenPrimaryKeyType, ParsedAppSyncModelConfig, RawAppSyncModelConfig } from './appsync-visitor'; +import { + AppSyncModelVisitor, + CodeGenField, + CodeGenGenerateEnum, + CodeGenModel, + CodeGenPrimaryKeyType, + ParsedAppSyncModelConfig, + RawAppSyncModelConfig +} from './appsync-visitor'; import { CodeGenConnectionType } from '../utils/process-connections'; import { AuthDirective, AuthStrategy } from '../utils/process-auth'; import { printWarning } from '../utils/warn'; @@ -36,8 +47,10 @@ export class AppSyncModelJavaVisitor< shouldImputeKeyForUniDirectionalHasMany ); - if (this._parsedConfig.generate === 'loader') { + if (this._parsedConfig.generate === CodeGenGenerateEnum.loader) { return this.generateClassLoader(); + } else if (this._parsedConfig.generate === CodeGenGenerateEnum.metadata) { + return this.generateModelPathClasses(); } validateFieldName({ ...this.getSelectedModels(), ...this.getSelectedNonModels() }); if (this.selectedTypeIsEnum()) { @@ -175,7 +188,11 @@ export class AppSyncModelJavaVisitor< } generatePackageName(): string { - return `package ${GENERATED_PACKAGE_NAME};`; + if (this.isGenerateModelsForLazyLoadAndCustomSelectionSet()) { + return `package ${GENERATED_API_PACKAGE_NAME};`; + } else { + return `package ${GENERATED_DATASTORE_PACKAGE_NAME};`; + } } generateModelClass(model: CodeGenModel): string { const classDeclarationBlock = new JavaDeclarationBlock() @@ -189,6 +206,11 @@ export class AppSyncModelJavaVisitor< const annotations = this.generateModelAnnotations(model); classDeclarationBlock.annotate(annotations); + // generate rootPath for models with Custom Selection Set enabled + if (this.isGenerateModelsForLazyLoadAndCustomSelectionSet()) { + this.generateRootPath(model, classDeclarationBlock); + } + const queryFields = this.getWritableFields(model); queryFields.forEach(field => this.generateQueryFields(model, field, classDeclarationBlock)); const nonConnectedFields = this.getNonConnectedField(model); @@ -735,7 +757,25 @@ export class AppSyncModelJavaVisitor< if (Object.keys(JAVA_TYPE_IMPORT_MAP).includes(nativeType)) { this.additionalPackages.add(JAVA_TYPE_IMPORT_MAP[nativeType]); } - return nativeType; + if(this.isGenerateModelsForLazyLoadAndCustomSelectionSet() && field.connectionInfo?.kind) { + switch (field.connectionInfo?.kind) { + case CodeGenConnectionType.BELONGS_TO: + case CodeGenConnectionType.HAS_ONE: + return `LazyModel<${nativeType}>`; + default: + return nativeType; + } + } else { + return nativeType; + } + } + + protected getListType(typeStr: string, field: CodeGenField): string { + if(this.isGenerateModelsForLazyLoadAndCustomSelectionSet()) { + return `LazyList<${typeStr}>` + } else { + return super.getListType(typeStr, field); + } } /** @@ -956,7 +996,9 @@ export class AppSyncModelJavaVisitor< const { connectionInfo } = field; // Add annotation to import this.additionalPackages.add(CONNECTION_RELATIONSHIP_IMPORTS[connectionInfo.kind]); - + if(this.isGenerateModelsForLazyLoadAndCustomSelectionSet()) { + this.additionalPackages.add(CONNECTION_RELATIONSHIP_LAZY_LOAD_IMPORTS[connectionInfo.kind]); + } let connectionDirectiveName: string = ''; const connectionArguments: string[] = []; @@ -1023,4 +1065,101 @@ export class AppSyncModelJavaVisitor< protected getWritableFields(model: CodeGenModel): CodeGenField[] { return this.getNonConnectedField(model).filter(f => !f.isReadOnly); } -} + + protected getConnectedFields(model: CodeGenModel): CodeGenField[] { + return model.fields.filter(f => { + if (f.connectionInfo) return true; + }) + } + + protected generateRootPath(model: CodeGenModel, classDeclarationBlock: JavaDeclarationBlock) { + const modelPathName = this.generateModelPathName(model); + classDeclarationBlock.addClassMember( + "rootPath", + modelPathName, + `new ${modelPathName}("root", false, null)`, + [], + 'public', + { + final: true, + static: true, + }, + ); + } + + protected generateModelPathClasses(): string { + const result: string[] = []; + Object.entries(this.getSelectedModels()).forEach(([name, model]) => { + const modelPathDeclaration = this.generateModelPathClass(model); + result.push(...[modelPathDeclaration]); + }); + const packageDeclaration = this.generateModelPathPackageHeader(); + return [packageDeclaration, ...result].join('\n'); + } + + protected generateModelPathClass(model: CodeGenModel): string { + const classDeclarationBlock = new JavaDeclarationBlock() + .asKind('class') + .access('public') + .withName(this.generateModelPathName(model)) + .extends([`ModelPath<${this.getModelName(model)}>`]) + .withComment(`This is an auto generated class representing the ModelPath for the ${model.name} type in your schema.`) + .final(); + + // constructor + this.generateModelPathConstructor(model, classDeclarationBlock); + + // fields and getters + const connectedFields = this.getConnectedFields(model); + connectedFields.forEach(field => this.generateModelPathField(field, classDeclarationBlock)); + + return classDeclarationBlock.string; + } + + protected generateModelPathName(model: CodeGenModel): string { + return this.getModelName(model) + "Path"; + } + + protected generateModelPathField(field: CodeGenField, classDeclarationBlock: JavaDeclarationBlock): void { + + const fieldName = this.getFieldName(field); + const fieldType = this.generateModelPathName(this.modelMap[field.type]) + classDeclarationBlock.addClassMember(fieldName, fieldType, '', [], 'private'); + + const methodName = this.getFieldGetterName(field); + const modelPathFieldGetterBody = dedent` + if (${fieldName} == null) { + ${fieldName} = new ${fieldType}("${fieldName}", ${field.isList}, this); + } + return ${fieldName};`; + + classDeclarationBlock.addClassMethod(methodName, fieldType, modelPathFieldGetterBody, undefined, undefined, 'public', { + synchronized: true, + }); + }; + + protected generateModelPathPackageHeader(): string { + const imports = this.generateImportStatements(MODEL_PATH_CLASS_IMPORT_PACKAGES); + return [this.generatePackageName(), '', imports].join('\n'); + } + + /** + * Generate constructor for the extended ModelPath class + * @param model CodeGenModel + * @param declarationsBlock Class Declaration block to which constructor will be added + */ + protected generateModelPathConstructor(model: CodeGenModel, declarationsBlock: JavaDeclarationBlock): void { + const modelPathName = this.generateModelPathName(model) + + const constructorArguments = [ + { name: "name", type: "@NonNull String" }, + { name: "isCollection", type: "@NonNull Boolean" }, + { name: "parent", type: "@Nullable PropertyPath" } + ] + + const body = `super(name, isCollection, parent, ${this.getModelName(model)}.class);` + + declarationsBlock.addClassMethod(modelPathName, null, body, constructorArguments, undefined, ''); + } + +} \ No newline at end of file From 31908c56dd7372451fbb2ec886cb19bf39dcdb45 Mon Sep 17 00:00:00 2001 From: Tyler Roach Date: Thu, 17 Aug 2023 16:47:53 -0400 Subject: [PATCH 02/30] Further model updates --- .../src/configs/java-config.ts | 13 +-- .../src/visitors/appsync-java-visitor.ts | 87 ++++++++++++------- 2 files changed, 65 insertions(+), 35 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/configs/java-config.ts b/packages/appsync-modelgen-plugin/src/configs/java-config.ts index ef6a585a0..29eabfe49 100644 --- a/packages/appsync-modelgen-plugin/src/configs/java-config.ts +++ b/packages/appsync-modelgen-plugin/src/configs/java-config.ts @@ -89,12 +89,15 @@ export const CONNECTION_RELATIONSHIP_IMPORTS: { [key in CodeGenConnectionType]: export const CUSTOM_PRIMARY_KEY_IMPORT_PACKAGE = 'com.amplifyframework.core.model.ModelIdentifier'; -export const LAZY_MODEL_IMPORT_PACKAGE = 'com.amplifyframework.core.model.LazyModel' +export const LAZY_MODEL_IMPORT_PACKAGES = [ + 'com.amplifyframework.core.model.LazyModel', + 'com.amplifyframework.core.model.InMemoryLazyModel' +] -export const CONNECTION_RELATIONSHIP_LAZY_LOAD_IMPORTS: { [key in CodeGenConnectionType]: string } = { - BELONGS_TO: LAZY_MODEL_IMPORT_PACKAGE, - HAS_MANY: 'com.amplifyframework.core.model.LazyList', - HAS_ONE: LAZY_MODEL_IMPORT_PACKAGE, +export const CONNECTION_RELATIONSHIP_LAZY_LOAD_IMPORTS: { [key in CodeGenConnectionType]: string[] } = { + BELONGS_TO: LAZY_MODEL_IMPORT_PACKAGES, + HAS_MANY: ['com.amplifyframework.api.graphql.PaginatedResult'], + HAS_ONE: LAZY_MODEL_IMPORT_PACKAGES, }; export const MODEL_PATH_IMPORT_PACKAGES = [ diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index c4d5a69c0..111b4fd50 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -414,7 +414,7 @@ export class AppSyncModelJavaVisitor< const returnType = isLastField ? 'Build' : requiredInterfaces[idx + 1].name; const interfaceName = this.getStepInterfaceName(field.name); const methodName = this.getStepFunctionName(field); - const argumentType = this.getNativeType(field); + const argumentType = this.getNativeType(field, true); const argumentName = this.getStepFunctionArgumentName(field); const interfaceDeclaration = new JavaDeclarationBlock() .asKind('interface') @@ -441,7 +441,7 @@ export class AppSyncModelJavaVisitor< nullableFields.forEach(field => { const fieldName = this.getStepFunctionArgumentName(field); const methodName = this.getStepFunctionName(field); - builderBody.push(`${this.getStepInterfaceName('Build')} ${methodName}(${this.getNativeType(field)} ${fieldName});`); + builderBody.push(`${this.getStepInterfaceName('Build')} ${methodName}(${this.getNativeType(field, true)} ${fieldName});`); }); builder.withBlock(indentMultiline(builderBody.join('\n'))); @@ -472,6 +472,24 @@ export class AppSyncModelJavaVisitor< builderClassDeclaration.addClassMember(fieldName, this.getNativeType(field), '', undefined, 'private'); }); + // public builder constructor + builderClassDeclaration.addClassMethod("Builder", null, "", [], [], 'public'); + + // private builder constructor for CopyOfBuilder + const constructorArguments = this.getWritableFields(model).map(field => ({ + name: this.getFieldName(field), + type: this.getNativeType(field), + })); + const constructorBody = dedent( + this.getWritableFields(model) + .map(field => { + const fieldName = this.getFieldName(field); + return `this.${fieldName} = ${fieldName};`; + }) + .join('\n'), + ).trim(); + builderClassDeclaration.addClassMethod("Builder", null, constructorBody, constructorArguments, [], 'private'); + // methods // build(); const buildImplementation = isIdAsModelPrimaryKey ? [`String id = this.id != null ? this.id : UUID.randomUUID().toString();`, ''] : ['']; @@ -496,9 +514,12 @@ export class AppSyncModelJavaVisitor< const fieldName = this.getFieldName(field); const methodName = this.getStepFunctionName(field); const returnType = isLastStep ? this.getStepInterfaceName('Build') : this.getStepInterfaceName(fields[idx + 1].name); - const argumentType = this.getNativeType(field); + const argumentType = this.getNativeType(field, true); const argumentName = this.getStepFunctionArgumentName(field); - const body = [`Objects.requireNonNull(${argumentName});`, `this.${fieldName} = ${argumentName};`, `return this;`].join('\n'); + const assignment = this.isLazyModel(field) ? + `this.${fieldName} = new InMemoryLazyModel<>(${argumentName});` : + `this.${fieldName} = ${argumentName};` + const body = [`Objects.requireNonNull(${argumentName});`, `${assignment}`, `return this;`].join('\n'); builderClassDeclaration.addClassMethod( methodName, returnType, @@ -516,7 +537,7 @@ export class AppSyncModelJavaVisitor< const fieldName = this.getFieldName(field); const methodName = this.getStepFunctionName(field); const returnType = this.getStepInterfaceName('Build'); - const argumentType = this.getNativeType(field); + const argumentType = this.getNativeType(field, true); const argumentName = this.getStepFunctionArgumentName(field); const body = [`this.${fieldName} = ${argumentName};`, `return this;`].join('\n'); builderClassDeclaration.addClassMethod( @@ -582,21 +603,18 @@ export class AppSyncModelJavaVisitor< name: this.getStepFunctionArgumentName(field), type: this.getNativeType(field), })); - const stepBuilderInvocation = [...nonNullableFields, ...nullableFields].map(field => { - const methodName = this.getStepFunctionName(field); - const argumentName = this.getStepFunctionArgumentName(field); - return `.${methodName}(${argumentName})`; - }); - const invocations = - stepBuilderInvocation.length === 0 ? '' : ['super', indentMultiline(stepBuilderInvocation.join('\n')).trim(), ';'].join(''); - const body = [...(isIdAsModelPrimaryKey ? ['super.id(id);'] : []), invocations].join('\n'); - copyOfBuilderClassDeclaration.addClassMethod(builderName, null, body, constructorArguments, [], 'private'); + const args = dedent( + this.getWritableFields(model) + .map(field => this.getFieldName(field)) + .join(', '), + ).trim(); + copyOfBuilderClassDeclaration.addClassMethod(builderName, null, `super(${args});`, constructorArguments, [], 'private'); // Non-nullable field setters need to be added to NewClass as this is not a step builder [...nonNullableFields, ...nullableFields].forEach(field => { const methodName = this.getStepFunctionName(field); const argumentName = this.getStepFunctionArgumentName(field); - const argumentType = this.getNativeType(field); + const argumentType = this.getNativeType(field, true); const implementation = `return (${builderName}) super.${methodName}(${argumentName});`; copyOfBuilderClassDeclaration.addClassMethod( methodName, @@ -752,32 +770,41 @@ export class AppSyncModelJavaVisitor< declarationsBlock.addClassMethod(name, null, body, constructorArguments, undefined, 'private'); } - protected getNativeType(field: CodeGenField): string { + // unwrapLazyModel is passed when we care to get the native type inside LazyModel, rather than return LazyModel type. + protected getNativeType(field: CodeGenField, unwrapLazyModel: boolean = false): string { const nativeType = super.getNativeType(field); if (Object.keys(JAVA_TYPE_IMPORT_MAP).includes(nativeType)) { this.additionalPackages.add(JAVA_TYPE_IMPORT_MAP[nativeType]); } - if(this.isGenerateModelsForLazyLoadAndCustomSelectionSet() && field.connectionInfo?.kind) { - switch (field.connectionInfo?.kind) { - case CodeGenConnectionType.BELONGS_TO: - case CodeGenConnectionType.HAS_ONE: - return `LazyModel<${nativeType}>`; - default: - return nativeType; - } - } else { - return nativeType; + if(!unwrapLazyModel && this.isLazyModel(field)) { + return `LazyModel<${nativeType}>`; } + return nativeType; } - + protected getListType(typeStr: string, field: CodeGenField): string { - if(this.isGenerateModelsForLazyLoadAndCustomSelectionSet()) { - return `LazyList<${typeStr}>` + if(this.isLazyList(field)) { + return `PaginatedResult<${typeStr}>`; } else { return super.getListType(typeStr, field); } } + protected isLazyModel(field: CodeGenField) { + if (!this.isGenerateModelsForLazyLoadAndCustomSelectionSet) return false; + switch (field.connectionInfo?.kind) { + case CodeGenConnectionType.BELONGS_TO: + case CodeGenConnectionType.HAS_ONE: + return true; + default: + return false; + } + } + + protected isLazyList(field: CodeGenField) { + return this.isGenerateModelsForLazyLoadAndCustomSelectionSet() && field.connectionInfo?.kind == CodeGenConnectionType.HAS_MANY; + } + /** * Generate code for equals method * @param model @@ -997,7 +1024,7 @@ export class AppSyncModelJavaVisitor< // Add annotation to import this.additionalPackages.add(CONNECTION_RELATIONSHIP_IMPORTS[connectionInfo.kind]); if(this.isGenerateModelsForLazyLoadAndCustomSelectionSet()) { - this.additionalPackages.add(CONNECTION_RELATIONSHIP_LAZY_LOAD_IMPORTS[connectionInfo.kind]); + CONNECTION_RELATIONSHIP_LAZY_LOAD_IMPORTS[connectionInfo.kind].forEach(item => this.additionalPackages.add(item)); } let connectionDirectiveName: string = ''; const connectionArguments: string[] = []; From 51517a6f6fddf4c63fb47dbb5ba446db5af32e3a Mon Sep 17 00:00:00 2001 From: Tyler Roach Date: Fri, 18 Aug 2023 11:04:15 -0400 Subject: [PATCH 03/30] Fix LazyModel generation logic --- packages/appsync-modelgen-plugin/src/preset.ts | 5 ++--- .../src/visitors/appsync-java-visitor.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index e41a1efab..037c72a32 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -64,8 +64,8 @@ const generateJavaPreset = ( }, }); + // if generateModelsForLazyLoadAndCustomSelectionSet = true, these next Models + Paths will be created in api package if (options.config.generateModelsForLazyLoadAndCustomSelectionSet) { - // If an overrideOutputDir is provided, we palce all API codegen in an 'api' folder to prevent collisions with DataStore models const apiModelFolder = options.config.overrideOutputDir ? [options.config.overrideOutputDir, "api"] : @@ -84,10 +84,9 @@ const generateJavaPreset = ( }); // ModelPath - const modelPathName = modelName + "Path"; config.push({ ...options, - filename: join(...apiModelFolder, `${modelPathName}.java`), + filename: join(...apiModelFolder, `${modelName}Path.java`), config: { ...options.config, scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index 111b4fd50..4a880df35 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -791,7 +791,7 @@ export class AppSyncModelJavaVisitor< } protected isLazyModel(field: CodeGenField) { - if (!this.isGenerateModelsForLazyLoadAndCustomSelectionSet) return false; + if (!this.isGenerateModelsForLazyLoadAndCustomSelectionSet()) return false; switch (field.connectionInfo?.kind) { case CodeGenConnectionType.BELONGS_TO: case CodeGenConnectionType.HAS_ONE: From 2bcf5ad50522154195734c4823d3b6919333a344 Mon Sep 17 00:00:00 2001 From: Tyler Roach Date: Fri, 18 Aug 2023 16:00:02 -0400 Subject: [PATCH 04/30] Only generate ModelPath if model type --- .../appsync-modelgen-plugin/src/preset.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index 037c72a32..0b261dcca 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -83,17 +83,19 @@ const generateJavaPreset = ( }, }); - // ModelPath - config.push({ - ...options, - filename: join(...apiModelFolder, `${modelName}Path.java`), - config: { - ...options.config, - scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, - generate: 'metadata', - selectedType: modelName, - }, - }); + // ModelPath if type is @model + if (model?.directives?.find((directive) => directive?.name?.value === 'model')) { + config.push({ + ...options, + filename: join(...apiModelFolder, `${modelName}Path.java`), + config: { + ...options.config, + scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, + generate: 'metadata', + selectedType: modelName, + }, + }); + } // Class loader config.push({ From 307e8507dbaf158754f43bfc6084192c10c50647 Mon Sep 17 00:00:00 2001 From: Tyler Roach Date: Fri, 18 Aug 2023 16:03:49 -0400 Subject: [PATCH 05/30] lint --- .../appsync-modelgen-plugin/src/preset.ts | 10 +++---- .../src/visitors/appsync-java-visitor.ts | 26 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index 0b261dcca..d3d1fa26a 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -38,7 +38,7 @@ const generateJavaPreset = ( // Android splits models into 2 different packages.. 1 for DataStore and 1 for API // generateModelsForLazyLoadAndCustomSelectionSet is used to decide whether or not we create the codegen for the API category - + // Model const modelName = model.name.value; config.push({ @@ -67,8 +67,8 @@ const generateJavaPreset = ( // if generateModelsForLazyLoadAndCustomSelectionSet = true, these next Models + Paths will be created in api package if (options.config.generateModelsForLazyLoadAndCustomSelectionSet) { // If an overrideOutputDir is provided, we palce all API codegen in an 'api' folder to prevent collisions with DataStore models - const apiModelFolder = options.config.overrideOutputDir ? - [options.config.overrideOutputDir, "api"] : + const apiModelFolder = options.config.overrideOutputDir ? + [options.config.overrideOutputDir, "api"] : [options.baseOutputDir, ...GENERATED_API_PACKAGE_NAME.split('.')]; // Model @@ -83,7 +83,7 @@ const generateJavaPreset = ( }, }); - // ModelPath if type is @model + // Create ModelPath if type is @model if (model?.directives?.find((directive) => directive?.name?.value === 'model')) { config.push({ ...options, @@ -96,7 +96,7 @@ const generateJavaPreset = ( }, }); } - + // Class loader config.push({ ...options, diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index 4a880df35..ac3fa4856 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -16,14 +16,14 @@ import { } from '../configs/java-config'; import { JAVA_TYPE_IMPORT_MAP } from '../scalars'; import { JavaDeclarationBlock } from '../languages/java-declaration-block'; -import { - AppSyncModelVisitor, - CodeGenField, +import { + AppSyncModelVisitor, + CodeGenField, CodeGenGenerateEnum, - CodeGenModel, - CodeGenPrimaryKeyType, - ParsedAppSyncModelConfig, - RawAppSyncModelConfig + CodeGenModel, + CodeGenPrimaryKeyType, + ParsedAppSyncModelConfig, + RawAppSyncModelConfig } from './appsync-visitor'; import { CodeGenConnectionType } from '../utils/process-connections'; import { AuthDirective, AuthStrategy } from '../utils/process-auth'; @@ -482,7 +482,7 @@ export class AppSyncModelJavaVisitor< })); const constructorBody = dedent( this.getWritableFields(model) - .map(field => { + .map(field => { const fieldName = this.getFieldName(field); return `this.${fieldName} = ${fieldName};`; }) @@ -516,7 +516,7 @@ export class AppSyncModelJavaVisitor< const returnType = isLastStep ? this.getStepInterfaceName('Build') : this.getStepInterfaceName(fields[idx + 1].name); const argumentType = this.getNativeType(field, true); const argumentName = this.getStepFunctionArgumentName(field); - const assignment = this.isLazyModel(field) ? + const assignment = this.isLazyModel(field) ? `this.${fieldName} = new InMemoryLazyModel<>(${argumentName});` : `this.${fieldName} = ${argumentName};` const body = [`Objects.requireNonNull(${argumentName});`, `${assignment}`, `return this;`].join('\n'); @@ -781,7 +781,7 @@ export class AppSyncModelJavaVisitor< } return nativeType; } - + protected getListType(typeStr: string, field: CodeGenField): string { if(this.isLazyList(field)) { return `PaginatedResult<${typeStr}>`; @@ -796,7 +796,7 @@ export class AppSyncModelJavaVisitor< case CodeGenConnectionType.BELONGS_TO: case CodeGenConnectionType.HAS_ONE: return true; - default: + default: return false; } } @@ -1177,7 +1177,7 @@ export class AppSyncModelJavaVisitor< */ protected generateModelPathConstructor(model: CodeGenModel, declarationsBlock: JavaDeclarationBlock): void { const modelPathName = this.generateModelPathName(model) - + const constructorArguments = [ { name: "name", type: "@NonNull String" }, { name: "isCollection", type: "@NonNull Boolean" }, @@ -1188,5 +1188,5 @@ export class AppSyncModelJavaVisitor< declarationsBlock.addClassMethod(modelPathName, null, body, constructorArguments, undefined, ''); } - + } \ No newline at end of file From cf92b5267e1364c96fe3a1a1234b28b86c06d918 Mon Sep 17 00:00:00 2001 From: Tyler Roach Date: Mon, 21 Aug 2023 12:03:16 -0400 Subject: [PATCH 06/30] Fix LazyModel in builder --- .../src/visitors/appsync-java-visitor.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index ac3fa4856..22e063ea4 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -518,7 +518,7 @@ export class AppSyncModelJavaVisitor< const argumentName = this.getStepFunctionArgumentName(field); const assignment = this.isLazyModel(field) ? `this.${fieldName} = new InMemoryLazyModel<>(${argumentName});` : - `this.${fieldName} = ${argumentName};` + `this.${fieldName} = ${argumentName};`; const body = [`Objects.requireNonNull(${argumentName});`, `${assignment}`, `return this;`].join('\n'); builderClassDeclaration.addClassMethod( methodName, @@ -539,7 +539,10 @@ export class AppSyncModelJavaVisitor< const returnType = this.getStepInterfaceName('Build'); const argumentType = this.getNativeType(field, true); const argumentName = this.getStepFunctionArgumentName(field); - const body = [`this.${fieldName} = ${argumentName};`, `return this;`].join('\n'); + const assignment = this.isLazyModel(field) ? + `this.${fieldName} = new InMemoryLazyModel<>(${argumentName});` : + `this.${fieldName} = ${argumentName};` + const body = [`${assignment}`, `return this;`].join('\n'); builderClassDeclaration.addClassMethod( methodName, returnType, From 0f6f4bd9e1e5a05f4809e652e98f310c74451dc4 Mon Sep 17 00:00:00 2001 From: Tyler Roach Date: Tue, 5 Sep 2023 15:59:51 -0700 Subject: [PATCH 07/30] android lazy + css support --- .../src/configs/java-config.ts | 7 +-- .../appsync-modelgen-plugin/src/preset.ts | 47 +++---------------- .../src/visitors/appsync-java-visitor.ts | 18 ++++--- 3 files changed, 17 insertions(+), 55 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/configs/java-config.ts b/packages/appsync-modelgen-plugin/src/configs/java-config.ts index 29eabfe49..de9886e36 100644 --- a/packages/appsync-modelgen-plugin/src/configs/java-config.ts +++ b/packages/appsync-modelgen-plugin/src/configs/java-config.ts @@ -1,10 +1,7 @@ import { CodeGenConnectionType } from '../utils/process-connections'; // Name of the Generated Java Package for DataStore category -export const GENERATED_DATASTORE_PACKAGE_NAME = 'com.amplifyframework.datastore.generated.model'; - -// Name of the Generated Java Package for API category -export const GENERATED_API_PACKAGE_NAME = 'com.amplifyframework.api.generated.model'; +export const GENERATED_PACKAGE_NAME = 'com.amplifyframework.datastore.generated.model'; // Name of the Class Loader package export const LOADER_CLASS_NAME = 'AmplifyModelProvider'; @@ -96,7 +93,7 @@ export const LAZY_MODEL_IMPORT_PACKAGES = [ export const CONNECTION_RELATIONSHIP_LAZY_LOAD_IMPORTS: { [key in CodeGenConnectionType]: string[] } = { BELONGS_TO: LAZY_MODEL_IMPORT_PACKAGES, - HAS_MANY: ['com.amplifyframework.api.graphql.PaginatedResult'], + HAS_MANY: ['com.amplifyframework.core.model.ModelList'], HAS_ONE: LAZY_MODEL_IMPORT_PACKAGES, }; diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index b18eeccb4..2b75111fc 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -2,7 +2,7 @@ import { Types } from '@graphql-codegen/plugin-helpers'; import { Kind, TypeDefinitionNode } from 'graphql'; import { join } from 'path'; import { JAVA_SCALAR_MAP, SWIFT_SCALAR_MAP, TYPESCRIPT_SCALAR_MAP, DART_SCALAR_MAP, METADATA_SCALAR_MAP } from './scalars'; -import { LOADER_CLASS_NAME, GENERATED_API_PACKAGE_NAME, GENERATED_DATASTORE_PACKAGE_NAME } from './configs/java-config'; +import { LOADER_CLASS_NAME, GENERATED_PACKAGE_NAME } from './configs/java-config'; import { graphqlName, toUpper } from 'graphql-transformer-common'; const APPSYNC_DATA_STORE_CODEGEN_TARGETS = ['java', 'swift', 'javascript', 'typescript', 'dart', 'introspection']; @@ -35,20 +35,16 @@ const generateJavaPreset = ( models: TypeDefinitionNode[], ): Types.GenerateOptions[] => { const config: Types.GenerateOptions[] = []; - const dataStoreModelFolder = options.config.overrideOutputDir ? [options.config.overrideOutputDir] : [options.baseOutputDir, ...GENERATED_DATASTORE_PACKAGE_NAME.split('.')]; + const modelFolder = options.config.overrideOutputDir + ? [options.config.overrideOutputDir] + : [options.baseOutputDir, ...GENERATED_PACKAGE_NAME.split('.')]; models.forEach(model => { - - // Android splits models into 2 different packages.. 1 for DataStore and 1 for API - // generateModelsForLazyLoadAndCustomSelectionSet is used to decide whether or not we create the codegen for the API category - - // Model const modelName = model.name.value; config.push({ ...options, - filename: join(...dataStoreModelFolder, `${modelName}.java`), + filename: join(...modelFolder, `${modelName}.java`), config: { ...options.config, - generateModelsForLazyLoadAndCustomSelectionSet: false, // override value to output DataStore models scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, selectedType: modelName, }, @@ -57,10 +53,9 @@ const generateJavaPreset = ( // Class loader config.push({ ...options, - filename: join(...dataStoreModelFolder, `${LOADER_CLASS_NAME}.java`), + filename: join(...modelFolder, `${LOADER_CLASS_NAME}.java`), config: { ...options.config, - generateModelsForLazyLoadAndCustomSelectionSet: false, // override value to output DataStore models scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, generate: 'loader', }, @@ -68,28 +63,11 @@ const generateJavaPreset = ( // if generateModelsForLazyLoadAndCustomSelectionSet = true, these next Models + Paths will be created in api package if (options.config.generateModelsForLazyLoadAndCustomSelectionSet) { - // If an overrideOutputDir is provided, we palce all API codegen in an 'api' folder to prevent collisions with DataStore models - const apiModelFolder = options.config.overrideOutputDir ? - [options.config.overrideOutputDir, "api"] : - [options.baseOutputDir, ...GENERATED_API_PACKAGE_NAME.split('.')]; - - // Model - const modelName = model.name.value; - config.push({ - ...options, - filename: join(...apiModelFolder, `${modelName}.java`), - config: { - ...options.config, - scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, - selectedType: modelName, - }, - }); - // Create ModelPath if type is @model if (model?.directives?.find((directive) => directive?.name?.value === 'model')) { config.push({ ...options, - filename: join(...apiModelFolder, `${modelName}Path.java`), + filename: join(...modelFolder, `${modelName}Path.java`), config: { ...options.config, scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, @@ -98,17 +76,6 @@ const generateJavaPreset = ( }, }); } - - // Class loader - config.push({ - ...options, - filename: join(...apiModelFolder, `${LOADER_CLASS_NAME}.java`), - config: { - ...options.config, - scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, - generate: 'loader', - }, - }); } }); diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index 22e063ea4..0ce43acee 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -4,8 +4,7 @@ import dedent from 'ts-dedent'; import { MODEL_CLASS_IMPORT_PACKAGES, MODEL_PATH_CLASS_IMPORT_PACKAGES, - GENERATED_API_PACKAGE_NAME, - GENERATED_DATASTORE_PACKAGE_NAME, + GENERATED_PACKAGE_NAME, LOADER_CLASS_NAME, LOADER_IMPORT_PACKAGES, CONNECTION_RELATIONSHIP_IMPORTS, @@ -188,11 +187,7 @@ export class AppSyncModelJavaVisitor< } generatePackageName(): string { - if (this.isGenerateModelsForLazyLoadAndCustomSelectionSet()) { - return `package ${GENERATED_API_PACKAGE_NAME};`; - } else { - return `package ${GENERATED_DATASTORE_PACKAGE_NAME};`; - } + return `package ${GENERATED_PACKAGE_NAME};`; } generateModelClass(model: CodeGenModel): string { const classDeclarationBlock = new JavaDeclarationBlock() @@ -786,8 +781,8 @@ export class AppSyncModelJavaVisitor< } protected getListType(typeStr: string, field: CodeGenField): string { - if(this.isLazyList(field)) { - return `PaginatedResult<${typeStr}>`; + if(this.isModelList(field)) { + return `ModelList<${typeStr}>`; } else { return super.getListType(typeStr, field); } @@ -804,7 +799,7 @@ export class AppSyncModelJavaVisitor< } } - protected isLazyList(field: CodeGenField) { + protected isModelList(field: CodeGenField) { return this.isGenerateModelsForLazyLoadAndCustomSelectionSet() && field.connectionInfo?.kind == CodeGenConnectionType.HAS_MANY; } @@ -935,6 +930,9 @@ export class AppSyncModelJavaVisitor< this.usingAuth = true; modelArgs.push(`authRules = ${authRules}`); } + if (this.isGenerateModelsForLazyLoadAndCustomSelectionSet()) { + modelArgs.push(`hasLazySupport = true`) + } return `ModelConfig(${modelArgs.join(', ')})`; case 'key': const keyArgs: string[] = []; From 00d01df1222634e21e1067f8bad12b610d48e0af Mon Sep 17 00:00:00 2001 From: Tyler Roach Date: Tue, 5 Sep 2023 16:08:00 -0700 Subject: [PATCH 08/30] android updates --- packages/appsync-modelgen-plugin/src/configs/java-config.ts | 2 +- packages/appsync-modelgen-plugin/src/preset.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/configs/java-config.ts b/packages/appsync-modelgen-plugin/src/configs/java-config.ts index de9886e36..8dc689a77 100644 --- a/packages/appsync-modelgen-plugin/src/configs/java-config.ts +++ b/packages/appsync-modelgen-plugin/src/configs/java-config.ts @@ -1,6 +1,6 @@ import { CodeGenConnectionType } from '../utils/process-connections'; -// Name of the Generated Java Package for DataStore category +// Name of the Generated Java Package export const GENERATED_PACKAGE_NAME = 'com.amplifyframework.datastore.generated.model'; // Name of the Class Loader package diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index 2b75111fc..040e2d15a 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -36,8 +36,8 @@ const generateJavaPreset = ( ): Types.GenerateOptions[] => { const config: Types.GenerateOptions[] = []; const modelFolder = options.config.overrideOutputDir - ? [options.config.overrideOutputDir] - : [options.baseOutputDir, ...GENERATED_PACKAGE_NAME.split('.')]; + ? [options.config.overrideOutputDir] + : [options.baseOutputDir, ...GENERATED_PACKAGE_NAME.split('.')]; models.forEach(model => { const modelName = model.name.value; config.push({ @@ -61,7 +61,7 @@ const generateJavaPreset = ( }, }); - // if generateModelsForLazyLoadAndCustomSelectionSet = true, these next Models + Paths will be created in api package + // Create ModelPath's if generateModelsForLazyLoadAndCustomSelectionSet = true if (options.config.generateModelsForLazyLoadAndCustomSelectionSet) { // Create ModelPath if type is @model if (model?.directives?.find((directive) => directive?.name?.value === 'model')) { From df021ab084844d7252d0e59baccbd65554b946b0 Mon Sep 17 00:00:00 2001 From: Tyler Roach Date: Wed, 6 Sep 2023 10:38:12 -0700 Subject: [PATCH 09/30] Add nullability requirements to CopyOfBuilder --- .../src/visitors/appsync-java-visitor.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index 0ce43acee..950c6cf46 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -601,12 +601,27 @@ export class AppSyncModelJavaVisitor< name: this.getStepFunctionArgumentName(field), type: this.getNativeType(field), })); - const args = dedent( + + const constructorNullChecks = dedent( + nonNullableFields.map( + field => `Objects.requireNonNull(${this.getFieldName(field)});` + ).join('\n') + ).trim() + + const superArgs = dedent( this.getWritableFields(model) .map(field => this.getFieldName(field)) .join(', '), ).trim(); - copyOfBuilderClassDeclaration.addClassMethod(builderName, null, `super(${args});`, constructorArguments, [], 'private'); + + copyOfBuilderClassDeclaration.addClassMethod( + builderName, + null, + `super(${superArgs});\n${constructorNullChecks}`, + constructorArguments, + [], + 'private' + ); // Non-nullable field setters need to be added to NewClass as this is not a step builder [...nonNullableFields, ...nullableFields].forEach(field => { From ba52cbf6078a333ebf92e9aaa160d3edc81feef9 Mon Sep 17 00:00:00 2001 From: tjroach Date: Wed, 13 Sep 2023 10:52:33 -0400 Subject: [PATCH 10/30] Update to use ModelReference types --- .../src/configs/java-config.ts | 4 ++-- .../src/visitors/appsync-java-visitor.ts | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/configs/java-config.ts b/packages/appsync-modelgen-plugin/src/configs/java-config.ts index 8dc689a77..fa241e8cd 100644 --- a/packages/appsync-modelgen-plugin/src/configs/java-config.ts +++ b/packages/appsync-modelgen-plugin/src/configs/java-config.ts @@ -87,8 +87,8 @@ export const CONNECTION_RELATIONSHIP_IMPORTS: { [key in CodeGenConnectionType]: export const CUSTOM_PRIMARY_KEY_IMPORT_PACKAGE = 'com.amplifyframework.core.model.ModelIdentifier'; export const LAZY_MODEL_IMPORT_PACKAGES = [ - 'com.amplifyframework.core.model.LazyModel', - 'com.amplifyframework.core.model.InMemoryLazyModel' + 'com.amplifyframework.core.model.ModelReference', + 'com.amplifyframework.core.model.LoadedModelReferenceImpl' ] export const CONNECTION_RELATIONSHIP_LAZY_LOAD_IMPORTS: { [key in CodeGenConnectionType]: string[] } = { diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index 950c6cf46..5f727e5d5 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -511,8 +511,8 @@ export class AppSyncModelJavaVisitor< const returnType = isLastStep ? this.getStepInterfaceName('Build') : this.getStepInterfaceName(fields[idx + 1].name); const argumentType = this.getNativeType(field, true); const argumentName = this.getStepFunctionArgumentName(field); - const assignment = this.isLazyModel(field) ? - `this.${fieldName} = new InMemoryLazyModel<>(${argumentName});` : + const assignment = this.isModelReference(field) ? + `this.${fieldName} = new LoadedModelReferenceImpl<>(${argumentName});` : `this.${fieldName} = ${argumentName};`; const body = [`Objects.requireNonNull(${argumentName});`, `${assignment}`, `return this;`].join('\n'); builderClassDeclaration.addClassMethod( @@ -534,8 +534,8 @@ export class AppSyncModelJavaVisitor< const returnType = this.getStepInterfaceName('Build'); const argumentType = this.getNativeType(field, true); const argumentName = this.getStepFunctionArgumentName(field); - const assignment = this.isLazyModel(field) ? - `this.${fieldName} = new InMemoryLazyModel<>(${argumentName});` : + const assignment = this.isModelReference(field) ? + `this.${fieldName} = new LoadedModelReferenceImpl<>(${argumentName});` : `this.${fieldName} = ${argumentName};` const body = [`${assignment}`, `return this;`].join('\n'); builderClassDeclaration.addClassMethod( @@ -783,14 +783,14 @@ export class AppSyncModelJavaVisitor< declarationsBlock.addClassMethod(name, null, body, constructorArguments, undefined, 'private'); } - // unwrapLazyModel is passed when we care to get the native type inside LazyModel, rather than return LazyModel type. - protected getNativeType(field: CodeGenField, unwrapLazyModel: boolean = false): string { + // unwrapModelReference is passed when we care to get the native type inside ModelReference, rather than return ModelReference type. + protected getNativeType(field: CodeGenField, unwrapModelReference: boolean = false): string { const nativeType = super.getNativeType(field); if (Object.keys(JAVA_TYPE_IMPORT_MAP).includes(nativeType)) { this.additionalPackages.add(JAVA_TYPE_IMPORT_MAP[nativeType]); } - if(!unwrapLazyModel && this.isLazyModel(field)) { - return `LazyModel<${nativeType}>`; + if(!unwrapModelReference && this.isModelReference(field)) { + return `ModelReference<${nativeType}>`; } return nativeType; } @@ -803,7 +803,7 @@ export class AppSyncModelJavaVisitor< } } - protected isLazyModel(field: CodeGenField) { + protected isModelReference(field: CodeGenField) { if (!this.isGenerateModelsForLazyLoadAndCustomSelectionSet()) return false; switch (field.connectionInfo?.kind) { case CodeGenConnectionType.BELONGS_TO: From f46d5a1b0eb3082a1aadb677530623066fd579f9 Mon Sep 17 00:00:00 2001 From: Michael Law <1365977+lawmicha@users.noreply.github.com> Date: Wed, 13 Sep 2023 13:47:59 -0400 Subject: [PATCH 11/30] Adding tests (#697) --- ...java-api-lazyload-css-visitor.test.ts.snap | 720 ++++++++++++++++++ .../appsync-java-visitor.test.ts.snap | 673 ++++++++++++---- ...sync-java-api-lazyload-css-visitor.test.ts | 140 ++++ .../appsync-java-visitor.test.ts.snap | 321 ++++++-- .../__snapshots__/models.test.ts.snap | 169 +++- 5 files changed, 1797 insertions(+), 226 deletions(-) create mode 100644 packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap create mode 100644 packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap new file mode 100644 index 000000000..2c8c3a623 --- /dev/null +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap @@ -0,0 +1,720 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AppSyncModelVisitor Should generate for DefaultPKParent DefaultPKChild models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.ModelList; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the DefaultPKParent type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"DefaultPKParents\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class DefaultPKParent implements Model { + public static final DefaultPKParentPath rootPath = new DefaultPKParentPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"DefaultPKParent\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"DefaultPKParent\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"DefaultPKChild\\") @HasMany(associatedWith = \\"parent\\", type = DefaultPKChild.class) ModelList children = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public ModelList getChildren() { + return children; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private DefaultPKParent(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + DefaultPKParent defaultPkParent = (DefaultPKParent) obj; + return ObjectsCompat.equals(getId(), defaultPkParent.getId()) && + ObjectsCompat.equals(getContent(), defaultPkParent.getContent()) && + ObjectsCompat.equals(getCreatedAt(), defaultPkParent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), defaultPkParent.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"DefaultPKParent {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static DefaultPKParent justId(String id) { + return new DefaultPKParent( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content); + } + public interface BuildStep { + DefaultPKParent build(); + BuildStep id(String id); + BuildStep content(String content); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + public Builder() { + + } + + private Builder(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public DefaultPKParent build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new DefaultPKParent( + id, + content); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content) { + super(id, content); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + +} + +/** This is an auto generated class representing the DefaultPKChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"DefaultPKChildren\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class DefaultPKChild implements Model { + public static final DefaultPKChildPath rootPath = new DefaultPKChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"DefaultPKChild\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"DefaultPKChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"DefaultPKChild\\", \\"defaultPKParentChildrenId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"DefaultPKParent\\") @BelongsTo(targetName = \\"defaultPKParentChildrenId\\", type = DefaultPKParent.class) ModelReference parent; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public ModelReference getParent() { + return parent; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private DefaultPKChild(String id, String content, ModelReference parent) { + this.id = id; + this.content = content; + this.parent = parent; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + DefaultPKChild defaultPkChild = (DefaultPKChild) obj; + return ObjectsCompat.equals(getId(), defaultPkChild.getId()) && + ObjectsCompat.equals(getContent(), defaultPkChild.getContent()) && + ObjectsCompat.equals(getParent(), defaultPkChild.getParent()) && + ObjectsCompat.equals(getCreatedAt(), defaultPkChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), defaultPkChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getParent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"DefaultPKChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static DefaultPKChild justId(String id) { + return new DefaultPKChild( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content, + parent); + } + public interface BuildStep { + DefaultPKChild build(); + BuildStep id(String id); + BuildStep content(String content); + BuildStep parent(DefaultPKParent parent); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + private ModelReference parent; + public Builder() { + + } + + private Builder(String id, String content, ModelReference parent) { + this.id = id; + this.content = content; + this.parent = parent; + } + + @Override + public DefaultPKChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new DefaultPKChild( + id, + content, + parent); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + @Override + public BuildStep parent(DefaultPKParent parent) { + this.parent = new LoadedModelReferenceImpl<>(parent); + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content, ModelReference parent) { + super(id, content, parent); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(DefaultPKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor Should generate for HasOneParent HasOneChild models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasOne; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; +import com.amplifyframework.core.model.temporal.Temporal; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the HasOneParent type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"HasOneParents\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class HasOneParent implements Model { + public static final HasOneParentPath rootPath = new HasOneParentPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"HasOneParent\\", \\"id\\"); + public static final QueryField HAS_ONE_PARENT_CHILD_ID = field(\\"HasOneParent\\", \\"hasOneParentChildId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"HasOneChild\\") @HasOne(associatedWith = \\"id\\", type = HasOneChild.class) ModelReference child = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + private final @ModelField(targetType=\\"ID\\") String hasOneParentChildId; + public String getId() { + return id; + } + + public ModelReference getChild() { + return child; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + public String getHasOneParentChildId() { + return hasOneParentChildId; + } + + private HasOneParent(String id, String hasOneParentChildId) { + this.id = id; + this.hasOneParentChildId = hasOneParentChildId; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + HasOneParent hasOneParent = (HasOneParent) obj; + return ObjectsCompat.equals(getId(), hasOneParent.getId()) && + ObjectsCompat.equals(getCreatedAt(), hasOneParent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), hasOneParent.getUpdatedAt()) && + ObjectsCompat.equals(getHasOneParentChildId(), hasOneParent.getHasOneParentChildId()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .append(getHasOneParentChildId()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"HasOneParent {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") + .append(\\"hasOneParentChildId=\\" + String.valueOf(getHasOneParentChildId())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static HasOneParent justId(String id) { + return new HasOneParent( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + hasOneParentChildId); + } + public interface BuildStep { + HasOneParent build(); + BuildStep id(String id); + BuildStep hasOneParentChildId(String hasOneParentChildId); + } + + + public static class Builder implements BuildStep { + private String id; + private String hasOneParentChildId; + public Builder() { + + } + + private Builder(String id, String hasOneParentChildId) { + this.id = id; + this.hasOneParentChildId = hasOneParentChildId; + } + + @Override + public HasOneParent build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new HasOneParent( + id, + hasOneParentChildId); + } + + @Override + public BuildStep hasOneParentChildId(String hasOneParentChildId) { + this.hasOneParentChildId = hasOneParentChildId; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String hasOneParentChildId) { + super(id, hasOneParentChildId); + + } + + @Override + public CopyOfBuilder hasOneParentChildId(String hasOneParentChildId) { + return (CopyOfBuilder) super.hasOneParentChildId(hasOneParentChildId); + } + } + +} + +/** This is an auto generated class representing the HasOneChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"HasOneChildren\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class HasOneChild implements Model { + public static final HasOneChildPath rootPath = new HasOneChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"HasOneChild\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"HasOneChild\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private HasOneChild(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + HasOneChild hasOneChild = (HasOneChild) obj; + return ObjectsCompat.equals(getId(), hasOneChild.getId()) && + ObjectsCompat.equals(getContent(), hasOneChild.getContent()) && + ObjectsCompat.equals(getCreatedAt(), hasOneChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), hasOneChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"HasOneChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static HasOneChild justId(String id) { + return new HasOneChild( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content); + } + public interface BuildStep { + HasOneChild build(); + BuildStep id(String id); + BuildStep content(String content); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + public Builder() { + + } + + private Builder(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public HasOneChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new HasOneChild( + id, + content); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content) { + super(id, content); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor should generate for CompositePKParent and (CompositePK, Implicit, StrangeExplicit, ChildSansBelongsTo) Child models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; +" +`; diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap index f4a9a0cf8..c507ba6b0 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap @@ -132,6 +132,15 @@ public final class Post implements Model { public static class Builder implements IdStep, TitleStep, BuildStep { private String id; private String title; + public Builder() { + + } + + private Builder(String id, String title) { + this.id = id; + this.title = title; + } + @Override public Post build() { @@ -158,8 +167,9 @@ public final class Post implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String title) { - super.id(id) - .title(title); + super(id, title); + Objects.requireNonNull(id); + Objects.requireNonNull(title); } @Override @@ -337,6 +347,17 @@ public final class Comment implements Model { private String content; private String postCommentsId; private String postCommentsTitle; + public Builder() { + + } + + private Builder(String id, String content, String postCommentsId, String postCommentsTitle) { + this.id = id; + this.content = content; + this.postCommentsId = postCommentsId; + this.postCommentsTitle = postCommentsTitle; + } + @Override public Comment build() { @@ -377,10 +398,9 @@ public final class Comment implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String content, String postCommentsId, String postCommentsTitle) { - super.id(id) - .content(content) - .postCommentsId(postCommentsId) - .postCommentsTitle(postCommentsTitle); + super(id, content, postCommentsId, postCommentsTitle); + Objects.requireNonNull(id); + Objects.requireNonNull(content); } @Override @@ -574,6 +594,17 @@ public final class Project implements Model { private String name; private String projectTeamTeamId; private String projectTeamName; + public Builder() { + + } + + private Builder(String projectId, String name, String projectTeamTeamId, String projectTeamName) { + this.projectId = projectId; + this.name = name; + this.projectTeamTeamId = projectTeamTeamId; + this.projectTeamName = projectTeamName; + } + @Override public Project build() { @@ -614,10 +645,9 @@ public final class Project implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String projectId, String name, String projectTeamTeamId, String projectTeamName) { - super.projectId(projectId) - .name(name) - .projectTeamTeamId(projectTeamTeamId) - .projectTeamName(projectTeamName); + super(projectId, name, projectTeamTeamId, projectTeamName); + Objects.requireNonNull(projectId); + Objects.requireNonNull(name); } @Override @@ -793,6 +823,16 @@ public final class Team implements Model { private String teamId; private String name; private Project project; + public Builder() { + + } + + private Builder(String teamId, String name, Project project) { + this.teamId = teamId; + this.name = name; + this.project = project; + } + @Override public Team build() { @@ -826,9 +866,9 @@ public final class Team implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String teamId, String name, Project project) { - super.teamId(teamId) - .name(name) - .project(project); + super(teamId, name, project); + Objects.requireNonNull(teamId); + Objects.requireNonNull(name); } @Override @@ -1008,6 +1048,16 @@ public final class BlogOwnerWithCustomPKS implements Model { private String id; private String name; private String wea; + public Builder() { + + } + + private Builder(String id, String name, String wea) { + this.id = id; + this.name = name; + this.wea = wea; + } + @Override public BlogOwnerWithCustomPKS build() { @@ -1042,9 +1092,10 @@ public final class BlogOwnerWithCustomPKS implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String wea) { - super.id(id) - .name(name) - .wea(wea); + super(id, name, wea); + Objects.requireNonNull(id); + Objects.requireNonNull(name); + Objects.requireNonNull(wea); } @Override @@ -1245,6 +1296,18 @@ public final class Comment implements Model { private Integer likes; private Post post; private String description; + public Builder() { + + } + + private Builder(Post post, String title, String content, Integer likes, String description) { + this.post = post; + this.title = title; + this.content = content; + this.likes = likes; + this.description = description; + } + @Override public Comment build() { @@ -1293,11 +1356,10 @@ public final class Comment implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(Post post, String title, String content, Integer likes, String description) { - super.title(title) - .content(content) - .likes(likes) - .post(post) - .description(description); + super(post, title, content, likes, description); + Objects.requireNonNull(title); + Objects.requireNonNull(content); + Objects.requireNonNull(likes); } @Override @@ -1527,6 +1589,19 @@ public final class Post implements Model { private String blogID; private Temporal.DateTime created; private Blog blog; + public Builder() { + + } + + private Builder(String postId, String title, Integer rating, Temporal.DateTime created, String blogID, Blog blog) { + this.postId = postId; + this.title = title; + this.rating = rating; + this.created = created; + this.blogID = blogID; + this.blog = blog; + } + @Override public Post build() { @@ -1583,12 +1658,11 @@ public final class Post implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String postId, String title, Integer rating, Temporal.DateTime created, String blogId, Blog blog) { - super.postId(postId) - .title(title) - .rating(rating) - .blogId(blogId) - .created(created) - .blog(blog); + super(postId, title, rating, created, blogID, blog); + Objects.requireNonNull(postId); + Objects.requireNonNull(title); + Objects.requireNonNull(rating); + Objects.requireNonNull(blogID); } @Override @@ -1791,6 +1865,16 @@ public final class Blog implements Model { private String id; private String name; private BlogOwnerWithCustomPKS blogOwner; + public Builder() { + + } + + private Builder(String id, String name, BlogOwnerWithCustomPKS blogOwner) { + this.id = id; + this.name = name; + this.blogOwner = blogOwner; + } + @Override public Blog build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -1828,9 +1912,9 @@ public final class Blog implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, BlogOwnerWithCustomPKS blogOwner) { - super.id(id); - super.name(name) - .blogOwner(blogOwner); + super(id, name, blogOwner); + Objects.requireNonNull(name); + Objects.requireNonNull(blogOwner); } @Override @@ -2002,6 +2086,16 @@ public final class Post implements Model { private String id; private String title; private String content; + public Builder() { + + } + + private Builder(String id, String title, String content) { + this.id = id; + this.title = title; + this.content = content; + } + @Override public Post build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -2038,9 +2132,8 @@ public final class Post implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String title, String content) { - super.id(id); - super.title(title) - .content(content); + super(id, title, content); + Objects.requireNonNull(title); } @Override @@ -2167,6 +2260,15 @@ public final class Tag implements Model { public static class Builder implements LabelStep, BuildStep { private String id; private String label; + public Builder() { + + } + + private Builder(String id, String label) { + this.id = id; + this.label = label; + } + @Override public Tag build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -2196,8 +2298,8 @@ public final class Tag implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String label) { - super.id(id); - super.label(label); + super(id, label); + Objects.requireNonNull(label); } @Override @@ -2334,6 +2436,16 @@ public final class PostTags implements Model { private String id; private Post post; private Tag tag; + public Builder() { + + } + + private Builder(String id, Post post, Tag tag) { + this.id = id; + this.post = post; + this.tag = tag; + } + @Override public PostTags build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -2371,9 +2483,9 @@ public final class PostTags implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, Post post, Tag tag) { - super.id(id); - super.post(post) - .tag(tag); + super(id, post, tag); + Objects.requireNonNull(post); + Objects.requireNonNull(tag); } @Override @@ -2531,6 +2643,16 @@ public final class customClaim implements Model { private String id; private String name; private String bar; + public Builder() { + + } + + private Builder(String id, String name, String bar) { + this.id = id; + this.name = name; + this.bar = bar; + } + @Override public customClaim build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -2566,9 +2688,8 @@ public final class customClaim implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String bar) { - super.id(id); - super.name(name) - .bar(bar); + super(id, name, bar); + } @Override @@ -2726,6 +2847,16 @@ public final class customClaim implements Model { private String id; private String name; private String bar; + public Builder() { + + } + + private Builder(String id, String name, String bar) { + this.id = id; + this.name = name; + this.bar = bar; + } + @Override public customClaim build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -2761,9 +2892,8 @@ public final class customClaim implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String bar) { - super.id(id); - super.name(name) - .bar(bar); + super(id, name, bar); + } @Override @@ -2946,6 +3076,17 @@ public final class Employee implements Model { private String name; private String address; private String ssn; + public Builder() { + + } + + private Builder(String id, String name, String address, String ssn) { + this.id = id; + this.name = name; + this.address = address; + this.ssn = ssn; + } + @Override public Employee build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -2990,10 +3131,9 @@ public final class Employee implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String address, String ssn) { - super.id(id); - super.name(name) - .address(address) - .ssn(ssn); + super(id, name, address, ssn); + Objects.requireNonNull(name); + Objects.requireNonNull(address); } @Override @@ -3156,6 +3296,16 @@ public final class dynamicGroups implements Model { private String id; private String name; private String bar; + public Builder() { + + } + + private Builder(String id, String name, String bar) { + this.id = id; + this.name = name; + this.bar = bar; + } + @Override public dynamicGroups build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -3191,9 +3341,8 @@ public final class dynamicGroups implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String bar) { - super.id(id); - super.name(name) - .bar(bar); + super(id, name, bar); + } @Override @@ -3376,6 +3525,17 @@ public final class Employee implements Model { private String name; private String address; private String ssn; + public Builder() { + + } + + private Builder(String id, String name, String address, String ssn) { + this.id = id; + this.name = name; + this.address = address; + this.ssn = ssn; + } + @Override public Employee build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -3420,10 +3580,9 @@ public final class Employee implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String address, String ssn) { - super.id(id); - super.name(name) - .address(address) - .ssn(ssn); + super(id, name, address, ssn); + Objects.requireNonNull(name); + Objects.requireNonNull(address); } @Override @@ -3586,6 +3745,16 @@ public final class simpleOwnerAuth implements Model { private String id; private String name; private String bar; + public Builder() { + + } + + private Builder(String id, String name, String bar) { + this.id = id; + this.name = name; + this.bar = bar; + } + @Override public simpleOwnerAuth build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -3621,9 +3790,8 @@ public final class simpleOwnerAuth implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String bar) { - super.id(id); - super.name(name) - .bar(bar); + super(id, name, bar); + } @Override @@ -3781,6 +3949,16 @@ public final class allowRead implements Model { private String id; private String name; private String bar; + public Builder() { + + } + + private Builder(String id, String name, String bar) { + this.id = id; + this.name = name; + this.bar = bar; + } + @Override public allowRead build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -3816,9 +3994,8 @@ public final class allowRead implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String bar) { - super.id(id); - super.name(name) - .bar(bar); + super(id, name, bar); + } @Override @@ -3976,6 +4153,16 @@ public final class privateType implements Model { private String id; private String name; private String bar; + public Builder() { + + } + + private Builder(String id, String name, String bar) { + this.id = id; + this.name = name; + this.bar = bar; + } + @Override public privateType build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -4011,9 +4198,8 @@ public final class privateType implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String bar) { - super.id(id); - super.name(name) - .bar(bar); + super(id, name, bar); + } @Override @@ -4173,6 +4359,16 @@ public final class privateType implements Model { private String id; private String name; private String bar; + public Builder() { + + } + + private Builder(String id, String name, String bar) { + this.id = id; + this.name = name; + this.bar = bar; + } + @Override public privateType build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -4208,9 +4404,8 @@ public final class privateType implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String bar) { - super.id(id); - super.name(name) - .bar(bar); + super(id, name, bar); + } @Override @@ -4368,6 +4563,16 @@ public final class publicType implements Model { private String id; private String name; private String bar; + public Builder() { + + } + + private Builder(String id, String name, String bar) { + this.id = id; + this.name = name; + this.bar = bar; + } + @Override public publicType build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -4403,9 +4608,8 @@ public final class publicType implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String bar) { - super.id(id); - super.name(name) - .bar(bar); + super(id, name, bar); + } @Override @@ -4563,6 +4767,16 @@ public final class staticGroups implements Model { private String id; private String name; private String bar; + public Builder() { + + } + + private Builder(String id, String name, String bar) { + this.id = id; + this.name = name; + this.bar = bar; + } + @Override public staticGroups build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -4598,9 +4812,8 @@ public final class staticGroups implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String bar) { - super.id(id); - super.name(name) - .bar(bar); + super(id, name, bar); + } @Override @@ -4770,6 +4983,17 @@ public final class MyPost implements Model { private String title; private Temporal.DateTime createdAt; private Double rating; + public Builder() { + + } + + private Builder(String postId, String title, Temporal.DateTime createdAt, Double rating) { + this.postId = postId; + this.title = title; + this.createdAt = createdAt; + this.rating = rating; + } + @Override public MyPost build() { @@ -4812,10 +5036,11 @@ public final class MyPost implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String postId, String title, Temporal.DateTime createdAt, Double rating) { - super.postId(postId) - .title(title) - .createdAt(createdAt) - .rating(rating); + super(postId, title, createdAt, rating); + Objects.requireNonNull(postId); + Objects.requireNonNull(title); + Objects.requireNonNull(createdAt); + Objects.requireNonNull(rating); } @Override @@ -4956,6 +5181,14 @@ public final class StringModel implements Model { public static class Builder implements CustomKeyStep, BuildStep { private String customKey; + public Builder() { + + } + + private Builder(String customKey) { + this.customKey = customKey; + } + @Override public StringModel build() { @@ -4974,7 +5207,8 @@ public final class StringModel implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String customKey) { - super.customKey(customKey); + super(customKey); + Objects.requireNonNull(customKey); } @Override @@ -5100,6 +5334,14 @@ public final class IdModel implements Model { public static class Builder implements CustomKeyStep, BuildStep { private String customKey; + public Builder() { + + } + + private Builder(String customKey) { + this.customKey = customKey; + } + @Override public IdModel build() { @@ -5118,7 +5360,8 @@ public final class IdModel implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String customKey) { - super.customKey(customKey); + super(customKey); + Objects.requireNonNull(customKey); } @Override @@ -5244,6 +5487,14 @@ public final class IntModel implements Model { public static class Builder implements CustomKeyStep, BuildStep { private Integer customKey; + public Builder() { + + } + + private Builder(Integer customKey) { + this.customKey = customKey; + } + @Override public IntModel build() { @@ -5262,7 +5513,8 @@ public final class IntModel implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(Integer customKey) { - super.customKey(customKey); + super(customKey); + Objects.requireNonNull(customKey); } @Override @@ -5458,6 +5710,18 @@ public final class Landmark implements Model { private Integer rating; private Location location; private Location parking; + public Builder() { + + } + + private Builder(String id, String name, Integer rating, Location location, Location parking) { + this.id = id; + this.name = name; + this.rating = rating; + this.location = location; + this.parking = parking; + } + @Override public Landmark build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -5510,11 +5774,10 @@ public final class Landmark implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, Integer rating, Location location, Location parking) { - super.id(id); - super.name(name) - .rating(rating) - .location(location) - .parking(parking); + super(id, name, rating, location, parking); + Objects.requireNonNull(name); + Objects.requireNonNull(rating); + Objects.requireNonNull(location); } @Override @@ -5616,6 +5879,15 @@ public final class Location { public static class Builder implements LatStep, LangStep, BuildStep { private String lat; private String lang; + public Builder() { + + } + + private Builder(String lat, String lang) { + this.lat = lat; + this.lang = lang; + } + @Override public Location build() { @@ -5642,8 +5914,9 @@ public final class Location { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String lat, String lang) { - super.lat(lat) - .lang(lang); + super(lat, lang); + Objects.requireNonNull(lat); + Objects.requireNonNull(lang); } @Override @@ -5735,6 +6008,15 @@ public final class Reference { public static class Builder implements IdStep, IdTypeStep, BuildStep { private String id; private ReferenceIdTypeEnum idType; + public Builder() { + + } + + private Builder(String id, ReferenceIdTypeEnum idType) { + this.id = id; + this.idType = idType; + } + @Override public Reference build() { @@ -5761,8 +6043,9 @@ public final class Reference { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, ReferenceIdTypeEnum idType) { - super.id(id) - .idType(idType); + super(id, idType); + Objects.requireNonNull(id); + Objects.requireNonNull(idType); } @Override @@ -5930,6 +6213,17 @@ public final class task implements Model { private Todo todo; private Temporal.Time time; private Temporal.Date createdOn; + public Builder() { + + } + + private Builder(String id, Todo todo, Temporal.Time time, Temporal.Date createdOn) { + this.id = id; + this.todo = todo; + this.time = time; + this.createdOn = createdOn; + } + @Override public task build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -5972,10 +6266,8 @@ public final class task implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, Todo todo, Temporal.Time time, Temporal.Date createdOn) { - super.id(id); - super.todo(todo) - .time(time) - .createdOn(createdOn); + super(id, todo, time, createdOn); + } @Override @@ -6111,6 +6403,14 @@ public final class Todo implements Model { public static class Builder implements BuildStep { private String id; + public Builder() { + + } + + private Builder(String id) { + this.id = id; + } + @Override public Todo build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -6132,7 +6432,7 @@ public final class Todo implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id) { - super.id(id); + super(id); } } @@ -6276,6 +6576,16 @@ public final class SimpleModel implements Model { private String id; private String name; private String bar; + public Builder() { + + } + + private Builder(String id, String name, String bar) { + this.id = id; + this.name = name; + this.bar = bar; + } + @Override public SimpleModel build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -6311,9 +6621,8 @@ public final class SimpleModel implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String bar) { - super.id(id); - super.name(name) - .bar(bar); + super(id, name, bar); + } @Override @@ -6466,6 +6775,16 @@ public final class SimpleModel implements Model { private String id; private String name; private String bar; + public Builder() { + + } + + private Builder(String id, String name, String bar) { + this.id = id; + this.name = name; + this.bar = bar; + } + @Override public SimpleModel build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -6501,9 +6820,8 @@ public final class SimpleModel implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String bar) { - super.id(id); - super.name(name) - .bar(bar); + super(id, name, bar); + } @Override @@ -6756,6 +7074,22 @@ public final class ListContainer implements Model { private List list; private List listOfRequired; private List listOfRequiredFloats; + public Builder() { + + } + + private Builder(String id, String name, List list, List requiredList, List requiredListOfRequired, List listOfRequired, List requiredListOfRequiredDates, List listOfRequiredFloats, List requiredListOfCustomTypes) { + this.id = id; + this.name = name; + this.list = list; + this.requiredList = requiredList; + this.requiredListOfRequired = requiredListOfRequired; + this.listOfRequired = listOfRequired; + this.requiredListOfRequiredDates = requiredListOfRequiredDates; + this.listOfRequiredFloats = listOfRequiredFloats; + this.requiredListOfCustomTypes = requiredListOfCustomTypes; + } + @Override public ListContainer build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -6837,15 +7171,11 @@ public final class ListContainer implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, List list, List requiredList, List requiredListOfRequired, List listOfRequired, List requiredListOfRequiredDates, List listOfRequiredFloats, List requiredListOfCustomTypes) { - super.id(id); - super.requiredList(requiredList) - .requiredListOfRequired(requiredListOfRequired) - .requiredListOfRequiredDates(requiredListOfRequiredDates) - .requiredListOfCustomTypes(requiredListOfCustomTypes) - .name(name) - .list(list) - .listOfRequired(listOfRequired) - .listOfRequiredFloats(listOfRequiredFloats); + super(id, name, list, requiredList, requiredListOfRequired, listOfRequired, requiredListOfRequiredDates, listOfRequiredFloats, requiredListOfCustomTypes); + Objects.requireNonNull(requiredList); + Objects.requireNonNull(requiredListOfRequired); + Objects.requireNonNull(requiredListOfRequiredDates); + Objects.requireNonNull(requiredListOfCustomTypes); } @Override @@ -7079,6 +7409,19 @@ public final class task implements Model { private Todo todo; private Temporal.Time time; private Temporal.Date createdOn; + public Builder() { + + } + + private Builder(String id, String title, Boolean done, Todo todo, Temporal.Time time, Temporal.Date createdOn) { + this.id = id; + this.title = title; + this.done = done; + this.todo = todo; + this.time = time; + this.createdOn = createdOn; + } + @Override public task build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -7137,12 +7480,9 @@ public final class task implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String title, Boolean done, Todo todo, Temporal.Time time, Temporal.Date createdOn) { - super.id(id); - super.title(title) - .done(done) - .todo(todo) - .time(time) - .createdOn(createdOn); + super(id, title, done, todo, time, createdOn); + Objects.requireNonNull(title); + Objects.requireNonNull(done); } @Override @@ -7384,6 +7724,20 @@ public final class Todo implements Model { private String description; private String due_date; private Double value; + public Builder() { + + } + + private Builder(String id, String title, Boolean done, String description, String due_date, Integer version, Double value) { + this.id = id; + this.title = title; + this.done = done; + this.description = description; + this.due_date = due_date; + this.version = version; + this.value = value; + } + @Override public Todo build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -7450,13 +7804,10 @@ public final class Todo implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String title, Boolean done, String description, String dueDate, Integer version, Double value) { - super.id(id); - super.title(title) - .done(done) - .version(version) - .description(description) - .dueDate(dueDate) - .value(value); + super(id, title, done, description, due_date, version, value); + Objects.requireNonNull(title); + Objects.requireNonNull(done); + Objects.requireNonNull(version); } @Override @@ -7649,6 +8000,18 @@ public final class TypeWithAWSDateScalars implements Model { private Temporal.DateTime createdAt; private Temporal.Time time; private Temporal.Timestamp timestamp; + public Builder() { + + } + + private Builder(String id, Temporal.Date date, Temporal.DateTime createdAt, Temporal.Time time, Temporal.Timestamp timestamp) { + this.id = id; + this.date = date; + this.createdAt = createdAt; + this.time = time; + this.timestamp = timestamp; + } + @Override public TypeWithAWSDateScalars build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -7698,11 +8061,8 @@ public final class TypeWithAWSDateScalars implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, Temporal.Date date, Temporal.DateTime createdAt, Temporal.Time time, Temporal.Timestamp timestamp) { - super.id(id); - super.date(date) - .createdAt(createdAt) - .time(time) - .timestamp(timestamp); + super(id, date, createdAt, time, timestamp); + } @Override @@ -7914,6 +8274,18 @@ public final class authorBook implements Model { private String book_id; private String author; private String book; + public Builder() { + + } + + private Builder(String id, String author_id, String book_id, String author, String book) { + this.id = id; + this.author_id = author_id; + this.book_id = book_id; + this.author = author; + this.book = book; + } + @Override public authorBook build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -7965,11 +8337,9 @@ public final class authorBook implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String authorId, String bookId, String author, String book) { - super.id(id); - super.authorId(authorId) - .bookId(bookId) - .author(author) - .book(book); + super(id, author_id, book_id, author, book); + Objects.requireNonNull(author_id); + Objects.requireNonNull(book_id); } @Override @@ -8118,6 +8488,15 @@ public final class NonCamelCaseField implements Model { public static class Builder implements BuildStep { private String id; private String employeePID; + public Builder() { + + } + + private Builder(String id, String employeePID) { + this.id = id; + this.employeePID = employeePID; + } + @Override public NonCamelCaseField build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -8146,8 +8525,8 @@ public final class NonCamelCaseField implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String employeePid) { - super.id(id); - super.employeePid(employeePid); + super(id, employeePID); + } @Override @@ -8281,6 +8660,15 @@ public final class snake_case implements Model { public static class Builder implements BuildStep { private String id; private String name; + public Builder() { + + } + + private Builder(String id, String name) { + this.id = id; + this.name = name; + } + @Override public snake_case build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -8309,8 +8697,8 @@ public final class snake_case implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name) { - super.id(id); - super.name(name); + super(id, name); + } @Override @@ -8444,6 +8832,15 @@ public final class SnakeCaseField implements Model { public static class Builder implements BuildStep { private String id; private String first_name; + public Builder() { + + } + + private Builder(String id, String first_name) { + this.id = id; + this.first_name = first_name; + } + @Override public SnakeCaseField build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -8472,8 +8869,8 @@ public final class SnakeCaseField implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String firstName) { - super.id(id); - super.firstName(firstName); + super(id, first_name); + } @Override diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts new file mode 100644 index 000000000..8321dddb2 --- /dev/null +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts @@ -0,0 +1,140 @@ +import { buildSchema, GraphQLSchema, parse, visit } from 'graphql'; +import { validateJava } from '../utils/validate-java'; +import { directives, scalars } from '../../scalars/supported-directives'; +import { AppSyncModelJavaVisitor } from '../../visitors/appsync-java-visitor'; +import { CodeGenGenerateEnum } from '../../visitors/appsync-visitor'; +import { JAVA_SCALAR_MAP } from '../../scalars'; + +const defaultJavaVisitorSettings = { + isTimestampFieldsAdded: true, + handleListNullabilityTransparently: true, + transformerVersion: 2, + generate: CodeGenGenerateEnum.code, + respectPrimaryKeyAttributesOnConnectionField: false, + generateModelsForLazyLoadAndCustomSelectionSet: true +} +const buildSchemaWithDirectives = (schema: String): GraphQLSchema => { + return buildSchema([schema, directives, scalars].join('\n')); +}; + + +const getVisitor = ( + schema: string, + selectedType?: string, + settings: any = {} +) => { + const visitorConfig = { ...defaultJavaVisitorSettings, ...settings }; + const ast = parse(schema); + const builtSchema = buildSchemaWithDirectives(schema); + const visitor = new AppSyncModelJavaVisitor( + builtSchema, + { + directives, + target: 'java', + scalars: JAVA_SCALAR_MAP, + ...visitorConfig + }, + { selectedType }, + ); + visit(ast, { leave: visitor }); + return visitor; +}; + +const getVisitorPipelinedTransformer = ( + schema: string, + selectedType?: string, + settings: any = {} +) => { + return getVisitor(schema, selectedType, { ...settings, transformerVersion: 2 }); +}; + +describe('AppSyncModelVisitor', () => { + + it('Should generate for HasOneParent HasOneChild models', () => { + const schema = /* GraphQL */ ` + type HasOneParent @model { + id: ID! @primaryKey + child: HasOneChild @hasOne + } + + type HasOneChild @model { + id: ID! @primaryKey + content: String + } + `; + + const visitor = getVisitor(schema); + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); + + it('Should generate for DefaultPKParent DefaultPKChild models', () => { + const schema = /* GraphQL */ ` + type DefaultPKParent @model { + id: ID! @primaryKey + content: String + children: [DefaultPKChild] @hasMany + } + + type DefaultPKChild @model { + id: ID! @primaryKey + content: String + parent: DefaultPKParent @belongsTo + } + `; + + const visitor = getVisitor(schema); + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); + + it('should generate for CompositePKParent and (CompositePK, Implicit, StrangeExplicit, ChildSansBelongsTo) Child models', () => { + const schema = /* GraphQL */ ` + type CompositePKParent @model { + customId: ID! @primaryKey(sortKeyFields:["content"]) + content: String! + children: [CompositePKChild] @hasMany(indexName:"byParent", fields:["customId", "content"]) + implicitChildren: [ImplicitChild] @hasMany + strangeChildren: [StrangeExplicitChild] @hasMany(indexName: "byCompositePKParentX", fields: ["customId", "content"]) + childrenSansBelongsTo: [ChildSansBelongsTo] @hasMany + } + + type CompositePKChild @model { + childId: ID! @primaryKey(sortKeyFields:["content"]) + content: String! + parent: CompositePKParent @belongsTo(fields:["parentId", "parentTitle"]) + parentId: ID @index(name: "byParent", sortKeyFields:["parentTitle"]) + parentTitle: String + } + + type ImplicitChild @model { + childId: ID! @primaryKey(sortKeyFields:["content"]) + content: String! + parent: CompositePKParent! @belongsTo + } + + type StrangeExplicitChild @model { + strangeId: ID! @primaryKey(sortKeyFields:["content"]) + content: String! + parent: CompositePKParent! @belongsTo(fields:["strangeParentId", "strangeParentTitle"]) + strangeParentId: ID @index(name: "byCompositePKParentX", sortKeyFields:["strangeParentTitle"]) + strangeParentTitle: String # customized foreign key for parent sort key + } + + type ChildSansBelongsTo @model { + childId: ID! @primaryKey(sortKeyFields:["content"]) + content: String! + compositePKParentChildrenSansBelongsToCustomId: ID! @index(name: "byParent", sortKeyFields: ["compositePKParentChildrenSansBelongsToContent"]) + compositePKParentChildrenSansBelongsToContent: String + } + `; + + const visitor = getVisitor(schema, 'status'); + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); +}); + diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/gqlv2-regression-tests/__snapshots__/appsync-java-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/gqlv2-regression-tests/__snapshots__/appsync-java-visitor.test.ts.snap index 9003768aa..187cc3ca4 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/gqlv2-regression-tests/__snapshots__/appsync-java-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/gqlv2-regression-tests/__snapshots__/appsync-java-visitor.test.ts.snap @@ -131,6 +131,15 @@ public final class Post implements Model { public static class Builder implements TitleStep, BuildStep { private String id; private String title; + public Builder() { + + } + + private Builder(String id, String title) { + this.id = id; + this.title = title; + } + @Override public Post build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -160,8 +169,8 @@ public final class Post implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String title) { - super.id(id); - super.title(title); + super(id, title); + Objects.requireNonNull(title); } @Override @@ -315,6 +324,16 @@ public final class Comment implements Model { private String id; private String content; private Post post; + public Builder() { + + } + + private Builder(String id, String content, Post post) { + this.id = id; + this.content = content; + this.post = post; + } + @Override public Comment build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -351,9 +370,8 @@ public final class Comment implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String content, Post post) { - super.id(id); - super.content(content) - .post(post); + super(id, content, post); + Objects.requireNonNull(content); } @Override @@ -512,6 +530,16 @@ public final class Project2 implements Model { private String id; private String name; private String project2TeamId; + public Builder() { + + } + + private Builder(String id, String name, String project2TeamId) { + this.id = id; + this.name = name; + this.project2TeamId = project2TeamId; + } + @Override public Project2 build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -547,9 +575,8 @@ public final class Project2 implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String project2TeamId) { - super.id(id); - super.name(name) - .project2TeamId(project2TeamId); + super(id, name, project2TeamId); + } @Override @@ -707,6 +734,16 @@ public final class Team2 implements Model { private String id; private String name; private Project2 project; + public Builder() { + + } + + private Builder(String id, String name, Project2 project) { + this.id = id; + this.name = name; + this.project = project; + } + @Override public Team2 build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -743,9 +780,8 @@ public final class Team2 implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, Project2 project) { - super.id(id); - super.name(name) - .project(project); + super(id, name, project); + Objects.requireNonNull(name); } @Override @@ -894,6 +930,15 @@ public final class Blog7V2 implements Model { public static class Builder implements NameStep, BuildStep { private String id; private String name; + public Builder() { + + } + + private Builder(String id, String name) { + this.id = id; + this.name = name; + } + @Override public Blog7V2 build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -923,8 +968,8 @@ public final class Blog7V2 implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name) { - super.id(id); - super.name(name); + super(id, name); + Objects.requireNonNull(name); } @Override @@ -1083,6 +1128,16 @@ public final class Post7V2 implements Model { private String id; private String title; private Blog7V2 blog; + public Builder() { + + } + + private Builder(String id, String title, Blog7V2 blog) { + this.id = id; + this.title = title; + this.blog = blog; + } + @Override public Post7V2 build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -1119,9 +1174,8 @@ public final class Post7V2 implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String title, Blog7V2 blog) { - super.id(id); - super.title(title) - .blog(blog); + super(id, title, blog); + Objects.requireNonNull(title); } @Override @@ -1275,6 +1329,16 @@ public final class Comment7V2 implements Model { private String id; private String content; private Post7V2 post; + public Builder() { + + } + + private Builder(String id, String content, Post7V2 post) { + this.id = id; + this.content = content; + this.post = post; + } + @Override public Comment7V2 build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -1310,9 +1374,8 @@ public final class Comment7V2 implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String content, Post7V2 post) { - super.id(id); - super.content(content) - .post(post); + super(id, content, post); + } @Override @@ -1471,6 +1534,16 @@ public final class Project implements Model { private String id; private String name; private String projectTeamId; + public Builder() { + + } + + private Builder(String id, String name, String projectTeamId) { + this.id = id; + this.name = name; + this.projectTeamId = projectTeamId; + } + @Override public Project build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -1506,9 +1579,8 @@ public final class Project implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String projectTeamId) { - super.id(id); - super.name(name) - .projectTeamId(projectTeamId); + super(id, name, projectTeamId); + } @Override @@ -1666,6 +1738,16 @@ public final class Team implements Model { private String id; private String name; private Project project; + public Builder() { + + } + + private Builder(String id, String name, Project project) { + this.id = id; + this.name = name; + this.project = project; + } + @Override public Team build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -1702,9 +1784,8 @@ public final class Team implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, Project project) { - super.id(id); - super.name(name) - .project(project); + super(id, name, project); + Objects.requireNonNull(name); } @Override @@ -1867,6 +1948,16 @@ public final class Post implements Model { private String id; private String title; private String content; + public Builder() { + + } + + private Builder(String id, String title, String content) { + this.id = id; + this.title = title; + this.content = content; + } + @Override public Post build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -1903,9 +1994,8 @@ public final class Post implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String title, String content) { - super.id(id); - super.title(title) - .content(content); + super(id, title, content); + Objects.requireNonNull(title); } @Override @@ -2054,6 +2144,15 @@ public final class Tag implements Model { public static class Builder implements LabelStep, BuildStep { private String id; private String label; + public Builder() { + + } + + private Builder(String id, String label) { + this.id = id; + this.label = label; + } + @Override public Tag build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -2083,8 +2182,8 @@ public final class Tag implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String label) { - super.id(id); - super.label(label); + super(id, label); + Objects.requireNonNull(label); } @Override @@ -2218,6 +2317,15 @@ public final class Todo implements Model { public static class Builder implements BuildStep { private String id; private String content; + public Builder() { + + } + + private Builder(String id, String content) { + this.id = id; + this.content = content; + } + @Override public Todo build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -2246,8 +2354,8 @@ public final class Todo implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String content) { - super.id(id); - super.content(content); + super(id, content); + } @Override @@ -2391,6 +2499,15 @@ public final class Post2 implements Model { public static class Builder implements TitleStep, BuildStep { private String id; private String title; + public Builder() { + + } + + private Builder(String id, String title) { + this.id = id; + this.title = title; + } + @Override public Post2 build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -2420,8 +2537,8 @@ public final class Post2 implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String title) { - super.id(id); - super.title(title); + super(id, title); + Objects.requireNonNull(title); } @Override @@ -2578,6 +2695,16 @@ public final class Comment2 implements Model { private String id; private String postID; private String content; + public Builder() { + + } + + private Builder(String id, String postID, String content) { + this.id = id; + this.postID = postID; + this.content = content; + } + @Override public Comment2 build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -2615,9 +2742,9 @@ public final class Comment2 implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String postId, String content) { - super.id(id); - super.postId(postId) - .content(content); + super(id, postID, content); + Objects.requireNonNull(postID); + Objects.requireNonNull(content); } @Override @@ -2776,6 +2903,16 @@ public final class Project2 implements Model { private String id; private String name; private String teamID; + public Builder() { + + } + + private Builder(String id, String name, String teamID) { + this.id = id; + this.name = name; + this.teamID = teamID; + } + @Override public Project2 build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -2811,9 +2948,8 @@ public final class Project2 implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String teamId) { - super.id(id); - super.name(name) - .teamId(teamId); + super(id, name, teamID); + } @Override @@ -2956,6 +3092,15 @@ public final class Team2 implements Model { public static class Builder implements NameStep, BuildStep { private String id; private String name; + public Builder() { + + } + + private Builder(String id, String name) { + this.id = id; + this.name = name; + } + @Override public Team2 build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -2985,8 +3130,8 @@ public final class Team2 implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name) { - super.id(id); - super.name(name); + super(id, name); + Objects.requireNonNull(name); } @Override @@ -3130,6 +3275,15 @@ public final class Post implements Model { public static class Builder implements TitleStep, BuildStep { private String id; private String title; + public Builder() { + + } + + private Builder(String id, String title) { + this.id = id; + this.title = title; + } + @Override public Post build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -3159,8 +3313,8 @@ public final class Post implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String title) { - super.id(id); - super.title(title); + super(id, title); + Objects.requireNonNull(title); } @Override @@ -3312,6 +3466,16 @@ public final class Comment implements Model { private String id; private String content; private String postCommentsId; + public Builder() { + + } + + private Builder(String id, String content, String postCommentsId) { + this.id = id; + this.content = content; + this.postCommentsId = postCommentsId; + } + @Override public Comment build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -3348,9 +3512,8 @@ public final class Comment implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String content, String postCommentsId) { - super.id(id); - super.content(content) - .postCommentsId(postCommentsId); + super(id, content, postCommentsId); + Objects.requireNonNull(content); } @Override @@ -3509,6 +3672,16 @@ public final class Project implements Model { private String id; private String name; private String projectTeamId; + public Builder() { + + } + + private Builder(String id, String name, String projectTeamId) { + this.id = id; + this.name = name; + this.projectTeamId = projectTeamId; + } + @Override public Project build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -3544,9 +3717,8 @@ public final class Project implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String projectTeamId) { - super.id(id); - super.name(name) - .projectTeamId(projectTeamId); + super(id, name, projectTeamId); + } @Override @@ -3689,6 +3861,15 @@ public final class Team implements Model { public static class Builder implements NameStep, BuildStep { private String id; private String name; + public Builder() { + + } + + private Builder(String id, String name) { + this.id = id; + this.name = name; + } + @Override public Team build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -3718,8 +3899,8 @@ public final class Team implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name) { - super.id(id); - super.name(name); + super(id, name); + Objects.requireNonNull(name); } @Override @@ -3890,6 +4071,17 @@ public final class Customer implements Model { private String name; private String accountRepresentativeID; private String phoneNumber; + public Builder() { + + } + + private Builder(String id, String name, String phoneNumber, String accountRepresentativeID) { + this.id = id; + this.name = name; + this.phoneNumber = phoneNumber; + this.accountRepresentativeID = accountRepresentativeID; + } + @Override public Customer build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -3934,10 +4126,9 @@ public final class Customer implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String phoneNumber, String accountRepresentativeId) { - super.id(id); - super.name(name) - .accountRepresentativeId(accountRepresentativeId) - .phoneNumber(phoneNumber); + super(id, name, phoneNumber, accountRepresentativeID); + Objects.requireNonNull(name); + Objects.requireNonNull(accountRepresentativeID); } @Override @@ -4118,6 +4309,17 @@ public final class Customer implements Model { private String name; private String accountRepresentativeID; private String phoneNumber; + public Builder() { + + } + + private Builder(String id, String name, String phoneNumber, String accountRepresentativeID) { + this.id = id; + this.name = name; + this.phoneNumber = phoneNumber; + this.accountRepresentativeID = accountRepresentativeID; + } + @Override public Customer build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -4162,10 +4364,9 @@ public final class Customer implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name, String phoneNumber, String accountRepresentativeId) { - super.id(id); - super.name(name) - .accountRepresentativeId(accountRepresentativeId) - .phoneNumber(phoneNumber); + super(id, name, phoneNumber, accountRepresentativeID); + Objects.requireNonNull(name); + Objects.requireNonNull(accountRepresentativeID); } @Override diff --git a/packages/graphql-generator/src/__tests__/__snapshots__/models.test.ts.snap b/packages/graphql-generator/src/__tests__/__snapshots__/models.test.ts.snap index 5fb032e28..a4af66343 100644 --- a/packages/graphql-generator/src/__tests__/__snapshots__/models.test.ts.snap +++ b/packages/graphql-generator/src/__tests__/__snapshots__/models.test.ts.snap @@ -1097,7 +1097,7 @@ public final class AmplifyModelProvider implements ModelProvider { } - public static AmplifyModelProvider getInstance() { + public static synchronized AmplifyModelProvider getInstance() { if (amplifyGeneratedModelInstance == null) { amplifyGeneratedModelInstance = new AmplifyModelProvider(); } @@ -1133,6 +1133,7 @@ public final class AmplifyModelProvider implements ModelProvider { "com/amplifyframework/datastore/generated/model/Blog.java": "package com.amplifyframework.datastore.generated.model; import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.ModelList; import com.amplifyframework.core.model.temporal.Temporal; import com.amplifyframework.core.model.ModelIdentifier; @@ -1152,13 +1153,14 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field; /** This is an auto generated class representing the Blog type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"Blogs\\", type = Model.Type.USER, version = 1) +@ModelConfig(pluralName = \\"Blogs\\", type = Model.Type.USER, version = 1, hasLazySupport = true) public final class Blog implements Model { + public static final BlogPath rootPath = new BlogPath(\\"root\\", false, null); public static final QueryField ID = field(\\"Blog\\", \\"id\\"); public static final QueryField NAME = field(\\"Blog\\", \\"name\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; private final @ModelField(targetType=\\"String\\", isRequired = true) String name; - private final @ModelField(targetType=\\"Post\\") @HasMany(associatedWith = \\"blog\\", type = Post.class) List posts = null; + private final @ModelField(targetType=\\"Post\\") @HasMany(associatedWith = \\"blog\\", type = Post.class) ModelList posts = null; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; /** @deprecated This API is internal to Amplify and should not be used. */ @@ -1175,7 +1177,7 @@ public final class Blog implements Model { return name; } - public List getPosts() { + public ModelList getPosts() { return posts; } @@ -1267,6 +1269,15 @@ public final class Blog implements Model { public static class Builder implements NameStep, BuildStep { private String id; private String name; + public Builder() { + + } + + private Builder(String id, String name) { + this.id = id; + this.name = name; + } + @Override public Blog build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -1296,8 +1307,8 @@ public final class Blog implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String name) { - super.id(id); - super.name(name); + super(id, name); + Objects.requireNonNull(name); } @Override @@ -1315,10 +1326,35 @@ public final class Blog implements Model { } } +", + "com/amplifyframework/datastore/generated/model/BlogPath.java": "package com.amplifyframework.datastore.generated.model; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.amplifyframework.core.model.ModelPath; +import com.amplifyframework.core.model.PropertyPath; + +/** This is an auto generated class representing the ModelPath for the Blog type in your schema. */ +public final class BlogPath extends ModelPath { + private PostPath posts; + BlogPath(@NonNull String name, @NonNull Boolean isCollection, @Nullable PropertyPath parent) { + super(name, isCollection, parent, Blog.class); + } + + public synchronized PostPath getPosts() { + if (posts == null) { + posts = new PostPath(\\"posts\\", true, this); + } + return posts; + } +} ", "com/amplifyframework/datastore/generated/model/Comment.java": "package com.amplifyframework.datastore.generated.model; import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; import com.amplifyframework.core.model.temporal.Temporal; import com.amplifyframework.core.model.ModelIdentifier; @@ -1338,13 +1374,14 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field; /** This is an auto generated class representing the Comment type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"Comments\\", type = Model.Type.USER, version = 1) +@ModelConfig(pluralName = \\"Comments\\", type = Model.Type.USER, version = 1, hasLazySupport = true) public final class Comment implements Model { + public static final CommentPath rootPath = new CommentPath(\\"root\\", false, null); public static final QueryField ID = field(\\"Comment\\", \\"id\\"); public static final QueryField POST = field(\\"Comment\\", \\"postCommentsId\\"); public static final QueryField CONTENT = field(\\"Comment\\", \\"content\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"Post\\") @BelongsTo(targetName = \\"postCommentsId\\", targetNames = {\\"postCommentsId\\"}, type = Post.class) Post post; + private final @ModelField(targetType=\\"Post\\") @BelongsTo(targetName = \\"postCommentsId\\", targetNames = {\\"postCommentsId\\"}, type = Post.class) ModelReference post; private final @ModelField(targetType=\\"String\\", isRequired = true) String content; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; @@ -1358,7 +1395,7 @@ public final class Comment implements Model { return id; } - public Post getPost() { + public ModelReference getPost() { return post; } @@ -1374,7 +1411,7 @@ public final class Comment implements Model { return updatedAt; } - private Comment(String id, Post post, String content) { + private Comment(String id, ModelReference post, String content) { this.id = id; this.post = post; this.content = content; @@ -1461,7 +1498,17 @@ public final class Comment implements Model { public static class Builder implements ContentStep, BuildStep { private String id; private String content; - private Post post; + private ModelReference post; + public Builder() { + + } + + private Builder(String id, ModelReference post, String content) { + this.id = id; + this.post = post; + this.content = content; + } + @Override public Comment build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -1481,7 +1528,7 @@ public final class Comment implements Model { @Override public BuildStep post(Post post) { - this.post = post; + this.post = new LoadedModelReferenceImpl<>(post); return this; } @@ -1497,10 +1544,9 @@ public final class Comment implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, Post post, String content) { - super.id(id); - super.content(content) - .post(post); + private CopyOfBuilder(String id, ModelReference post, String content) { + super(id, post, content); + Objects.requireNonNull(content); } @Override @@ -1523,11 +1569,37 @@ public final class Comment implements Model { } } +", + "com/amplifyframework/datastore/generated/model/CommentPath.java": "package com.amplifyframework.datastore.generated.model; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.amplifyframework.core.model.ModelPath; +import com.amplifyframework.core.model.PropertyPath; + +/** This is an auto generated class representing the ModelPath for the Comment type in your schema. */ +public final class CommentPath extends ModelPath { + private PostPath post; + CommentPath(@NonNull String name, @NonNull Boolean isCollection, @Nullable PropertyPath parent) { + super(name, isCollection, parent, Comment.class); + } + + public synchronized PostPath getPost() { + if (post == null) { + post = new PostPath(\\"post\\", false, this); + } + return post; + } +} ", "com/amplifyframework/datastore/generated/model/Post.java": "package com.amplifyframework.datastore.generated.model; import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.ModelList; import com.amplifyframework.core.model.temporal.Temporal; import com.amplifyframework.core.model.ModelIdentifier; @@ -1547,15 +1619,16 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field; /** This is an auto generated class representing the Post type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"Posts\\", type = Model.Type.USER, version = 1) +@ModelConfig(pluralName = \\"Posts\\", type = Model.Type.USER, version = 1, hasLazySupport = true) public final class Post implements Model { + public static final PostPath rootPath = new PostPath(\\"root\\", false, null); public static final QueryField ID = field(\\"Post\\", \\"id\\"); public static final QueryField TITLE = field(\\"Post\\", \\"title\\"); public static final QueryField BLOG = field(\\"Post\\", \\"blogPostsId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; private final @ModelField(targetType=\\"String\\", isRequired = true) String title; - private final @ModelField(targetType=\\"Blog\\") @BelongsTo(targetName = \\"blogPostsId\\", targetNames = {\\"blogPostsId\\"}, type = Blog.class) Blog blog; - private final @ModelField(targetType=\\"Comment\\") @HasMany(associatedWith = \\"post\\", type = Comment.class) List comments = null; + private final @ModelField(targetType=\\"Blog\\") @BelongsTo(targetName = \\"blogPostsId\\", targetNames = {\\"blogPostsId\\"}, type = Blog.class) ModelReference blog; + private final @ModelField(targetType=\\"Comment\\") @HasMany(associatedWith = \\"post\\", type = Comment.class) ModelList comments = null; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; /** @deprecated This API is internal to Amplify and should not be used. */ @@ -1572,11 +1645,11 @@ public final class Post implements Model { return title; } - public Blog getBlog() { + public ModelReference getBlog() { return blog; } - public List getComments() { + public ModelList getComments() { return comments; } @@ -1588,7 +1661,7 @@ public final class Post implements Model { return updatedAt; } - private Post(String id, String title, Blog blog) { + private Post(String id, String title, ModelReference blog) { this.id = id; this.title = title; this.blog = blog; @@ -1675,7 +1748,17 @@ public final class Post implements Model { public static class Builder implements TitleStep, BuildStep { private String id; private String title; - private Blog blog; + private ModelReference blog; + public Builder() { + + } + + private Builder(String id, String title, ModelReference blog) { + this.id = id; + this.title = title; + this.blog = blog; + } + @Override public Post build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -1695,7 +1778,7 @@ public final class Post implements Model { @Override public BuildStep blog(Blog blog) { - this.blog = blog; + this.blog = new LoadedModelReferenceImpl<>(blog); return this; } @@ -1711,10 +1794,9 @@ public final class Post implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String title, Blog blog) { - super.id(id); - super.title(title) - .blog(blog); + private CopyOfBuilder(String id, String title, ModelReference blog) { + super(id, title, blog); + Objects.requireNonNull(title); } @Override @@ -1737,6 +1819,37 @@ public final class Post implements Model { } } +", + "com/amplifyframework/datastore/generated/model/PostPath.java": "package com.amplifyframework.datastore.generated.model; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.amplifyframework.core.model.ModelPath; +import com.amplifyframework.core.model.PropertyPath; + +/** This is an auto generated class representing the ModelPath for the Post type in your schema. */ +public final class PostPath extends ModelPath { + private BlogPath blog; + private CommentPath comments; + PostPath(@NonNull String name, @NonNull Boolean isCollection, @Nullable PropertyPath parent) { + super(name, isCollection, parent, Post.class); + } + + public synchronized BlogPath getBlog() { + if (blog == null) { + blog = new BlogPath(\\"blog\\", false, this); + } + return blog; + } + + public synchronized CommentPath getComments() { + if (comments == null) { + comments = new CommentPath(\\"comments\\", true, this); + } + return comments; + } +} ", } `; From 79ad44a40b08f715c6eb6bf6790fb66f1cac2ad2 Mon Sep 17 00:00:00 2001 From: tjroach Date: Thu, 14 Sep 2023 09:26:30 -0400 Subject: [PATCH 12/30] lint --- .../src/visitors/appsync-java-visitor.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index 5f727e5d5..e2456a03b 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -615,11 +615,11 @@ export class AppSyncModelJavaVisitor< ).trim(); copyOfBuilderClassDeclaration.addClassMethod( - builderName, - null, - `super(${superArgs});\n${constructorNullChecks}`, - constructorArguments, - [], + builderName, + null, + `super(${superArgs});\n${constructorNullChecks}`, + constructorArguments, + [], 'private' ); From 76653094a37cf600b674ab38b7b199e6903f80b3 Mon Sep 17 00:00:00 2001 From: Michael Law <1365977+lawmicha@users.noreply.github.com> Date: Thu, 14 Sep 2023 10:08:35 -0400 Subject: [PATCH 13/30] generate CompositePKParent files correctly --- ...java-api-lazyload-css-visitor.test.ts.snap | 1218 +++++++++++++++++ ...sync-java-api-lazyload-css-visitor.test.ts | 2 +- 2 files changed, 1219 insertions(+), 1 deletion(-) diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap index 2c8c3a623..4a0b5f791 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap @@ -702,6 +702,12 @@ public final class HasOneChild implements Model { exports[`AppSyncModelVisitor should generate for CompositePKParent and (CompositePK, Implicit, StrangeExplicit, ChildSansBelongsTo) Child models 1`] = ` "package com.amplifyframework.datastore.generated.model; +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.ModelList; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; import java.util.List; import java.util.UUID; @@ -716,5 +722,1217 @@ import com.amplifyframework.core.model.annotations.ModelField; import com.amplifyframework.core.model.query.predicate.QueryField; import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the CompositePKParent type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"CompositePKParents\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"customId\\",\\"content\\"}) +public final class CompositePKParent implements Model { + public static final CompositePKParentPath rootPath = new CompositePKParentPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"CompositePKParent\\", \\"id\\"); + public static final QueryField CUSTOM_ID = field(\\"CompositePKParent\\", \\"customId\\"); + public static final QueryField CONTENT = field(\\"CompositePKParent\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String customId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKChild\\") @HasMany(associatedWith = \\"parent\\", type = CompositePKChild.class) ModelList children = null; + private final @ModelField(targetType=\\"ImplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = ImplicitChild.class) ModelList implicitChildren = null; + private final @ModelField(targetType=\\"StrangeExplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = StrangeExplicitChild.class) ModelList strangeChildren = null; + private final @ModelField(targetType=\\"ChildSansBelongsTo\\") @HasMany(associatedWith = \\"compositePKParentChildrenSansBelongsToId\\", type = ChildSansBelongsTo.class) ModelList childrenSansBelongsTo = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getCustomId() { + return customId; + } + + public String getContent() { + return content; + } + + public ModelList getChildren() { + return children; + } + + public ModelList getImplicitChildren() { + return implicitChildren; + } + + public ModelList getStrangeChildren() { + return strangeChildren; + } + + public ModelList getChildrenSansBelongsTo() { + return childrenSansBelongsTo; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private CompositePKParent(String id, String customId, String content) { + this.id = id; + this.customId = customId; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + CompositePKParent compositePkParent = (CompositePKParent) obj; + return ObjectsCompat.equals(getId(), compositePkParent.getId()) && + ObjectsCompat.equals(getCustomId(), compositePkParent.getCustomId()) && + ObjectsCompat.equals(getContent(), compositePkParent.getContent()) && + ObjectsCompat.equals(getCreatedAt(), compositePkParent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), compositePkParent.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getCustomId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"CompositePKParent {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"customId=\\" + String.valueOf(getCustomId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static CustomIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static CompositePKParent justId(String id) { + return new CompositePKParent( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + customId, + content); + } + public interface CustomIdStep { + ContentStep customId(String customId); + } + + + public interface ContentStep { + BuildStep content(String content); + } + + + public interface BuildStep { + CompositePKParent build(); + BuildStep id(String id); + } + + + public static class Builder implements CustomIdStep, ContentStep, BuildStep { + private String id; + private String customId; + private String content; + public Builder() { + + } + + private Builder(String id, String customId, String content) { + this.id = id; + this.customId = customId; + this.content = content; + } + + @Override + public CompositePKParent build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new CompositePKParent( + id, + customId, + content); + } + + @Override + public ContentStep customId(String customId) { + Objects.requireNonNull(customId); + this.customId = customId; + return this; + } + + @Override + public BuildStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String customId, String content) { + super(id, customId, content); + Objects.requireNonNull(customId); + Objects.requireNonNull(content); + } + + @Override + public CopyOfBuilder customId(String customId) { + return (CopyOfBuilder) super.customId(customId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + +} + +/** This is an auto generated class representing the CompositePKChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"CompositePKChildren\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) +@Index(name = \\"byParent\\", fields = {\\"parentId\\",\\"parentTitle\\"}) +public final class CompositePKChild implements Model { + public static final CompositePKChildPath rootPath = new CompositePKChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"CompositePKChild\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"CompositePKChild\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"CompositePKChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"CompositePKChild\\", \\"parentId\\"); + public static final QueryField PARENT_TITLE = field(\\"CompositePKChild\\", \\"parentTitle\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKParent\\") @BelongsTo(targetName = \\"parentId\\", type = CompositePKParent.class) ModelReference parent; + private final @ModelField(targetType=\\"String\\") String parentTitle; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getChildId() { + return childId; + } + + public String getContent() { + return content; + } + + public ModelReference getParent() { + return parent; + } + + public String getParentTitle() { + return parentTitle; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private CompositePKChild(String id, String childId, String content, ModelReference parent, String parentTitle) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + this.parentTitle = parentTitle; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + CompositePKChild compositePkChild = (CompositePKChild) obj; + return ObjectsCompat.equals(getId(), compositePkChild.getId()) && + ObjectsCompat.equals(getChildId(), compositePkChild.getChildId()) && + ObjectsCompat.equals(getContent(), compositePkChild.getContent()) && + ObjectsCompat.equals(getParent(), compositePkChild.getParent()) && + ObjectsCompat.equals(getParentTitle(), compositePkChild.getParentTitle()) && + ObjectsCompat.equals(getCreatedAt(), compositePkChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), compositePkChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getChildId()) + .append(getContent()) + .append(getParent()) + .append(getParentTitle()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"CompositePKChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"parentTitle=\\" + String.valueOf(getParentTitle()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static ChildIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static CompositePKChild justId(String id) { + return new CompositePKChild( + id, + null, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + childId, + content, + parent, + parentTitle); + } + public interface ChildIdStep { + ContentStep childId(String childId); + } + + + public interface ContentStep { + BuildStep content(String content); + } + + + public interface BuildStep { + CompositePKChild build(); + BuildStep id(String id); + BuildStep parent(CompositePKParent parent); + BuildStep parentTitle(String parentTitle); + } + + + public static class Builder implements ChildIdStep, ContentStep, BuildStep { + private String id; + private String childId; + private String content; + private ModelReference parent; + private String parentTitle; + public Builder() { + + } + + private Builder(String id, String childId, String content, ModelReference parent, String parentTitle) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + this.parentTitle = parentTitle; + } + + @Override + public CompositePKChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new CompositePKChild( + id, + childId, + content, + parent, + parentTitle); + } + + @Override + public ContentStep childId(String childId) { + Objects.requireNonNull(childId); + this.childId = childId; + return this; + } + + @Override + public BuildStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep parent(CompositePKParent parent) { + this.parent = new LoadedModelReferenceImpl<>(parent); + return this; + } + + @Override + public BuildStep parentTitle(String parentTitle) { + this.parentTitle = parentTitle; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String childId, String content, ModelReference parent, String parentTitle) { + super(id, childId, content, parent, parentTitle); + Objects.requireNonNull(childId); + Objects.requireNonNull(content); + } + + @Override + public CopyOfBuilder childId(String childId) { + return (CopyOfBuilder) super.childId(childId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(CompositePKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + + @Override + public CopyOfBuilder parentTitle(String parentTitle) { + return (CopyOfBuilder) super.parentTitle(parentTitle); + } + } + +} + +/** This is an auto generated class representing the ImplicitChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"ImplicitChildren\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) +public final class ImplicitChild implements Model { + public static final ImplicitChildPath rootPath = new ImplicitChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"ImplicitChild\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"ImplicitChild\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"ImplicitChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"ImplicitChild\\", \\"compositePKParentImplicitChildrenId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"compositePKParentImplicitChildrenId\\", type = CompositePKParent.class) ModelReference parent; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getChildId() { + return childId; + } + + public String getContent() { + return content; + } + + public ModelReference getParent() { + return parent; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private ImplicitChild(String id, String childId, String content, ModelReference parent) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + ImplicitChild implicitChild = (ImplicitChild) obj; + return ObjectsCompat.equals(getId(), implicitChild.getId()) && + ObjectsCompat.equals(getChildId(), implicitChild.getChildId()) && + ObjectsCompat.equals(getContent(), implicitChild.getContent()) && + ObjectsCompat.equals(getParent(), implicitChild.getParent()) && + ObjectsCompat.equals(getCreatedAt(), implicitChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), implicitChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getChildId()) + .append(getContent()) + .append(getParent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"ImplicitChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static ChildIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static ImplicitChild justId(String id) { + return new ImplicitChild( + id, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + childId, + content, + parent); + } + public interface ChildIdStep { + ContentStep childId(String childId); + } + + + public interface ContentStep { + ParentStep content(String content); + } + + + public interface ParentStep { + BuildStep parent(CompositePKParent parent); + } + + + public interface BuildStep { + ImplicitChild build(); + BuildStep id(String id); + } + + + public static class Builder implements ChildIdStep, ContentStep, ParentStep, BuildStep { + private String id; + private String childId; + private String content; + private ModelReference parent; + public Builder() { + + } + + private Builder(String id, String childId, String content, ModelReference parent) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + } + + @Override + public ImplicitChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new ImplicitChild( + id, + childId, + content, + parent); + } + + @Override + public ContentStep childId(String childId) { + Objects.requireNonNull(childId); + this.childId = childId; + return this; + } + + @Override + public ParentStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep parent(CompositePKParent parent) { + Objects.requireNonNull(parent); + this.parent = new LoadedModelReferenceImpl<>(parent); + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String childId, String content, ModelReference parent) { + super(id, childId, content, parent); + Objects.requireNonNull(childId); + Objects.requireNonNull(content); + Objects.requireNonNull(parent); + } + + @Override + public CopyOfBuilder childId(String childId) { + return (CopyOfBuilder) super.childId(childId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(CompositePKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + } + +} + +/** This is an auto generated class representing the StrangeExplicitChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"StrangeExplicitChildren\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"strangeId\\",\\"content\\"}) +@Index(name = \\"byCompositePKParentX\\", fields = {\\"strangeParentId\\",\\"strangeParentTitle\\"}) +public final class StrangeExplicitChild implements Model { + public static final StrangeExplicitChildPath rootPath = new StrangeExplicitChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"StrangeExplicitChild\\", \\"id\\"); + public static final QueryField STRANGE_ID = field(\\"StrangeExplicitChild\\", \\"strangeId\\"); + public static final QueryField CONTENT = field(\\"StrangeExplicitChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"StrangeExplicitChild\\", \\"strangeParentId\\"); + public static final QueryField STRANGE_PARENT_TITLE = field(\\"StrangeExplicitChild\\", \\"strangeParentTitle\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String strangeId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"strangeParentId\\", type = CompositePKParent.class) ModelReference parent; + private final @ModelField(targetType=\\"String\\") String strangeParentTitle; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getStrangeId() { + return strangeId; + } + + public String getContent() { + return content; + } + + public ModelReference getParent() { + return parent; + } + + public String getStrangeParentTitle() { + return strangeParentTitle; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private StrangeExplicitChild(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { + this.id = id; + this.strangeId = strangeId; + this.content = content; + this.parent = parent; + this.strangeParentTitle = strangeParentTitle; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + StrangeExplicitChild strangeExplicitChild = (StrangeExplicitChild) obj; + return ObjectsCompat.equals(getId(), strangeExplicitChild.getId()) && + ObjectsCompat.equals(getStrangeId(), strangeExplicitChild.getStrangeId()) && + ObjectsCompat.equals(getContent(), strangeExplicitChild.getContent()) && + ObjectsCompat.equals(getParent(), strangeExplicitChild.getParent()) && + ObjectsCompat.equals(getStrangeParentTitle(), strangeExplicitChild.getStrangeParentTitle()) && + ObjectsCompat.equals(getCreatedAt(), strangeExplicitChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), strangeExplicitChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getStrangeId()) + .append(getContent()) + .append(getParent()) + .append(getStrangeParentTitle()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"StrangeExplicitChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"strangeId=\\" + String.valueOf(getStrangeId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"strangeParentTitle=\\" + String.valueOf(getStrangeParentTitle()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static StrangeIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static StrangeExplicitChild justId(String id) { + return new StrangeExplicitChild( + id, + null, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + strangeId, + content, + parent, + strangeParentTitle); + } + public interface StrangeIdStep { + ContentStep strangeId(String strangeId); + } + + + public interface ContentStep { + ParentStep content(String content); + } + + + public interface ParentStep { + BuildStep parent(CompositePKParent parent); + } + + + public interface BuildStep { + StrangeExplicitChild build(); + BuildStep id(String id); + BuildStep strangeParentTitle(String strangeParentTitle); + } + + + public static class Builder implements StrangeIdStep, ContentStep, ParentStep, BuildStep { + private String id; + private String strangeId; + private String content; + private ModelReference parent; + private String strangeParentTitle; + public Builder() { + + } + + private Builder(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { + this.id = id; + this.strangeId = strangeId; + this.content = content; + this.parent = parent; + this.strangeParentTitle = strangeParentTitle; + } + + @Override + public StrangeExplicitChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new StrangeExplicitChild( + id, + strangeId, + content, + parent, + strangeParentTitle); + } + + @Override + public ContentStep strangeId(String strangeId) { + Objects.requireNonNull(strangeId); + this.strangeId = strangeId; + return this; + } + + @Override + public ParentStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep parent(CompositePKParent parent) { + Objects.requireNonNull(parent); + this.parent = new LoadedModelReferenceImpl<>(parent); + return this; + } + + @Override + public BuildStep strangeParentTitle(String strangeParentTitle) { + this.strangeParentTitle = strangeParentTitle; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { + super(id, strangeId, content, parent, strangeParentTitle); + Objects.requireNonNull(strangeId); + Objects.requireNonNull(content); + Objects.requireNonNull(parent); + } + + @Override + public CopyOfBuilder strangeId(String strangeId) { + return (CopyOfBuilder) super.strangeId(strangeId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(CompositePKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + + @Override + public CopyOfBuilder strangeParentTitle(String strangeParentTitle) { + return (CopyOfBuilder) super.strangeParentTitle(strangeParentTitle); + } + } + +} + +/** This is an auto generated class representing the ChildSansBelongsTo type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"ChildSansBelongsTos\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) +@Index(name = \\"byParent\\", fields = {\\"compositePKParentChildrenSansBelongsToCustomId\\",\\"compositePKParentChildrenSansBelongsToContent\\"}) +public final class ChildSansBelongsTo implements Model { + public static final ChildSansBelongsToPath rootPath = new ChildSansBelongsToPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"ChildSansBelongsTo\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"ChildSansBelongsTo\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"ChildSansBelongsTo\\", \\"content\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CUSTOM_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToCustomId\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CONTENT = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToContent\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String compositePKParentChildrenSansBelongsToCustomId; + private final @ModelField(targetType=\\"String\\") String compositePKParentChildrenSansBelongsToContent; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + private final @ModelField(targetType=\\"ID\\") String compositePKParentChildrenSansBelongsToId; + public String getId() { + return id; + } + + public String getChildId() { + return childId; + } + + public String getContent() { + return content; + } + + public String getCompositePkParentChildrenSansBelongsToCustomId() { + return compositePKParentChildrenSansBelongsToCustomId; + } + + public String getCompositePkParentChildrenSansBelongsToContent() { + return compositePKParentChildrenSansBelongsToContent; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + public String getCompositePkParentChildrenSansBelongsToId() { + return compositePKParentChildrenSansBelongsToId; + } + + private ChildSansBelongsTo(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { + this.id = id; + this.childId = childId; + this.content = content; + this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; + this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; + this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + ChildSansBelongsTo childSansBelongsTo = (ChildSansBelongsTo) obj; + return ObjectsCompat.equals(getId(), childSansBelongsTo.getId()) && + ObjectsCompat.equals(getChildId(), childSansBelongsTo.getChildId()) && + ObjectsCompat.equals(getContent(), childSansBelongsTo.getContent()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToCustomId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToCustomId()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToContent(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToContent()) && + ObjectsCompat.equals(getCreatedAt(), childSansBelongsTo.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), childSansBelongsTo.getUpdatedAt()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToId()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getChildId()) + .append(getContent()) + .append(getCompositePkParentChildrenSansBelongsToCustomId()) + .append(getCompositePkParentChildrenSansBelongsToContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .append(getCompositePkParentChildrenSansBelongsToId()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"ChildSansBelongsTo {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToCustomId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToCustomId()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToContent=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToId())) + .append(\\"}\\") + .toString(); + } + + public static ChildIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static ChildSansBelongsTo justId(String id) { + return new ChildSansBelongsTo( + id, + null, + null, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + childId, + content, + compositePKParentChildrenSansBelongsToCustomId, + compositePKParentChildrenSansBelongsToContent, + compositePKParentChildrenSansBelongsToId); + } + public interface ChildIdStep { + ContentStep childId(String childId); + } + + + public interface ContentStep { + CompositePkParentChildrenSansBelongsToCustomIdStep content(String content); + } + + + public interface CompositePkParentChildrenSansBelongsToCustomIdStep { + BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId); + } + + + public interface BuildStep { + ChildSansBelongsTo build(); + BuildStep id(String id); + BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent); + BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId); + } + + + public static class Builder implements ChildIdStep, ContentStep, CompositePkParentChildrenSansBelongsToCustomIdStep, BuildStep { + private String id; + private String childId; + private String content; + private String compositePKParentChildrenSansBelongsToCustomId; + private String compositePKParentChildrenSansBelongsToContent; + private String compositePKParentChildrenSansBelongsToId; + public Builder() { + + } + + private Builder(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { + this.id = id; + this.childId = childId; + this.content = content; + this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; + this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; + this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; + } + + @Override + public ChildSansBelongsTo build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new ChildSansBelongsTo( + id, + childId, + content, + compositePKParentChildrenSansBelongsToCustomId, + compositePKParentChildrenSansBelongsToContent, + compositePKParentChildrenSansBelongsToId); + } + + @Override + public ContentStep childId(String childId) { + Objects.requireNonNull(childId); + this.childId = childId; + return this; + } + + @Override + public CompositePkParentChildrenSansBelongsToCustomIdStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { + Objects.requireNonNull(compositePkParentChildrenSansBelongsToCustomId); + this.compositePKParentChildrenSansBelongsToCustomId = compositePkParentChildrenSansBelongsToCustomId; + return this; + } + + @Override + public BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { + this.compositePKParentChildrenSansBelongsToContent = compositePkParentChildrenSansBelongsToContent; + return this; + } + + @Override + public BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { + this.compositePKParentChildrenSansBelongsToId = compositePkParentChildrenSansBelongsToId; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String childId, String content, String compositePkParentChildrenSansBelongsToCustomId, String compositePkParentChildrenSansBelongsToContent, String compositePkParentChildrenSansBelongsToId) { + super(id, childId, content, compositePKParentChildrenSansBelongsToCustomId, compositePKParentChildrenSansBelongsToContent, compositePKParentChildrenSansBelongsToId); + Objects.requireNonNull(childId); + Objects.requireNonNull(content); + Objects.requireNonNull(compositePKParentChildrenSansBelongsToCustomId); + } + + @Override + public CopyOfBuilder childId(String childId) { + return (CopyOfBuilder) super.childId(childId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToCustomId(compositePkParentChildrenSansBelongsToCustomId); + } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToContent(compositePkParentChildrenSansBelongsToContent); + } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToId(compositePkParentChildrenSansBelongsToId); + } + } + +} " `; diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts index 8321dddb2..de9e474db 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts @@ -131,7 +131,7 @@ describe('AppSyncModelVisitor', () => { } `; - const visitor = getVisitor(schema, 'status'); + const visitor = getVisitor(schema); const generatedCode = visitor.generate(); expect(() => validateJava(generatedCode)).not.toThrow(); expect(generatedCode).toMatchSnapshot(); From f2b8d64f7bdf13a4301f8d2269f0cf920e83b2f8 Mon Sep 17 00:00:00 2001 From: tjroach Date: Thu, 14 Sep 2023 14:10:51 -0400 Subject: [PATCH 14/30] WIP: attempt to check if datastore is enabled --- .../appsync-modelgen-plugin/src/preset.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index 040e2d15a..0f2b606ea 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -4,6 +4,8 @@ import { join } from 'path'; import { JAVA_SCALAR_MAP, SWIFT_SCALAR_MAP, TYPESCRIPT_SCALAR_MAP, DART_SCALAR_MAP, METADATA_SCALAR_MAP } from './scalars'; import { LOADER_CLASS_NAME, GENERATED_PACKAGE_NAME } from './configs/java-config'; import { graphqlName, toUpper } from 'graphql-transformer-common'; +import { pathManager } from '@aws-amplify/amplify-cli-core'; +const { isDataStoreEnabled } = require('graphql-transformer-core'); const APPSYNC_DATA_STORE_CODEGEN_TARGETS = ['java', 'swift', 'javascript', 'typescript', 'dart', 'introspection']; @@ -32,12 +34,17 @@ export type AppSyncModelCodeGenPresetConfig = { const generateJavaPreset = ( options: Types.PresetFnArgs, + isDataStoreEnabled: boolean, models: TypeDefinitionNode[], ): Types.GenerateOptions[] => { const config: Types.GenerateOptions[] = []; const modelFolder = options.config.overrideOutputDir ? [options.config.overrideOutputDir] : [options.baseOutputDir, ...GENERATED_PACKAGE_NAME.split('.')]; + + // Only generate lazy models if feature flag enabled and datastore is not being used. + const generateLazyModels = options.config.generateModelsForLazyLoadAndCustomSelectionSet && !isDataStoreEnabled + models.forEach(model => { const modelName = model.name.value; config.push({ @@ -45,6 +52,7 @@ const generateJavaPreset = ( filename: join(...modelFolder, `${modelName}.java`), config: { ...options.config, + generateModelsForLazyLoadAndCustomSelectionSet: generateLazyModels, scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, selectedType: modelName, }, @@ -61,8 +69,8 @@ const generateJavaPreset = ( }, }); - // Create ModelPath's if generateModelsForLazyLoadAndCustomSelectionSet = true - if (options.config.generateModelsForLazyLoadAndCustomSelectionSet) { + // Create ModelPath's only if lazy models are generated + if (generateLazyModels) { // Create ModelPath if type is @model if (model?.directives?.find((directive) => directive?.name?.value === 'model')) { config.push({ @@ -291,7 +299,7 @@ const generateIntrospectionPreset = ( }; export const preset: Types.OutputPreset = { - buildGeneratesSection: (options: Types.PresetFnArgs): Types.GenerateOptions[] => { + buildGeneratesSection: async (options: Types.PresetFnArgs): Promise => { const codeGenTarget = options.config.target; const typesToSkip: string[] = ['Query', 'Mutation', 'Subscription']; const models: TypeDefinitionNode[] = options.schema.definitions.filter( @@ -303,9 +311,11 @@ export const preset: Types.OutputPreset = { models.push(...generateManyToManyModelStubs(options)); } - switch (codeGenTarget) { + switch (codeGenTarget) { case 'java': - return generateJavaPreset(options, models); + const path = join(pathManager.getBackendDirPath(), 'api', ""); + let datastoreEnabled = await isDataStoreEnabled(join(pathManager.getBackendDirPath(), 'api', "wrong")); + return generateJavaPreset(options, datastoreEnabled, models); case 'swift': return generateSwiftPreset(options, models); case 'javascript': From 279d803da4ee09b0aa5d5703f68e72027f467cfb Mon Sep 17 00:00:00 2001 From: tjroach Date: Thu, 14 Sep 2023 15:43:49 -0400 Subject: [PATCH 15/30] Generate lazy if datastore is disbled --- packages/amplify-codegen/src/commands/models.js | 2 ++ packages/appsync-modelgen-plugin/src/preset.ts | 15 +++++---------- .../src/visitors/appsync-java-visitor.ts | 5 +++++ .../src/visitors/appsync-visitor.ts | 9 +++++++++ packages/graphql-generator/src/models.ts | 2 ++ packages/graphql-generator/src/typescript.ts | 2 ++ 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/packages/amplify-codegen/src/commands/models.js b/packages/amplify-codegen/src/commands/models.js index 637653461..f238bcbdf 100644 --- a/packages/amplify-codegen/src/commands/models.js +++ b/packages/amplify-codegen/src/commands/models.js @@ -7,6 +7,7 @@ const { validateAmplifyFlutterMinSupportedVersion } = require('../utils/validate const defaultDirectiveDefinitions = require('../utils/defaultDirectiveDefinitions'); const getProjectRoot = require('../utils/getProjectRoot'); const { getModelSchemaPathParam, hasModelSchemaPathParam } = require('../utils/getModelSchemaPathParam'); +const { isDataStoreEnabled } = require('graphql-transformer-core'); /** * Amplify Context type. @@ -259,6 +260,7 @@ async function generateModels(context, generateOptions = null) { const generatedCode = await generateModelsHelper({ schema: loadSchema(apiResourcePath), + isDataStoreEnabled: await isDataStoreEnabled(apiResourcePath), directives: await getDirectives(context, apiResourcePath), target: modelgenFrontendToTargetMap[frontend], generateIndexRules: readFeatureFlag(context, 'codegen.generateIndexRules'), diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index 0f2b606ea..caece11e2 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -4,8 +4,6 @@ import { join } from 'path'; import { JAVA_SCALAR_MAP, SWIFT_SCALAR_MAP, TYPESCRIPT_SCALAR_MAP, DART_SCALAR_MAP, METADATA_SCALAR_MAP } from './scalars'; import { LOADER_CLASS_NAME, GENERATED_PACKAGE_NAME } from './configs/java-config'; import { graphqlName, toUpper } from 'graphql-transformer-common'; -import { pathManager } from '@aws-amplify/amplify-cli-core'; -const { isDataStoreEnabled } = require('graphql-transformer-core'); const APPSYNC_DATA_STORE_CODEGEN_TARGETS = ['java', 'swift', 'javascript', 'typescript', 'dart', 'introspection']; @@ -30,11 +28,11 @@ export type AppSyncModelCodeGenPresetConfig = { */ overrideOutputDir: string | null; target: Target; + isDataStoreEnabled?: boolean; }; const generateJavaPreset = ( options: Types.PresetFnArgs, - isDataStoreEnabled: boolean, models: TypeDefinitionNode[], ): Types.GenerateOptions[] => { const config: Types.GenerateOptions[] = []; @@ -43,8 +41,8 @@ const generateJavaPreset = ( : [options.baseOutputDir, ...GENERATED_PACKAGE_NAME.split('.')]; // Only generate lazy models if feature flag enabled and datastore is not being used. - const generateLazyModels = options.config.generateModelsForLazyLoadAndCustomSelectionSet && !isDataStoreEnabled - + const generateLazyModels = options.config.generateModelsForLazyLoadAndCustomSelectionSet && !options.config.isDataStoreEnabled + models.forEach(model => { const modelName = model.name.value; config.push({ @@ -52,7 +50,6 @@ const generateJavaPreset = ( filename: join(...modelFolder, `${modelName}.java`), config: { ...options.config, - generateModelsForLazyLoadAndCustomSelectionSet: generateLazyModels, scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, selectedType: modelName, }, @@ -299,7 +296,7 @@ const generateIntrospectionPreset = ( }; export const preset: Types.OutputPreset = { - buildGeneratesSection: async (options: Types.PresetFnArgs): Promise => { + buildGeneratesSection: (options: Types.PresetFnArgs): Types.GenerateOptions[] => { const codeGenTarget = options.config.target; const typesToSkip: string[] = ['Query', 'Mutation', 'Subscription']; const models: TypeDefinitionNode[] = options.schema.definitions.filter( @@ -313,9 +310,7 @@ export const preset: Types.OutputPreset = { switch (codeGenTarget) { case 'java': - const path = join(pathManager.getBackendDirPath(), 'api', ""); - let datastoreEnabled = await isDataStoreEnabled(join(pathManager.getBackendDirPath(), 'api', "wrong")); - return generateJavaPreset(options, datastoreEnabled, models); + return generateJavaPreset(options, models); case 'swift': return generateSwiftPreset(options, models); case 'javascript': diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index e2456a03b..68fc07302 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -36,6 +36,11 @@ export class AppSyncModelJavaVisitor< protected additionalPackages: Set = new Set(); protected usingAuth: boolean = false; + // We override lazy generation to also only generate lazy models if data store is disabled + protected override isGenerateModelsForLazyLoadAndCustomSelectionSet(): boolean { + return super.isGenerateModelsForLazyLoadAndCustomSelectionSet() && !(this.config.isDataStoreEnabled ?? false); + } + generate(): string { // TODO: Remove us, leaving in to be explicit on why this flag is here. const shouldUseModelNameFieldInHasManyAndBelongsTo = true; diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts index c0e0aa0da..8d77a8ef8 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts @@ -150,6 +150,13 @@ export interface RawAppSyncModelConfig extends RawConfig { * @description semantic version of amplify-codegen package */ codegenVersion: string; + + /** + * @name isDataStoreEnabled + * @type boolean + * @description true if DataStore is enabled on project + */ + isDataStoreEnabled?: boolean; } // Todo: need to figure out how to share config @@ -165,6 +172,7 @@ export interface ParsedAppSyncModelConfig extends ParsedConfig { improvePluralization?: boolean; generateModelsForLazyLoadAndCustomSelectionSet?: boolean; codegenVersion?: string; + isDataStoreEnabled?: string; } export type CodeGenArgumentsMap = Record; @@ -256,6 +264,7 @@ export class AppSyncModelVisitor< improvePluralization: rawConfig.improvePluralization, generateModelsForLazyLoadAndCustomSelectionSet: rawConfig.generateModelsForLazyLoadAndCustomSelectionSet, codegenVersion: rawConfig.codegenVersion, + isDataStoreEnabled: rawConfig.isDataStoreEnabled }); const typesUsedInDirectives: string[] = []; diff --git a/packages/graphql-generator/src/models.ts b/packages/graphql-generator/src/models.ts index 3dfb490ed..fdeb89c16 100644 --- a/packages/graphql-generator/src/models.ts +++ b/packages/graphql-generator/src/models.ts @@ -9,6 +9,7 @@ export async function generateModels(options: GenerateModelsOptions): Promise Date: Mon, 18 Sep 2023 10:43:37 -0400 Subject: [PATCH 16/30] Fix indentation --- .../src/visitors/appsync-java-visitor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index 68fc07302..68237fcf2 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -540,8 +540,8 @@ export class AppSyncModelJavaVisitor< const argumentType = this.getNativeType(field, true); const argumentName = this.getStepFunctionArgumentName(field); const assignment = this.isModelReference(field) ? - `this.${fieldName} = new LoadedModelReferenceImpl<>(${argumentName});` : - `this.${fieldName} = ${argumentName};` + `this.${fieldName} = new LoadedModelReferenceImpl<>(${argumentName});` : + `this.${fieldName} = ${argumentName};` const body = [`${assignment}`, `return this;`].join('\n'); builderClassDeclaration.addClassMethod( methodName, From e69515beeb5af9d9d69e56bfabdcb5ff8d674bb0 Mon Sep 17 00:00:00 2001 From: tjroach Date: Mon, 18 Sep 2023 13:53:27 -0400 Subject: [PATCH 17/30] PR Comments --- .../amplify-codegen/src/commands/models.js | 2 +- .../src/visitors/appsync-visitor.ts | 19 ++++++++++--------- packages/graphql-generator/src/models.ts | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/amplify-codegen/src/commands/models.js b/packages/amplify-codegen/src/commands/models.js index f238bcbdf..0b1a60266 100644 --- a/packages/amplify-codegen/src/commands/models.js +++ b/packages/amplify-codegen/src/commands/models.js @@ -260,8 +260,8 @@ async function generateModels(context, generateOptions = null) { const generatedCode = await generateModelsHelper({ schema: loadSchema(apiResourcePath), - isDataStoreEnabled: await isDataStoreEnabled(apiResourcePath), directives: await getDirectives(context, apiResourcePath), + isDataStoreEnabled: await isDataStoreEnabled(apiResourcePath), target: modelgenFrontendToTargetMap[frontend], generateIndexRules: readFeatureFlag(context, 'codegen.generateIndexRules'), emitAuthProvider: readFeatureFlag(context, 'codegen.emitAuthProvider'), diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts index 8d77a8ef8..674519e1d 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts @@ -102,6 +102,14 @@ export interface RawAppSyncModelConfig extends RawConfig { * @descriptions optional string which includes directive definition and types used by directives. The types defined in here won't make it to output */ directives?: string; + + /** + * @name isDataStoreEnabled + * @type boolean + * @description true if DataStore is enabled on project + */ + isDataStoreEnabled?: boolean; + /** * @name isTimestampFieldsAdded * @type boolean @@ -150,13 +158,6 @@ export interface RawAppSyncModelConfig extends RawConfig { * @description semantic version of amplify-codegen package */ codegenVersion: string; - - /** - * @name isDataStoreEnabled - * @type boolean - * @description true if DataStore is enabled on project - */ - isDataStoreEnabled?: boolean; } // Todo: need to figure out how to share config @@ -164,6 +165,7 @@ export interface ParsedAppSyncModelConfig extends ParsedConfig { selectedType?: string; generate?: CodeGenGenerateEnum; target?: string; + isDataStoreEnabled?: string; isTimestampFieldsAdded?: boolean; handleListNullabilityTransparently?: boolean; usePipelinedTransformer?: boolean; @@ -172,7 +174,6 @@ export interface ParsedAppSyncModelConfig extends ParsedConfig { improvePluralization?: boolean; generateModelsForLazyLoadAndCustomSelectionSet?: boolean; codegenVersion?: string; - isDataStoreEnabled?: string; } export type CodeGenArgumentsMap = Record; @@ -256,6 +257,7 @@ export class AppSyncModelVisitor< ...additionalConfig, scalars: buildScalars(_schema, rawConfig.scalars || '', defaultScalars), target: rawConfig.target, + isDataStoreEnabled: rawConfig.isDataStoreEnabled, isTimestampFieldsAdded: rawConfig.isTimestampFieldsAdded, handleListNullabilityTransparently: rawConfig.handleListNullabilityTransparently, usePipelinedTransformer: rawConfig.usePipelinedTransformer, @@ -264,7 +266,6 @@ export class AppSyncModelVisitor< improvePluralization: rawConfig.improvePluralization, generateModelsForLazyLoadAndCustomSelectionSet: rawConfig.generateModelsForLazyLoadAndCustomSelectionSet, codegenVersion: rawConfig.codegenVersion, - isDataStoreEnabled: rawConfig.isDataStoreEnabled }); const typesUsedInDirectives: string[] = []; diff --git a/packages/graphql-generator/src/models.ts b/packages/graphql-generator/src/models.ts index fdeb89c16..845fd240c 100644 --- a/packages/graphql-generator/src/models.ts +++ b/packages/graphql-generator/src/models.ts @@ -31,6 +31,7 @@ export async function generateModels(options: GenerateModelsOptions): Promise Date: Mon, 18 Sep 2023 15:06:09 -0400 Subject: [PATCH 18/30] add isDataStoreEnabled true tests --- ...java-api-lazyload-css-visitor.test.ts.snap | 3857 +++++++++++++++++ ...sync-java-api-lazyload-css-visitor.test.ts | 191 +- 2 files changed, 3960 insertions(+), 88 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap index 4a0b5f791..08d0c9fa1 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap @@ -1,5 +1,3862 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`AppSyncModelVisitor API only Should generate for DefaultPKParent DefaultPKChild models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.ModelList; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the DefaultPKParent type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"DefaultPKParents\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class DefaultPKParent implements Model { + public static final DefaultPKParentPath rootPath = new DefaultPKParentPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"DefaultPKParent\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"DefaultPKParent\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"DefaultPKChild\\") @HasMany(associatedWith = \\"parent\\", type = DefaultPKChild.class) ModelList children = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public ModelList getChildren() { + return children; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private DefaultPKParent(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + DefaultPKParent defaultPkParent = (DefaultPKParent) obj; + return ObjectsCompat.equals(getId(), defaultPkParent.getId()) && + ObjectsCompat.equals(getContent(), defaultPkParent.getContent()) && + ObjectsCompat.equals(getCreatedAt(), defaultPkParent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), defaultPkParent.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"DefaultPKParent {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static DefaultPKParent justId(String id) { + return new DefaultPKParent( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content); + } + public interface BuildStep { + DefaultPKParent build(); + BuildStep id(String id); + BuildStep content(String content); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + public Builder() { + + } + + private Builder(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public DefaultPKParent build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new DefaultPKParent( + id, + content); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content) { + super(id, content); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + +} + +/** This is an auto generated class representing the DefaultPKChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"DefaultPKChildren\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class DefaultPKChild implements Model { + public static final DefaultPKChildPath rootPath = new DefaultPKChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"DefaultPKChild\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"DefaultPKChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"DefaultPKChild\\", \\"defaultPKParentChildrenId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"DefaultPKParent\\") @BelongsTo(targetName = \\"defaultPKParentChildrenId\\", type = DefaultPKParent.class) ModelReference parent; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public ModelReference getParent() { + return parent; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private DefaultPKChild(String id, String content, ModelReference parent) { + this.id = id; + this.content = content; + this.parent = parent; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + DefaultPKChild defaultPkChild = (DefaultPKChild) obj; + return ObjectsCompat.equals(getId(), defaultPkChild.getId()) && + ObjectsCompat.equals(getContent(), defaultPkChild.getContent()) && + ObjectsCompat.equals(getParent(), defaultPkChild.getParent()) && + ObjectsCompat.equals(getCreatedAt(), defaultPkChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), defaultPkChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getParent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"DefaultPKChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static DefaultPKChild justId(String id) { + return new DefaultPKChild( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content, + parent); + } + public interface BuildStep { + DefaultPKChild build(); + BuildStep id(String id); + BuildStep content(String content); + BuildStep parent(DefaultPKParent parent); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + private ModelReference parent; + public Builder() { + + } + + private Builder(String id, String content, ModelReference parent) { + this.id = id; + this.content = content; + this.parent = parent; + } + + @Override + public DefaultPKChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new DefaultPKChild( + id, + content, + parent); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + @Override + public BuildStep parent(DefaultPKParent parent) { + this.parent = new LoadedModelReferenceImpl<>(parent); + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content, ModelReference parent) { + super(id, content, parent); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(DefaultPKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor API only Should generate for HasOneParent HasOneChild models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasOne; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; +import com.amplifyframework.core.model.temporal.Temporal; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the HasOneParent type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"HasOneParents\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class HasOneParent implements Model { + public static final HasOneParentPath rootPath = new HasOneParentPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"HasOneParent\\", \\"id\\"); + public static final QueryField HAS_ONE_PARENT_CHILD_ID = field(\\"HasOneParent\\", \\"hasOneParentChildId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"HasOneChild\\") @HasOne(associatedWith = \\"id\\", type = HasOneChild.class) ModelReference child = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + private final @ModelField(targetType=\\"ID\\") String hasOneParentChildId; + public String getId() { + return id; + } + + public ModelReference getChild() { + return child; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + public String getHasOneParentChildId() { + return hasOneParentChildId; + } + + private HasOneParent(String id, String hasOneParentChildId) { + this.id = id; + this.hasOneParentChildId = hasOneParentChildId; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + HasOneParent hasOneParent = (HasOneParent) obj; + return ObjectsCompat.equals(getId(), hasOneParent.getId()) && + ObjectsCompat.equals(getCreatedAt(), hasOneParent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), hasOneParent.getUpdatedAt()) && + ObjectsCompat.equals(getHasOneParentChildId(), hasOneParent.getHasOneParentChildId()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .append(getHasOneParentChildId()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"HasOneParent {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") + .append(\\"hasOneParentChildId=\\" + String.valueOf(getHasOneParentChildId())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static HasOneParent justId(String id) { + return new HasOneParent( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + hasOneParentChildId); + } + public interface BuildStep { + HasOneParent build(); + BuildStep id(String id); + BuildStep hasOneParentChildId(String hasOneParentChildId); + } + + + public static class Builder implements BuildStep { + private String id; + private String hasOneParentChildId; + public Builder() { + + } + + private Builder(String id, String hasOneParentChildId) { + this.id = id; + this.hasOneParentChildId = hasOneParentChildId; + } + + @Override + public HasOneParent build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new HasOneParent( + id, + hasOneParentChildId); + } + + @Override + public BuildStep hasOneParentChildId(String hasOneParentChildId) { + this.hasOneParentChildId = hasOneParentChildId; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String hasOneParentChildId) { + super(id, hasOneParentChildId); + + } + + @Override + public CopyOfBuilder hasOneParentChildId(String hasOneParentChildId) { + return (CopyOfBuilder) super.hasOneParentChildId(hasOneParentChildId); + } + } + +} + +/** This is an auto generated class representing the HasOneChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"HasOneChildren\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class HasOneChild implements Model { + public static final HasOneChildPath rootPath = new HasOneChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"HasOneChild\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"HasOneChild\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private HasOneChild(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + HasOneChild hasOneChild = (HasOneChild) obj; + return ObjectsCompat.equals(getId(), hasOneChild.getId()) && + ObjectsCompat.equals(getContent(), hasOneChild.getContent()) && + ObjectsCompat.equals(getCreatedAt(), hasOneChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), hasOneChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"HasOneChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static HasOneChild justId(String id) { + return new HasOneChild( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content); + } + public interface BuildStep { + HasOneChild build(); + BuildStep id(String id); + BuildStep content(String content); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + public Builder() { + + } + + private Builder(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public HasOneChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new HasOneChild( + id, + content); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content) { + super(id, content); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor API only should generate for CompositePKParent and (CompositePK, Implicit, StrangeExplicit, ChildSansBelongsTo) Child models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.ModelList; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the CompositePKParent type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"CompositePKParents\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"customId\\",\\"content\\"}) +public final class CompositePKParent implements Model { + public static final CompositePKParentPath rootPath = new CompositePKParentPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"CompositePKParent\\", \\"id\\"); + public static final QueryField CUSTOM_ID = field(\\"CompositePKParent\\", \\"customId\\"); + public static final QueryField CONTENT = field(\\"CompositePKParent\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String customId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKChild\\") @HasMany(associatedWith = \\"parent\\", type = CompositePKChild.class) ModelList children = null; + private final @ModelField(targetType=\\"ImplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = ImplicitChild.class) ModelList implicitChildren = null; + private final @ModelField(targetType=\\"StrangeExplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = StrangeExplicitChild.class) ModelList strangeChildren = null; + private final @ModelField(targetType=\\"ChildSansBelongsTo\\") @HasMany(associatedWith = \\"compositePKParentChildrenSansBelongsToId\\", type = ChildSansBelongsTo.class) ModelList childrenSansBelongsTo = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getCustomId() { + return customId; + } + + public String getContent() { + return content; + } + + public ModelList getChildren() { + return children; + } + + public ModelList getImplicitChildren() { + return implicitChildren; + } + + public ModelList getStrangeChildren() { + return strangeChildren; + } + + public ModelList getChildrenSansBelongsTo() { + return childrenSansBelongsTo; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private CompositePKParent(String id, String customId, String content) { + this.id = id; + this.customId = customId; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + CompositePKParent compositePkParent = (CompositePKParent) obj; + return ObjectsCompat.equals(getId(), compositePkParent.getId()) && + ObjectsCompat.equals(getCustomId(), compositePkParent.getCustomId()) && + ObjectsCompat.equals(getContent(), compositePkParent.getContent()) && + ObjectsCompat.equals(getCreatedAt(), compositePkParent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), compositePkParent.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getCustomId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"CompositePKParent {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"customId=\\" + String.valueOf(getCustomId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static CustomIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static CompositePKParent justId(String id) { + return new CompositePKParent( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + customId, + content); + } + public interface CustomIdStep { + ContentStep customId(String customId); + } + + + public interface ContentStep { + BuildStep content(String content); + } + + + public interface BuildStep { + CompositePKParent build(); + BuildStep id(String id); + } + + + public static class Builder implements CustomIdStep, ContentStep, BuildStep { + private String id; + private String customId; + private String content; + public Builder() { + + } + + private Builder(String id, String customId, String content) { + this.id = id; + this.customId = customId; + this.content = content; + } + + @Override + public CompositePKParent build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new CompositePKParent( + id, + customId, + content); + } + + @Override + public ContentStep customId(String customId) { + Objects.requireNonNull(customId); + this.customId = customId; + return this; + } + + @Override + public BuildStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String customId, String content) { + super(id, customId, content); + Objects.requireNonNull(customId); + Objects.requireNonNull(content); + } + + @Override + public CopyOfBuilder customId(String customId) { + return (CopyOfBuilder) super.customId(customId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + +} + +/** This is an auto generated class representing the CompositePKChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"CompositePKChildren\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) +@Index(name = \\"byParent\\", fields = {\\"parentId\\",\\"parentTitle\\"}) +public final class CompositePKChild implements Model { + public static final CompositePKChildPath rootPath = new CompositePKChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"CompositePKChild\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"CompositePKChild\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"CompositePKChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"CompositePKChild\\", \\"parentId\\"); + public static final QueryField PARENT_TITLE = field(\\"CompositePKChild\\", \\"parentTitle\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKParent\\") @BelongsTo(targetName = \\"parentId\\", type = CompositePKParent.class) ModelReference parent; + private final @ModelField(targetType=\\"String\\") String parentTitle; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getChildId() { + return childId; + } + + public String getContent() { + return content; + } + + public ModelReference getParent() { + return parent; + } + + public String getParentTitle() { + return parentTitle; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private CompositePKChild(String id, String childId, String content, ModelReference parent, String parentTitle) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + this.parentTitle = parentTitle; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + CompositePKChild compositePkChild = (CompositePKChild) obj; + return ObjectsCompat.equals(getId(), compositePkChild.getId()) && + ObjectsCompat.equals(getChildId(), compositePkChild.getChildId()) && + ObjectsCompat.equals(getContent(), compositePkChild.getContent()) && + ObjectsCompat.equals(getParent(), compositePkChild.getParent()) && + ObjectsCompat.equals(getParentTitle(), compositePkChild.getParentTitle()) && + ObjectsCompat.equals(getCreatedAt(), compositePkChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), compositePkChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getChildId()) + .append(getContent()) + .append(getParent()) + .append(getParentTitle()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"CompositePKChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"parentTitle=\\" + String.valueOf(getParentTitle()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static ChildIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static CompositePKChild justId(String id) { + return new CompositePKChild( + id, + null, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + childId, + content, + parent, + parentTitle); + } + public interface ChildIdStep { + ContentStep childId(String childId); + } + + + public interface ContentStep { + BuildStep content(String content); + } + + + public interface BuildStep { + CompositePKChild build(); + BuildStep id(String id); + BuildStep parent(CompositePKParent parent); + BuildStep parentTitle(String parentTitle); + } + + + public static class Builder implements ChildIdStep, ContentStep, BuildStep { + private String id; + private String childId; + private String content; + private ModelReference parent; + private String parentTitle; + public Builder() { + + } + + private Builder(String id, String childId, String content, ModelReference parent, String parentTitle) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + this.parentTitle = parentTitle; + } + + @Override + public CompositePKChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new CompositePKChild( + id, + childId, + content, + parent, + parentTitle); + } + + @Override + public ContentStep childId(String childId) { + Objects.requireNonNull(childId); + this.childId = childId; + return this; + } + + @Override + public BuildStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep parent(CompositePKParent parent) { + this.parent = new LoadedModelReferenceImpl<>(parent); + return this; + } + + @Override + public BuildStep parentTitle(String parentTitle) { + this.parentTitle = parentTitle; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String childId, String content, ModelReference parent, String parentTitle) { + super(id, childId, content, parent, parentTitle); + Objects.requireNonNull(childId); + Objects.requireNonNull(content); + } + + @Override + public CopyOfBuilder childId(String childId) { + return (CopyOfBuilder) super.childId(childId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(CompositePKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + + @Override + public CopyOfBuilder parentTitle(String parentTitle) { + return (CopyOfBuilder) super.parentTitle(parentTitle); + } + } + +} + +/** This is an auto generated class representing the ImplicitChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"ImplicitChildren\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) +public final class ImplicitChild implements Model { + public static final ImplicitChildPath rootPath = new ImplicitChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"ImplicitChild\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"ImplicitChild\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"ImplicitChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"ImplicitChild\\", \\"compositePKParentImplicitChildrenId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"compositePKParentImplicitChildrenId\\", type = CompositePKParent.class) ModelReference parent; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getChildId() { + return childId; + } + + public String getContent() { + return content; + } + + public ModelReference getParent() { + return parent; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private ImplicitChild(String id, String childId, String content, ModelReference parent) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + ImplicitChild implicitChild = (ImplicitChild) obj; + return ObjectsCompat.equals(getId(), implicitChild.getId()) && + ObjectsCompat.equals(getChildId(), implicitChild.getChildId()) && + ObjectsCompat.equals(getContent(), implicitChild.getContent()) && + ObjectsCompat.equals(getParent(), implicitChild.getParent()) && + ObjectsCompat.equals(getCreatedAt(), implicitChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), implicitChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getChildId()) + .append(getContent()) + .append(getParent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"ImplicitChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static ChildIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static ImplicitChild justId(String id) { + return new ImplicitChild( + id, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + childId, + content, + parent); + } + public interface ChildIdStep { + ContentStep childId(String childId); + } + + + public interface ContentStep { + ParentStep content(String content); + } + + + public interface ParentStep { + BuildStep parent(CompositePKParent parent); + } + + + public interface BuildStep { + ImplicitChild build(); + BuildStep id(String id); + } + + + public static class Builder implements ChildIdStep, ContentStep, ParentStep, BuildStep { + private String id; + private String childId; + private String content; + private ModelReference parent; + public Builder() { + + } + + private Builder(String id, String childId, String content, ModelReference parent) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + } + + @Override + public ImplicitChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new ImplicitChild( + id, + childId, + content, + parent); + } + + @Override + public ContentStep childId(String childId) { + Objects.requireNonNull(childId); + this.childId = childId; + return this; + } + + @Override + public ParentStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep parent(CompositePKParent parent) { + Objects.requireNonNull(parent); + this.parent = new LoadedModelReferenceImpl<>(parent); + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String childId, String content, ModelReference parent) { + super(id, childId, content, parent); + Objects.requireNonNull(childId); + Objects.requireNonNull(content); + Objects.requireNonNull(parent); + } + + @Override + public CopyOfBuilder childId(String childId) { + return (CopyOfBuilder) super.childId(childId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(CompositePKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + } + +} + +/** This is an auto generated class representing the StrangeExplicitChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"StrangeExplicitChildren\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"strangeId\\",\\"content\\"}) +@Index(name = \\"byCompositePKParentX\\", fields = {\\"strangeParentId\\",\\"strangeParentTitle\\"}) +public final class StrangeExplicitChild implements Model { + public static final StrangeExplicitChildPath rootPath = new StrangeExplicitChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"StrangeExplicitChild\\", \\"id\\"); + public static final QueryField STRANGE_ID = field(\\"StrangeExplicitChild\\", \\"strangeId\\"); + public static final QueryField CONTENT = field(\\"StrangeExplicitChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"StrangeExplicitChild\\", \\"strangeParentId\\"); + public static final QueryField STRANGE_PARENT_TITLE = field(\\"StrangeExplicitChild\\", \\"strangeParentTitle\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String strangeId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"strangeParentId\\", type = CompositePKParent.class) ModelReference parent; + private final @ModelField(targetType=\\"String\\") String strangeParentTitle; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getStrangeId() { + return strangeId; + } + + public String getContent() { + return content; + } + + public ModelReference getParent() { + return parent; + } + + public String getStrangeParentTitle() { + return strangeParentTitle; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private StrangeExplicitChild(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { + this.id = id; + this.strangeId = strangeId; + this.content = content; + this.parent = parent; + this.strangeParentTitle = strangeParentTitle; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + StrangeExplicitChild strangeExplicitChild = (StrangeExplicitChild) obj; + return ObjectsCompat.equals(getId(), strangeExplicitChild.getId()) && + ObjectsCompat.equals(getStrangeId(), strangeExplicitChild.getStrangeId()) && + ObjectsCompat.equals(getContent(), strangeExplicitChild.getContent()) && + ObjectsCompat.equals(getParent(), strangeExplicitChild.getParent()) && + ObjectsCompat.equals(getStrangeParentTitle(), strangeExplicitChild.getStrangeParentTitle()) && + ObjectsCompat.equals(getCreatedAt(), strangeExplicitChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), strangeExplicitChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getStrangeId()) + .append(getContent()) + .append(getParent()) + .append(getStrangeParentTitle()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"StrangeExplicitChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"strangeId=\\" + String.valueOf(getStrangeId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"strangeParentTitle=\\" + String.valueOf(getStrangeParentTitle()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static StrangeIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static StrangeExplicitChild justId(String id) { + return new StrangeExplicitChild( + id, + null, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + strangeId, + content, + parent, + strangeParentTitle); + } + public interface StrangeIdStep { + ContentStep strangeId(String strangeId); + } + + + public interface ContentStep { + ParentStep content(String content); + } + + + public interface ParentStep { + BuildStep parent(CompositePKParent parent); + } + + + public interface BuildStep { + StrangeExplicitChild build(); + BuildStep id(String id); + BuildStep strangeParentTitle(String strangeParentTitle); + } + + + public static class Builder implements StrangeIdStep, ContentStep, ParentStep, BuildStep { + private String id; + private String strangeId; + private String content; + private ModelReference parent; + private String strangeParentTitle; + public Builder() { + + } + + private Builder(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { + this.id = id; + this.strangeId = strangeId; + this.content = content; + this.parent = parent; + this.strangeParentTitle = strangeParentTitle; + } + + @Override + public StrangeExplicitChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new StrangeExplicitChild( + id, + strangeId, + content, + parent, + strangeParentTitle); + } + + @Override + public ContentStep strangeId(String strangeId) { + Objects.requireNonNull(strangeId); + this.strangeId = strangeId; + return this; + } + + @Override + public ParentStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep parent(CompositePKParent parent) { + Objects.requireNonNull(parent); + this.parent = new LoadedModelReferenceImpl<>(parent); + return this; + } + + @Override + public BuildStep strangeParentTitle(String strangeParentTitle) { + this.strangeParentTitle = strangeParentTitle; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { + super(id, strangeId, content, parent, strangeParentTitle); + Objects.requireNonNull(strangeId); + Objects.requireNonNull(content); + Objects.requireNonNull(parent); + } + + @Override + public CopyOfBuilder strangeId(String strangeId) { + return (CopyOfBuilder) super.strangeId(strangeId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(CompositePKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + + @Override + public CopyOfBuilder strangeParentTitle(String strangeParentTitle) { + return (CopyOfBuilder) super.strangeParentTitle(strangeParentTitle); + } + } + +} + +/** This is an auto generated class representing the ChildSansBelongsTo type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"ChildSansBelongsTos\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) +@Index(name = \\"byParent\\", fields = {\\"compositePKParentChildrenSansBelongsToCustomId\\",\\"compositePKParentChildrenSansBelongsToContent\\"}) +public final class ChildSansBelongsTo implements Model { + public static final ChildSansBelongsToPath rootPath = new ChildSansBelongsToPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"ChildSansBelongsTo\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"ChildSansBelongsTo\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"ChildSansBelongsTo\\", \\"content\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CUSTOM_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToCustomId\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CONTENT = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToContent\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String compositePKParentChildrenSansBelongsToCustomId; + private final @ModelField(targetType=\\"String\\") String compositePKParentChildrenSansBelongsToContent; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + private final @ModelField(targetType=\\"ID\\") String compositePKParentChildrenSansBelongsToId; + public String getId() { + return id; + } + + public String getChildId() { + return childId; + } + + public String getContent() { + return content; + } + + public String getCompositePkParentChildrenSansBelongsToCustomId() { + return compositePKParentChildrenSansBelongsToCustomId; + } + + public String getCompositePkParentChildrenSansBelongsToContent() { + return compositePKParentChildrenSansBelongsToContent; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + public String getCompositePkParentChildrenSansBelongsToId() { + return compositePKParentChildrenSansBelongsToId; + } + + private ChildSansBelongsTo(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { + this.id = id; + this.childId = childId; + this.content = content; + this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; + this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; + this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + ChildSansBelongsTo childSansBelongsTo = (ChildSansBelongsTo) obj; + return ObjectsCompat.equals(getId(), childSansBelongsTo.getId()) && + ObjectsCompat.equals(getChildId(), childSansBelongsTo.getChildId()) && + ObjectsCompat.equals(getContent(), childSansBelongsTo.getContent()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToCustomId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToCustomId()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToContent(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToContent()) && + ObjectsCompat.equals(getCreatedAt(), childSansBelongsTo.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), childSansBelongsTo.getUpdatedAt()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToId()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getChildId()) + .append(getContent()) + .append(getCompositePkParentChildrenSansBelongsToCustomId()) + .append(getCompositePkParentChildrenSansBelongsToContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .append(getCompositePkParentChildrenSansBelongsToId()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"ChildSansBelongsTo {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToCustomId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToCustomId()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToContent=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToId())) + .append(\\"}\\") + .toString(); + } + + public static ChildIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static ChildSansBelongsTo justId(String id) { + return new ChildSansBelongsTo( + id, + null, + null, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + childId, + content, + compositePKParentChildrenSansBelongsToCustomId, + compositePKParentChildrenSansBelongsToContent, + compositePKParentChildrenSansBelongsToId); + } + public interface ChildIdStep { + ContentStep childId(String childId); + } + + + public interface ContentStep { + CompositePkParentChildrenSansBelongsToCustomIdStep content(String content); + } + + + public interface CompositePkParentChildrenSansBelongsToCustomIdStep { + BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId); + } + + + public interface BuildStep { + ChildSansBelongsTo build(); + BuildStep id(String id); + BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent); + BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId); + } + + + public static class Builder implements ChildIdStep, ContentStep, CompositePkParentChildrenSansBelongsToCustomIdStep, BuildStep { + private String id; + private String childId; + private String content; + private String compositePKParentChildrenSansBelongsToCustomId; + private String compositePKParentChildrenSansBelongsToContent; + private String compositePKParentChildrenSansBelongsToId; + public Builder() { + + } + + private Builder(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { + this.id = id; + this.childId = childId; + this.content = content; + this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; + this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; + this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; + } + + @Override + public ChildSansBelongsTo build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new ChildSansBelongsTo( + id, + childId, + content, + compositePKParentChildrenSansBelongsToCustomId, + compositePKParentChildrenSansBelongsToContent, + compositePKParentChildrenSansBelongsToId); + } + + @Override + public ContentStep childId(String childId) { + Objects.requireNonNull(childId); + this.childId = childId; + return this; + } + + @Override + public CompositePkParentChildrenSansBelongsToCustomIdStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { + Objects.requireNonNull(compositePkParentChildrenSansBelongsToCustomId); + this.compositePKParentChildrenSansBelongsToCustomId = compositePkParentChildrenSansBelongsToCustomId; + return this; + } + + @Override + public BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { + this.compositePKParentChildrenSansBelongsToContent = compositePkParentChildrenSansBelongsToContent; + return this; + } + + @Override + public BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { + this.compositePKParentChildrenSansBelongsToId = compositePkParentChildrenSansBelongsToId; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String childId, String content, String compositePkParentChildrenSansBelongsToCustomId, String compositePkParentChildrenSansBelongsToContent, String compositePkParentChildrenSansBelongsToId) { + super(id, childId, content, compositePKParentChildrenSansBelongsToCustomId, compositePKParentChildrenSansBelongsToContent, compositePKParentChildrenSansBelongsToId); + Objects.requireNonNull(childId); + Objects.requireNonNull(content); + Objects.requireNonNull(compositePKParentChildrenSansBelongsToCustomId); + } + + @Override + public CopyOfBuilder childId(String childId) { + return (CopyOfBuilder) super.childId(childId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToCustomId(compositePkParentChildrenSansBelongsToCustomId); + } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToContent(compositePkParentChildrenSansBelongsToContent); + } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToId(compositePkParentChildrenSansBelongsToId); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor DataStore Enabled Should generate for DefaultPKParent DefaultPKChild models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.annotations.BelongsTo; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the DefaultPKParent type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"DefaultPKParents\\") +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class DefaultPKParent implements Model { + public static final QueryField ID = field(\\"DefaultPKParent\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"DefaultPKParent\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"DefaultPKChild\\") @HasMany(associatedWith = \\"parent\\", type = DefaultPKChild.class) List children = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public List getChildren() { + return children; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private DefaultPKParent(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + DefaultPKParent defaultPkParent = (DefaultPKParent) obj; + return ObjectsCompat.equals(getId(), defaultPkParent.getId()) && + ObjectsCompat.equals(getContent(), defaultPkParent.getContent()) && + ObjectsCompat.equals(getCreatedAt(), defaultPkParent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), defaultPkParent.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"DefaultPKParent {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static DefaultPKParent justId(String id) { + return new DefaultPKParent( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content); + } + public interface BuildStep { + DefaultPKParent build(); + BuildStep id(String id); + BuildStep content(String content); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + public Builder() { + + } + + private Builder(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public DefaultPKParent build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new DefaultPKParent( + id, + content); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content) { + super(id, content); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + +} + +/** This is an auto generated class representing the DefaultPKChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"DefaultPKChildren\\") +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class DefaultPKChild implements Model { + public static final QueryField ID = field(\\"DefaultPKChild\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"DefaultPKChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"DefaultPKChild\\", \\"defaultPKParentChildrenId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"DefaultPKParent\\") @BelongsTo(targetName = \\"defaultPKParentChildrenId\\", type = DefaultPKParent.class) DefaultPKParent parent; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public DefaultPKParent getParent() { + return parent; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private DefaultPKChild(String id, String content, DefaultPKParent parent) { + this.id = id; + this.content = content; + this.parent = parent; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + DefaultPKChild defaultPkChild = (DefaultPKChild) obj; + return ObjectsCompat.equals(getId(), defaultPkChild.getId()) && + ObjectsCompat.equals(getContent(), defaultPkChild.getContent()) && + ObjectsCompat.equals(getParent(), defaultPkChild.getParent()) && + ObjectsCompat.equals(getCreatedAt(), defaultPkChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), defaultPkChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getParent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"DefaultPKChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static DefaultPKChild justId(String id) { + return new DefaultPKChild( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content, + parent); + } + public interface BuildStep { + DefaultPKChild build(); + BuildStep id(String id); + BuildStep content(String content); + BuildStep parent(DefaultPKParent parent); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + private DefaultPKParent parent; + public Builder() { + + } + + private Builder(String id, String content, DefaultPKParent parent) { + this.id = id; + this.content = content; + this.parent = parent; + } + + @Override + public DefaultPKChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new DefaultPKChild( + id, + content, + parent); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + @Override + public BuildStep parent(DefaultPKParent parent) { + this.parent = parent; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content, DefaultPKParent parent) { + super(id, content, parent); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(DefaultPKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor DataStore Enabled Should generate for HasOneParent HasOneChild models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasOne; +import com.amplifyframework.core.model.temporal.Temporal; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the HasOneParent type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"HasOneParents\\") +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class HasOneParent implements Model { + public static final QueryField ID = field(\\"HasOneParent\\", \\"id\\"); + public static final QueryField HAS_ONE_PARENT_CHILD_ID = field(\\"HasOneParent\\", \\"hasOneParentChildId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"HasOneChild\\") @HasOne(associatedWith = \\"id\\", type = HasOneChild.class) HasOneChild child = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + private final @ModelField(targetType=\\"ID\\") String hasOneParentChildId; + public String getId() { + return id; + } + + public HasOneChild getChild() { + return child; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + public String getHasOneParentChildId() { + return hasOneParentChildId; + } + + private HasOneParent(String id, String hasOneParentChildId) { + this.id = id; + this.hasOneParentChildId = hasOneParentChildId; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + HasOneParent hasOneParent = (HasOneParent) obj; + return ObjectsCompat.equals(getId(), hasOneParent.getId()) && + ObjectsCompat.equals(getCreatedAt(), hasOneParent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), hasOneParent.getUpdatedAt()) && + ObjectsCompat.equals(getHasOneParentChildId(), hasOneParent.getHasOneParentChildId()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .append(getHasOneParentChildId()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"HasOneParent {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") + .append(\\"hasOneParentChildId=\\" + String.valueOf(getHasOneParentChildId())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static HasOneParent justId(String id) { + return new HasOneParent( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + hasOneParentChildId); + } + public interface BuildStep { + HasOneParent build(); + BuildStep id(String id); + BuildStep hasOneParentChildId(String hasOneParentChildId); + } + + + public static class Builder implements BuildStep { + private String id; + private String hasOneParentChildId; + public Builder() { + + } + + private Builder(String id, String hasOneParentChildId) { + this.id = id; + this.hasOneParentChildId = hasOneParentChildId; + } + + @Override + public HasOneParent build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new HasOneParent( + id, + hasOneParentChildId); + } + + @Override + public BuildStep hasOneParentChildId(String hasOneParentChildId) { + this.hasOneParentChildId = hasOneParentChildId; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String hasOneParentChildId) { + super(id, hasOneParentChildId); + + } + + @Override + public CopyOfBuilder hasOneParentChildId(String hasOneParentChildId) { + return (CopyOfBuilder) super.hasOneParentChildId(hasOneParentChildId); + } + } + +} + +/** This is an auto generated class representing the HasOneChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"HasOneChildren\\") +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class HasOneChild implements Model { + public static final QueryField ID = field(\\"HasOneChild\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"HasOneChild\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private HasOneChild(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + HasOneChild hasOneChild = (HasOneChild) obj; + return ObjectsCompat.equals(getId(), hasOneChild.getId()) && + ObjectsCompat.equals(getContent(), hasOneChild.getContent()) && + ObjectsCompat.equals(getCreatedAt(), hasOneChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), hasOneChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"HasOneChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static HasOneChild justId(String id) { + return new HasOneChild( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content); + } + public interface BuildStep { + HasOneChild build(); + BuildStep id(String id); + BuildStep content(String content); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + public Builder() { + + } + + private Builder(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public HasOneChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new HasOneChild( + id, + content); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content) { + super(id, content); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor DataStore Enabled should generate for CompositePKParent and (CompositePK, Implicit, StrangeExplicit, ChildSansBelongsTo) Child models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.annotations.BelongsTo; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the CompositePKParent type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"CompositePKParents\\") +@Index(name = \\"undefined\\", fields = {\\"customId\\",\\"content\\"}) +public final class CompositePKParent implements Model { + public static final QueryField ID = field(\\"CompositePKParent\\", \\"id\\"); + public static final QueryField CUSTOM_ID = field(\\"CompositePKParent\\", \\"customId\\"); + public static final QueryField CONTENT = field(\\"CompositePKParent\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String customId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKChild\\") @HasMany(associatedWith = \\"parent\\", type = CompositePKChild.class) List children = null; + private final @ModelField(targetType=\\"ImplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = ImplicitChild.class) List implicitChildren = null; + private final @ModelField(targetType=\\"StrangeExplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = StrangeExplicitChild.class) List strangeChildren = null; + private final @ModelField(targetType=\\"ChildSansBelongsTo\\") @HasMany(associatedWith = \\"compositePKParentChildrenSansBelongsToId\\", type = ChildSansBelongsTo.class) List childrenSansBelongsTo = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getCustomId() { + return customId; + } + + public String getContent() { + return content; + } + + public List getChildren() { + return children; + } + + public List getImplicitChildren() { + return implicitChildren; + } + + public List getStrangeChildren() { + return strangeChildren; + } + + public List getChildrenSansBelongsTo() { + return childrenSansBelongsTo; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private CompositePKParent(String id, String customId, String content) { + this.id = id; + this.customId = customId; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + CompositePKParent compositePkParent = (CompositePKParent) obj; + return ObjectsCompat.equals(getId(), compositePkParent.getId()) && + ObjectsCompat.equals(getCustomId(), compositePkParent.getCustomId()) && + ObjectsCompat.equals(getContent(), compositePkParent.getContent()) && + ObjectsCompat.equals(getCreatedAt(), compositePkParent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), compositePkParent.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getCustomId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"CompositePKParent {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"customId=\\" + String.valueOf(getCustomId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static CustomIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static CompositePKParent justId(String id) { + return new CompositePKParent( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + customId, + content); + } + public interface CustomIdStep { + ContentStep customId(String customId); + } + + + public interface ContentStep { + BuildStep content(String content); + } + + + public interface BuildStep { + CompositePKParent build(); + BuildStep id(String id); + } + + + public static class Builder implements CustomIdStep, ContentStep, BuildStep { + private String id; + private String customId; + private String content; + public Builder() { + + } + + private Builder(String id, String customId, String content) { + this.id = id; + this.customId = customId; + this.content = content; + } + + @Override + public CompositePKParent build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new CompositePKParent( + id, + customId, + content); + } + + @Override + public ContentStep customId(String customId) { + Objects.requireNonNull(customId); + this.customId = customId; + return this; + } + + @Override + public BuildStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String customId, String content) { + super(id, customId, content); + Objects.requireNonNull(customId); + Objects.requireNonNull(content); + } + + @Override + public CopyOfBuilder customId(String customId) { + return (CopyOfBuilder) super.customId(customId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + +} + +/** This is an auto generated class representing the CompositePKChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"CompositePKChildren\\") +@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) +@Index(name = \\"byParent\\", fields = {\\"parentId\\",\\"parentTitle\\"}) +public final class CompositePKChild implements Model { + public static final QueryField ID = field(\\"CompositePKChild\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"CompositePKChild\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"CompositePKChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"CompositePKChild\\", \\"parentId\\"); + public static final QueryField PARENT_TITLE = field(\\"CompositePKChild\\", \\"parentTitle\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKParent\\") @BelongsTo(targetName = \\"parentId\\", type = CompositePKParent.class) CompositePKParent parent; + private final @ModelField(targetType=\\"String\\") String parentTitle; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getChildId() { + return childId; + } + + public String getContent() { + return content; + } + + public CompositePKParent getParent() { + return parent; + } + + public String getParentTitle() { + return parentTitle; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private CompositePKChild(String id, String childId, String content, CompositePKParent parent, String parentTitle) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + this.parentTitle = parentTitle; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + CompositePKChild compositePkChild = (CompositePKChild) obj; + return ObjectsCompat.equals(getId(), compositePkChild.getId()) && + ObjectsCompat.equals(getChildId(), compositePkChild.getChildId()) && + ObjectsCompat.equals(getContent(), compositePkChild.getContent()) && + ObjectsCompat.equals(getParent(), compositePkChild.getParent()) && + ObjectsCompat.equals(getParentTitle(), compositePkChild.getParentTitle()) && + ObjectsCompat.equals(getCreatedAt(), compositePkChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), compositePkChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getChildId()) + .append(getContent()) + .append(getParent()) + .append(getParentTitle()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"CompositePKChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"parentTitle=\\" + String.valueOf(getParentTitle()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static ChildIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static CompositePKChild justId(String id) { + return new CompositePKChild( + id, + null, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + childId, + content, + parent, + parentTitle); + } + public interface ChildIdStep { + ContentStep childId(String childId); + } + + + public interface ContentStep { + BuildStep content(String content); + } + + + public interface BuildStep { + CompositePKChild build(); + BuildStep id(String id); + BuildStep parent(CompositePKParent parent); + BuildStep parentTitle(String parentTitle); + } + + + public static class Builder implements ChildIdStep, ContentStep, BuildStep { + private String id; + private String childId; + private String content; + private CompositePKParent parent; + private String parentTitle; + public Builder() { + + } + + private Builder(String id, String childId, String content, CompositePKParent parent, String parentTitle) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + this.parentTitle = parentTitle; + } + + @Override + public CompositePKChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new CompositePKChild( + id, + childId, + content, + parent, + parentTitle); + } + + @Override + public ContentStep childId(String childId) { + Objects.requireNonNull(childId); + this.childId = childId; + return this; + } + + @Override + public BuildStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep parent(CompositePKParent parent) { + this.parent = parent; + return this; + } + + @Override + public BuildStep parentTitle(String parentTitle) { + this.parentTitle = parentTitle; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String childId, String content, CompositePKParent parent, String parentTitle) { + super(id, childId, content, parent, parentTitle); + Objects.requireNonNull(childId); + Objects.requireNonNull(content); + } + + @Override + public CopyOfBuilder childId(String childId) { + return (CopyOfBuilder) super.childId(childId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(CompositePKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + + @Override + public CopyOfBuilder parentTitle(String parentTitle) { + return (CopyOfBuilder) super.parentTitle(parentTitle); + } + } + +} + +/** This is an auto generated class representing the ImplicitChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"ImplicitChildren\\") +@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) +public final class ImplicitChild implements Model { + public static final QueryField ID = field(\\"ImplicitChild\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"ImplicitChild\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"ImplicitChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"ImplicitChild\\", \\"compositePKParentImplicitChildrenId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"compositePKParentImplicitChildrenId\\", type = CompositePKParent.class) CompositePKParent parent; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getChildId() { + return childId; + } + + public String getContent() { + return content; + } + + public CompositePKParent getParent() { + return parent; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private ImplicitChild(String id, String childId, String content, CompositePKParent parent) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + ImplicitChild implicitChild = (ImplicitChild) obj; + return ObjectsCompat.equals(getId(), implicitChild.getId()) && + ObjectsCompat.equals(getChildId(), implicitChild.getChildId()) && + ObjectsCompat.equals(getContent(), implicitChild.getContent()) && + ObjectsCompat.equals(getParent(), implicitChild.getParent()) && + ObjectsCompat.equals(getCreatedAt(), implicitChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), implicitChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getChildId()) + .append(getContent()) + .append(getParent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"ImplicitChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static ChildIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static ImplicitChild justId(String id) { + return new ImplicitChild( + id, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + childId, + content, + parent); + } + public interface ChildIdStep { + ContentStep childId(String childId); + } + + + public interface ContentStep { + ParentStep content(String content); + } + + + public interface ParentStep { + BuildStep parent(CompositePKParent parent); + } + + + public interface BuildStep { + ImplicitChild build(); + BuildStep id(String id); + } + + + public static class Builder implements ChildIdStep, ContentStep, ParentStep, BuildStep { + private String id; + private String childId; + private String content; + private CompositePKParent parent; + public Builder() { + + } + + private Builder(String id, String childId, String content, CompositePKParent parent) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + } + + @Override + public ImplicitChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new ImplicitChild( + id, + childId, + content, + parent); + } + + @Override + public ContentStep childId(String childId) { + Objects.requireNonNull(childId); + this.childId = childId; + return this; + } + + @Override + public ParentStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep parent(CompositePKParent parent) { + Objects.requireNonNull(parent); + this.parent = parent; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String childId, String content, CompositePKParent parent) { + super(id, childId, content, parent); + Objects.requireNonNull(childId); + Objects.requireNonNull(content); + Objects.requireNonNull(parent); + } + + @Override + public CopyOfBuilder childId(String childId) { + return (CopyOfBuilder) super.childId(childId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(CompositePKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + } + +} + +/** This is an auto generated class representing the StrangeExplicitChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"StrangeExplicitChildren\\") +@Index(name = \\"undefined\\", fields = {\\"strangeId\\",\\"content\\"}) +@Index(name = \\"byCompositePKParentX\\", fields = {\\"strangeParentId\\",\\"strangeParentTitle\\"}) +public final class StrangeExplicitChild implements Model { + public static final QueryField ID = field(\\"StrangeExplicitChild\\", \\"id\\"); + public static final QueryField STRANGE_ID = field(\\"StrangeExplicitChild\\", \\"strangeId\\"); + public static final QueryField CONTENT = field(\\"StrangeExplicitChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"StrangeExplicitChild\\", \\"strangeParentId\\"); + public static final QueryField STRANGE_PARENT_TITLE = field(\\"StrangeExplicitChild\\", \\"strangeParentTitle\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String strangeId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"strangeParentId\\", type = CompositePKParent.class) CompositePKParent parent; + private final @ModelField(targetType=\\"String\\") String strangeParentTitle; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getStrangeId() { + return strangeId; + } + + public String getContent() { + return content; + } + + public CompositePKParent getParent() { + return parent; + } + + public String getStrangeParentTitle() { + return strangeParentTitle; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private StrangeExplicitChild(String id, String strangeId, String content, CompositePKParent parent, String strangeParentTitle) { + this.id = id; + this.strangeId = strangeId; + this.content = content; + this.parent = parent; + this.strangeParentTitle = strangeParentTitle; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + StrangeExplicitChild strangeExplicitChild = (StrangeExplicitChild) obj; + return ObjectsCompat.equals(getId(), strangeExplicitChild.getId()) && + ObjectsCompat.equals(getStrangeId(), strangeExplicitChild.getStrangeId()) && + ObjectsCompat.equals(getContent(), strangeExplicitChild.getContent()) && + ObjectsCompat.equals(getParent(), strangeExplicitChild.getParent()) && + ObjectsCompat.equals(getStrangeParentTitle(), strangeExplicitChild.getStrangeParentTitle()) && + ObjectsCompat.equals(getCreatedAt(), strangeExplicitChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), strangeExplicitChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getStrangeId()) + .append(getContent()) + .append(getParent()) + .append(getStrangeParentTitle()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"StrangeExplicitChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"strangeId=\\" + String.valueOf(getStrangeId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"strangeParentTitle=\\" + String.valueOf(getStrangeParentTitle()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static StrangeIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static StrangeExplicitChild justId(String id) { + return new StrangeExplicitChild( + id, + null, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + strangeId, + content, + parent, + strangeParentTitle); + } + public interface StrangeIdStep { + ContentStep strangeId(String strangeId); + } + + + public interface ContentStep { + ParentStep content(String content); + } + + + public interface ParentStep { + BuildStep parent(CompositePKParent parent); + } + + + public interface BuildStep { + StrangeExplicitChild build(); + BuildStep id(String id); + BuildStep strangeParentTitle(String strangeParentTitle); + } + + + public static class Builder implements StrangeIdStep, ContentStep, ParentStep, BuildStep { + private String id; + private String strangeId; + private String content; + private CompositePKParent parent; + private String strangeParentTitle; + public Builder() { + + } + + private Builder(String id, String strangeId, String content, CompositePKParent parent, String strangeParentTitle) { + this.id = id; + this.strangeId = strangeId; + this.content = content; + this.parent = parent; + this.strangeParentTitle = strangeParentTitle; + } + + @Override + public StrangeExplicitChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new StrangeExplicitChild( + id, + strangeId, + content, + parent, + strangeParentTitle); + } + + @Override + public ContentStep strangeId(String strangeId) { + Objects.requireNonNull(strangeId); + this.strangeId = strangeId; + return this; + } + + @Override + public ParentStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep parent(CompositePKParent parent) { + Objects.requireNonNull(parent); + this.parent = parent; + return this; + } + + @Override + public BuildStep strangeParentTitle(String strangeParentTitle) { + this.strangeParentTitle = strangeParentTitle; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String strangeId, String content, CompositePKParent parent, String strangeParentTitle) { + super(id, strangeId, content, parent, strangeParentTitle); + Objects.requireNonNull(strangeId); + Objects.requireNonNull(content); + Objects.requireNonNull(parent); + } + + @Override + public CopyOfBuilder strangeId(String strangeId) { + return (CopyOfBuilder) super.strangeId(strangeId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(CompositePKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + + @Override + public CopyOfBuilder strangeParentTitle(String strangeParentTitle) { + return (CopyOfBuilder) super.strangeParentTitle(strangeParentTitle); + } + } + +} + +/** This is an auto generated class representing the ChildSansBelongsTo type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"ChildSansBelongsTos\\") +@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) +@Index(name = \\"byParent\\", fields = {\\"compositePKParentChildrenSansBelongsToCustomId\\",\\"compositePKParentChildrenSansBelongsToContent\\"}) +public final class ChildSansBelongsTo implements Model { + public static final QueryField ID = field(\\"ChildSansBelongsTo\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"ChildSansBelongsTo\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"ChildSansBelongsTo\\", \\"content\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CUSTOM_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToCustomId\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CONTENT = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToContent\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String compositePKParentChildrenSansBelongsToCustomId; + private final @ModelField(targetType=\\"String\\") String compositePKParentChildrenSansBelongsToContent; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + private final @ModelField(targetType=\\"ID\\") String compositePKParentChildrenSansBelongsToId; + public String getId() { + return id; + } + + public String getChildId() { + return childId; + } + + public String getContent() { + return content; + } + + public String getCompositePkParentChildrenSansBelongsToCustomId() { + return compositePKParentChildrenSansBelongsToCustomId; + } + + public String getCompositePkParentChildrenSansBelongsToContent() { + return compositePKParentChildrenSansBelongsToContent; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + public String getCompositePkParentChildrenSansBelongsToId() { + return compositePKParentChildrenSansBelongsToId; + } + + private ChildSansBelongsTo(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { + this.id = id; + this.childId = childId; + this.content = content; + this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; + this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; + this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + ChildSansBelongsTo childSansBelongsTo = (ChildSansBelongsTo) obj; + return ObjectsCompat.equals(getId(), childSansBelongsTo.getId()) && + ObjectsCompat.equals(getChildId(), childSansBelongsTo.getChildId()) && + ObjectsCompat.equals(getContent(), childSansBelongsTo.getContent()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToCustomId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToCustomId()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToContent(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToContent()) && + ObjectsCompat.equals(getCreatedAt(), childSansBelongsTo.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), childSansBelongsTo.getUpdatedAt()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToId()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getChildId()) + .append(getContent()) + .append(getCompositePkParentChildrenSansBelongsToCustomId()) + .append(getCompositePkParentChildrenSansBelongsToContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .append(getCompositePkParentChildrenSansBelongsToId()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"ChildSansBelongsTo {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToCustomId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToCustomId()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToContent=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToId())) + .append(\\"}\\") + .toString(); + } + + public static ChildIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static ChildSansBelongsTo justId(String id) { + return new ChildSansBelongsTo( + id, + null, + null, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + childId, + content, + compositePKParentChildrenSansBelongsToCustomId, + compositePKParentChildrenSansBelongsToContent, + compositePKParentChildrenSansBelongsToId); + } + public interface ChildIdStep { + ContentStep childId(String childId); + } + + + public interface ContentStep { + CompositePkParentChildrenSansBelongsToCustomIdStep content(String content); + } + + + public interface CompositePkParentChildrenSansBelongsToCustomIdStep { + BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId); + } + + + public interface BuildStep { + ChildSansBelongsTo build(); + BuildStep id(String id); + BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent); + BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId); + } + + + public static class Builder implements ChildIdStep, ContentStep, CompositePkParentChildrenSansBelongsToCustomIdStep, BuildStep { + private String id; + private String childId; + private String content; + private String compositePKParentChildrenSansBelongsToCustomId; + private String compositePKParentChildrenSansBelongsToContent; + private String compositePKParentChildrenSansBelongsToId; + public Builder() { + + } + + private Builder(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { + this.id = id; + this.childId = childId; + this.content = content; + this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; + this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; + this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; + } + + @Override + public ChildSansBelongsTo build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new ChildSansBelongsTo( + id, + childId, + content, + compositePKParentChildrenSansBelongsToCustomId, + compositePKParentChildrenSansBelongsToContent, + compositePKParentChildrenSansBelongsToId); + } + + @Override + public ContentStep childId(String childId) { + Objects.requireNonNull(childId); + this.childId = childId; + return this; + } + + @Override + public CompositePkParentChildrenSansBelongsToCustomIdStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { + Objects.requireNonNull(compositePkParentChildrenSansBelongsToCustomId); + this.compositePKParentChildrenSansBelongsToCustomId = compositePkParentChildrenSansBelongsToCustomId; + return this; + } + + @Override + public BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { + this.compositePKParentChildrenSansBelongsToContent = compositePkParentChildrenSansBelongsToContent; + return this; + } + + @Override + public BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { + this.compositePKParentChildrenSansBelongsToId = compositePkParentChildrenSansBelongsToId; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String childId, String content, String compositePkParentChildrenSansBelongsToCustomId, String compositePkParentChildrenSansBelongsToContent, String compositePkParentChildrenSansBelongsToId) { + super(id, childId, content, compositePKParentChildrenSansBelongsToCustomId, compositePKParentChildrenSansBelongsToContent, compositePKParentChildrenSansBelongsToId); + Objects.requireNonNull(childId); + Objects.requireNonNull(content); + Objects.requireNonNull(compositePKParentChildrenSansBelongsToCustomId); + } + + @Override + public CopyOfBuilder childId(String childId) { + return (CopyOfBuilder) super.childId(childId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToCustomId(compositePkParentChildrenSansBelongsToCustomId); + } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToContent(compositePkParentChildrenSansBelongsToContent); + } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToId(compositePkParentChildrenSansBelongsToId); + } + } + +} +" +`; + exports[`AppSyncModelVisitor Should generate for DefaultPKParent DefaultPKChild models 1`] = ` "package com.amplifyframework.datastore.generated.model; diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts index de9e474db..259a66899 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts @@ -17,7 +17,6 @@ const buildSchemaWithDirectives = (schema: String): GraphQLSchema => { return buildSchema([schema, directives, scalars].join('\n')); }; - const getVisitor = ( schema: string, selectedType?: string, @@ -40,101 +39,117 @@ const getVisitor = ( return visitor; }; -const getVisitorPipelinedTransformer = ( - schema: string, - selectedType?: string, - settings: any = {} -) => { - return getVisitor(schema, selectedType, { ...settings, transformerVersion: 2 }); -}; - describe('AppSyncModelVisitor', () => { - it('Should generate for HasOneParent HasOneChild models', () => { - const schema = /* GraphQL */ ` - type HasOneParent @model { - id: ID! @primaryKey - child: HasOneChild @hasOne - } - - type HasOneChild @model { - id: ID! @primaryKey - content: String - } - `; + const schemaHasOneParentChild = /* GraphQL */ ` + type HasOneParent @model { + id: ID! @primaryKey + child: HasOneChild @hasOne + } + + type HasOneChild @model { + id: ID! @primaryKey + content: String + } + `; - const visitor = getVisitor(schema); - const generatedCode = visitor.generate(); - expect(() => validateJava(generatedCode)).not.toThrow(); - expect(generatedCode).toMatchSnapshot(); - }); + const schemaDefaultPKParentChild = /* GraphQL */ ` + type DefaultPKParent @model { + id: ID! @primaryKey + content: String + children: [DefaultPKChild] @hasMany + } + + type DefaultPKChild @model { + id: ID! @primaryKey + content: String + parent: DefaultPKParent @belongsTo + } + `; - it('Should generate for DefaultPKParent DefaultPKChild models', () => { - const schema = /* GraphQL */ ` - type DefaultPKParent @model { - id: ID! @primaryKey - content: String - children: [DefaultPKChild] @hasMany - } - - type DefaultPKChild @model { - id: ID! @primaryKey - content: String - parent: DefaultPKParent @belongsTo - } - `; + const schemaCompositePK = /* GraphQL */ ` + type CompositePKParent @model { + customId: ID! @primaryKey(sortKeyFields:["content"]) + content: String! + children: [CompositePKChild] @hasMany(indexName:"byParent", fields:["customId", "content"]) + implicitChildren: [ImplicitChild] @hasMany + strangeChildren: [StrangeExplicitChild] @hasMany(indexName: "byCompositePKParentX", fields: ["customId", "content"]) + childrenSansBelongsTo: [ChildSansBelongsTo] @hasMany + } + + type CompositePKChild @model { + childId: ID! @primaryKey(sortKeyFields:["content"]) + content: String! + parent: CompositePKParent @belongsTo(fields:["parentId", "parentTitle"]) + parentId: ID @index(name: "byParent", sortKeyFields:["parentTitle"]) + parentTitle: String + } + + type ImplicitChild @model { + childId: ID! @primaryKey(sortKeyFields:["content"]) + content: String! + parent: CompositePKParent! @belongsTo + } + + type StrangeExplicitChild @model { + strangeId: ID! @primaryKey(sortKeyFields:["content"]) + content: String! + parent: CompositePKParent! @belongsTo(fields:["strangeParentId", "strangeParentTitle"]) + strangeParentId: ID @index(name: "byCompositePKParentX", sortKeyFields:["strangeParentTitle"]) + strangeParentTitle: String # customized foreign key for parent sort key + } + + type ChildSansBelongsTo @model { + childId: ID! @primaryKey(sortKeyFields:["content"]) + content: String! + compositePKParentChildrenSansBelongsToCustomId: ID! @index(name: "byParent", sortKeyFields: ["compositePKParentChildrenSansBelongsToContent"]) + compositePKParentChildrenSansBelongsToContent: String + } + `; + describe('DataStore Enabled', () => { + it('Should generate for HasOneParent HasOneChild models', () => { + const visitor = getVisitor(schemaHasOneParentChild, undefined, { isDataStoreEnabled: true }); + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); - const visitor = getVisitor(schema); - const generatedCode = visitor.generate(); - expect(() => validateJava(generatedCode)).not.toThrow(); - expect(generatedCode).toMatchSnapshot(); + it('Should generate for DefaultPKParent DefaultPKChild models', () => { + const visitor = getVisitor(schemaDefaultPKParentChild, undefined, { isDataStoreEnabled: true }); + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); + + it('should generate for CompositePKParent and (CompositePK, Implicit, StrangeExplicit, ChildSansBelongsTo) Child models', () => { + const visitor = getVisitor(schemaCompositePK, undefined, { isDataStoreEnabled: true }); + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); }); - it('should generate for CompositePKParent and (CompositePK, Implicit, StrangeExplicit, ChildSansBelongsTo) Child models', () => { - const schema = /* GraphQL */ ` - type CompositePKParent @model { - customId: ID! @primaryKey(sortKeyFields:["content"]) - content: String! - children: [CompositePKChild] @hasMany(indexName:"byParent", fields:["customId", "content"]) - implicitChildren: [ImplicitChild] @hasMany - strangeChildren: [StrangeExplicitChild] @hasMany(indexName: "byCompositePKParentX", fields: ["customId", "content"]) - childrenSansBelongsTo: [ChildSansBelongsTo] @hasMany - } - - type CompositePKChild @model { - childId: ID! @primaryKey(sortKeyFields:["content"]) - content: String! - parent: CompositePKParent @belongsTo(fields:["parentId", "parentTitle"]) - parentId: ID @index(name: "byParent", sortKeyFields:["parentTitle"]) - parentTitle: String - } - - type ImplicitChild @model { - childId: ID! @primaryKey(sortKeyFields:["content"]) - content: String! - parent: CompositePKParent! @belongsTo - } - - type StrangeExplicitChild @model { - strangeId: ID! @primaryKey(sortKeyFields:["content"]) - content: String! - parent: CompositePKParent! @belongsTo(fields:["strangeParentId", "strangeParentTitle"]) - strangeParentId: ID @index(name: "byCompositePKParentX", sortKeyFields:["strangeParentTitle"]) - strangeParentTitle: String # customized foreign key for parent sort key - } - - type ChildSansBelongsTo @model { - childId: ID! @primaryKey(sortKeyFields:["content"]) - content: String! - compositePKParentChildrenSansBelongsToCustomId: ID! @index(name: "byParent", sortKeyFields: ["compositePKParentChildrenSansBelongsToContent"]) - compositePKParentChildrenSansBelongsToContent: String - } - `; + describe('API only', () => { + it('Should generate for HasOneParent HasOneChild models', () => { + const visitor = getVisitor(schemaHasOneParentChild); + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); + + it('Should generate for DefaultPKParent DefaultPKChild models', () => { + const visitor = getVisitor(schemaDefaultPKParentChild); + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); - const visitor = getVisitor(schema); - const generatedCode = visitor.generate(); - expect(() => validateJava(generatedCode)).not.toThrow(); - expect(generatedCode).toMatchSnapshot(); + it('should generate for CompositePKParent and (CompositePK, Implicit, StrangeExplicit, ChildSansBelongsTo) Child models', () => { + const visitor = getVisitor(schemaCompositePK); + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); }); }); From 3981820cc02211c6e19f10e2b96fc79f3ab08f9f Mon Sep 17 00:00:00 2001 From: tjroach Date: Mon, 18 Sep 2023 16:49:59 -0400 Subject: [PATCH 19/30] lint --- packages/appsync-modelgen-plugin/src/preset.ts | 2 +- packages/graphql-generator/src/typescript.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index caece11e2..4c9c07ed2 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -42,7 +42,7 @@ const generateJavaPreset = ( // Only generate lazy models if feature flag enabled and datastore is not being used. const generateLazyModels = options.config.generateModelsForLazyLoadAndCustomSelectionSet && !options.config.isDataStoreEnabled - + models.forEach(model => { const modelName = model.name.value; config.push({ diff --git a/packages/graphql-generator/src/typescript.ts b/packages/graphql-generator/src/typescript.ts index 80bb5a356..378fc52bf 100644 --- a/packages/graphql-generator/src/typescript.ts +++ b/packages/graphql-generator/src/typescript.ts @@ -20,7 +20,7 @@ export type GenerateModelsOptions = { target: ModelsTarget; directives: string; isDataStoreEnabled?: boolean; - + // feature flags generateIndexRules?: boolean; emitAuthProvider?: boolean; From 413d2b9c65e7a9ae5d1bd085b7e9b3b297375d83 Mon Sep 17 00:00:00 2001 From: tjroach Date: Mon, 25 Sep 2023 09:19:53 -0400 Subject: [PATCH 20/30] Update tests --- ...java-api-lazyload-css-visitor.test.ts.snap | 1937 ----------------- .../appsync-java-visitor.test.ts.snap | 16 +- 2 files changed, 13 insertions(+), 1940 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap index 08d0c9fa1..df63d44ab 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap @@ -3819,1943 +3819,6 @@ public final class ChildSansBelongsTo implements Model { } - public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String childId, String content, String compositePkParentChildrenSansBelongsToCustomId, String compositePkParentChildrenSansBelongsToContent, String compositePkParentChildrenSansBelongsToId) { - super(id, childId, content, compositePKParentChildrenSansBelongsToCustomId, compositePKParentChildrenSansBelongsToContent, compositePKParentChildrenSansBelongsToId); - Objects.requireNonNull(childId); - Objects.requireNonNull(content); - Objects.requireNonNull(compositePKParentChildrenSansBelongsToCustomId); - } - - @Override - public CopyOfBuilder childId(String childId) { - return (CopyOfBuilder) super.childId(childId); - } - - @Override - public CopyOfBuilder content(String content) { - return (CopyOfBuilder) super.content(content); - } - - @Override - public CopyOfBuilder compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { - return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToCustomId(compositePkParentChildrenSansBelongsToCustomId); - } - - @Override - public CopyOfBuilder compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { - return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToContent(compositePkParentChildrenSansBelongsToContent); - } - - @Override - public CopyOfBuilder compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { - return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToId(compositePkParentChildrenSansBelongsToId); - } - } - -} -" -`; - -exports[`AppSyncModelVisitor Should generate for DefaultPKParent DefaultPKChild models 1`] = ` -"package com.amplifyframework.datastore.generated.model; - -import com.amplifyframework.core.model.annotations.HasMany; -import com.amplifyframework.core.model.ModelList; -import com.amplifyframework.core.model.temporal.Temporal; -import com.amplifyframework.core.model.annotations.BelongsTo; -import com.amplifyframework.core.model.ModelReference; -import com.amplifyframework.core.model.LoadedModelReferenceImpl; - -import java.util.List; -import java.util.UUID; -import java.util.Objects; - -import androidx.core.util.ObjectsCompat; - -import com.amplifyframework.core.model.Model; -import com.amplifyframework.core.model.annotations.Index; -import com.amplifyframework.core.model.annotations.ModelConfig; -import com.amplifyframework.core.model.annotations.ModelField; -import com.amplifyframework.core.model.query.predicate.QueryField; - -import static com.amplifyframework.core.model.query.predicate.QueryField.field; - -/** This is an auto generated class representing the DefaultPKParent type in your schema. */ -@SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"DefaultPKParents\\", hasLazySupport = true) -@Index(name = \\"undefined\\", fields = {\\"id\\"}) -public final class DefaultPKParent implements Model { - public static final DefaultPKParentPath rootPath = new DefaultPKParentPath(\\"root\\", false, null); - public static final QueryField ID = field(\\"DefaultPKParent\\", \\"id\\"); - public static final QueryField CONTENT = field(\\"DefaultPKParent\\", \\"content\\"); - private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"String\\") String content; - private final @ModelField(targetType=\\"DefaultPKChild\\") @HasMany(associatedWith = \\"parent\\", type = DefaultPKChild.class) ModelList children = null; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - public String getId() { - return id; - } - - public String getContent() { - return content; - } - - public ModelList getChildren() { - return children; - } - - public Temporal.DateTime getCreatedAt() { - return createdAt; - } - - public Temporal.DateTime getUpdatedAt() { - return updatedAt; - } - - private DefaultPKParent(String id, String content) { - this.id = id; - this.content = content; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if(obj == null || getClass() != obj.getClass()) { - return false; - } else { - DefaultPKParent defaultPkParent = (DefaultPKParent) obj; - return ObjectsCompat.equals(getId(), defaultPkParent.getId()) && - ObjectsCompat.equals(getContent(), defaultPkParent.getContent()) && - ObjectsCompat.equals(getCreatedAt(), defaultPkParent.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), defaultPkParent.getUpdatedAt()); - } - } - - @Override - public int hashCode() { - return new StringBuilder() - .append(getId()) - .append(getContent()) - .append(getCreatedAt()) - .append(getUpdatedAt()) - .toString() - .hashCode(); - } - - @Override - public String toString() { - return new StringBuilder() - .append(\\"DefaultPKParent {\\") - .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) - .append(\\"}\\") - .toString(); - } - - public static BuildStep builder() { - return new Builder(); - } - - /** - * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. - * This is a convenience method to return an instance of the object with only its ID populated - * to be used in the context of a parameter in a delete mutation or referencing a foreign key - * in a relationship. - * @param id the id of the existing item this instance will represent - * @return an instance of this model with only ID populated - */ - public static DefaultPKParent justId(String id) { - return new DefaultPKParent( - id, - null - ); - } - - public CopyOfBuilder copyOfBuilder() { - return new CopyOfBuilder(id, - content); - } - public interface BuildStep { - DefaultPKParent build(); - BuildStep id(String id); - BuildStep content(String content); - } - - - public static class Builder implements BuildStep { - private String id; - private String content; - public Builder() { - - } - - private Builder(String id, String content) { - this.id = id; - this.content = content; - } - - @Override - public DefaultPKParent build() { - String id = this.id != null ? this.id : UUID.randomUUID().toString(); - - return new DefaultPKParent( - id, - content); - } - - @Override - public BuildStep content(String content) { - this.content = content; - return this; - } - - /** - * @param id id - * @return Current Builder instance, for fluent method chaining - */ - public BuildStep id(String id) { - this.id = id; - return this; - } - } - - - public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String content) { - super(id, content); - - } - - @Override - public CopyOfBuilder content(String content) { - return (CopyOfBuilder) super.content(content); - } - } - -} - -/** This is an auto generated class representing the DefaultPKChild type in your schema. */ -@SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"DefaultPKChildren\\", hasLazySupport = true) -@Index(name = \\"undefined\\", fields = {\\"id\\"}) -public final class DefaultPKChild implements Model { - public static final DefaultPKChildPath rootPath = new DefaultPKChildPath(\\"root\\", false, null); - public static final QueryField ID = field(\\"DefaultPKChild\\", \\"id\\"); - public static final QueryField CONTENT = field(\\"DefaultPKChild\\", \\"content\\"); - public static final QueryField PARENT = field(\\"DefaultPKChild\\", \\"defaultPKParentChildrenId\\"); - private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"String\\") String content; - private final @ModelField(targetType=\\"DefaultPKParent\\") @BelongsTo(targetName = \\"defaultPKParentChildrenId\\", type = DefaultPKParent.class) ModelReference parent; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - public String getId() { - return id; - } - - public String getContent() { - return content; - } - - public ModelReference getParent() { - return parent; - } - - public Temporal.DateTime getCreatedAt() { - return createdAt; - } - - public Temporal.DateTime getUpdatedAt() { - return updatedAt; - } - - private DefaultPKChild(String id, String content, ModelReference parent) { - this.id = id; - this.content = content; - this.parent = parent; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if(obj == null || getClass() != obj.getClass()) { - return false; - } else { - DefaultPKChild defaultPkChild = (DefaultPKChild) obj; - return ObjectsCompat.equals(getId(), defaultPkChild.getId()) && - ObjectsCompat.equals(getContent(), defaultPkChild.getContent()) && - ObjectsCompat.equals(getParent(), defaultPkChild.getParent()) && - ObjectsCompat.equals(getCreatedAt(), defaultPkChild.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), defaultPkChild.getUpdatedAt()); - } - } - - @Override - public int hashCode() { - return new StringBuilder() - .append(getId()) - .append(getContent()) - .append(getParent()) - .append(getCreatedAt()) - .append(getUpdatedAt()) - .toString() - .hashCode(); - } - - @Override - public String toString() { - return new StringBuilder() - .append(\\"DefaultPKChild {\\") - .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") - .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) - .append(\\"}\\") - .toString(); - } - - public static BuildStep builder() { - return new Builder(); - } - - /** - * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. - * This is a convenience method to return an instance of the object with only its ID populated - * to be used in the context of a parameter in a delete mutation or referencing a foreign key - * in a relationship. - * @param id the id of the existing item this instance will represent - * @return an instance of this model with only ID populated - */ - public static DefaultPKChild justId(String id) { - return new DefaultPKChild( - id, - null, - null - ); - } - - public CopyOfBuilder copyOfBuilder() { - return new CopyOfBuilder(id, - content, - parent); - } - public interface BuildStep { - DefaultPKChild build(); - BuildStep id(String id); - BuildStep content(String content); - BuildStep parent(DefaultPKParent parent); - } - - - public static class Builder implements BuildStep { - private String id; - private String content; - private ModelReference parent; - public Builder() { - - } - - private Builder(String id, String content, ModelReference parent) { - this.id = id; - this.content = content; - this.parent = parent; - } - - @Override - public DefaultPKChild build() { - String id = this.id != null ? this.id : UUID.randomUUID().toString(); - - return new DefaultPKChild( - id, - content, - parent); - } - - @Override - public BuildStep content(String content) { - this.content = content; - return this; - } - - @Override - public BuildStep parent(DefaultPKParent parent) { - this.parent = new LoadedModelReferenceImpl<>(parent); - return this; - } - - /** - * @param id id - * @return Current Builder instance, for fluent method chaining - */ - public BuildStep id(String id) { - this.id = id; - return this; - } - } - - - public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String content, ModelReference parent) { - super(id, content, parent); - - } - - @Override - public CopyOfBuilder content(String content) { - return (CopyOfBuilder) super.content(content); - } - - @Override - public CopyOfBuilder parent(DefaultPKParent parent) { - return (CopyOfBuilder) super.parent(parent); - } - } - -} -" -`; - -exports[`AppSyncModelVisitor Should generate for HasOneParent HasOneChild models 1`] = ` -"package com.amplifyframework.datastore.generated.model; - -import com.amplifyframework.core.model.annotations.HasOne; -import com.amplifyframework.core.model.ModelReference; -import com.amplifyframework.core.model.LoadedModelReferenceImpl; -import com.amplifyframework.core.model.temporal.Temporal; - -import java.util.List; -import java.util.UUID; -import java.util.Objects; - -import androidx.core.util.ObjectsCompat; - -import com.amplifyframework.core.model.Model; -import com.amplifyframework.core.model.annotations.Index; -import com.amplifyframework.core.model.annotations.ModelConfig; -import com.amplifyframework.core.model.annotations.ModelField; -import com.amplifyframework.core.model.query.predicate.QueryField; - -import static com.amplifyframework.core.model.query.predicate.QueryField.field; - -/** This is an auto generated class representing the HasOneParent type in your schema. */ -@SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"HasOneParents\\", hasLazySupport = true) -@Index(name = \\"undefined\\", fields = {\\"id\\"}) -public final class HasOneParent implements Model { - public static final HasOneParentPath rootPath = new HasOneParentPath(\\"root\\", false, null); - public static final QueryField ID = field(\\"HasOneParent\\", \\"id\\"); - public static final QueryField HAS_ONE_PARENT_CHILD_ID = field(\\"HasOneParent\\", \\"hasOneParentChildId\\"); - private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"HasOneChild\\") @HasOne(associatedWith = \\"id\\", type = HasOneChild.class) ModelReference child = null; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - private final @ModelField(targetType=\\"ID\\") String hasOneParentChildId; - public String getId() { - return id; - } - - public ModelReference getChild() { - return child; - } - - public Temporal.DateTime getCreatedAt() { - return createdAt; - } - - public Temporal.DateTime getUpdatedAt() { - return updatedAt; - } - - public String getHasOneParentChildId() { - return hasOneParentChildId; - } - - private HasOneParent(String id, String hasOneParentChildId) { - this.id = id; - this.hasOneParentChildId = hasOneParentChildId; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if(obj == null || getClass() != obj.getClass()) { - return false; - } else { - HasOneParent hasOneParent = (HasOneParent) obj; - return ObjectsCompat.equals(getId(), hasOneParent.getId()) && - ObjectsCompat.equals(getCreatedAt(), hasOneParent.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), hasOneParent.getUpdatedAt()) && - ObjectsCompat.equals(getHasOneParentChildId(), hasOneParent.getHasOneParentChildId()); - } - } - - @Override - public int hashCode() { - return new StringBuilder() - .append(getId()) - .append(getCreatedAt()) - .append(getUpdatedAt()) - .append(getHasOneParentChildId()) - .toString() - .hashCode(); - } - - @Override - public String toString() { - return new StringBuilder() - .append(\\"HasOneParent {\\") - .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") - .append(\\"hasOneParentChildId=\\" + String.valueOf(getHasOneParentChildId())) - .append(\\"}\\") - .toString(); - } - - public static BuildStep builder() { - return new Builder(); - } - - /** - * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. - * This is a convenience method to return an instance of the object with only its ID populated - * to be used in the context of a parameter in a delete mutation or referencing a foreign key - * in a relationship. - * @param id the id of the existing item this instance will represent - * @return an instance of this model with only ID populated - */ - public static HasOneParent justId(String id) { - return new HasOneParent( - id, - null - ); - } - - public CopyOfBuilder copyOfBuilder() { - return new CopyOfBuilder(id, - hasOneParentChildId); - } - public interface BuildStep { - HasOneParent build(); - BuildStep id(String id); - BuildStep hasOneParentChildId(String hasOneParentChildId); - } - - - public static class Builder implements BuildStep { - private String id; - private String hasOneParentChildId; - public Builder() { - - } - - private Builder(String id, String hasOneParentChildId) { - this.id = id; - this.hasOneParentChildId = hasOneParentChildId; - } - - @Override - public HasOneParent build() { - String id = this.id != null ? this.id : UUID.randomUUID().toString(); - - return new HasOneParent( - id, - hasOneParentChildId); - } - - @Override - public BuildStep hasOneParentChildId(String hasOneParentChildId) { - this.hasOneParentChildId = hasOneParentChildId; - return this; - } - - /** - * @param id id - * @return Current Builder instance, for fluent method chaining - */ - public BuildStep id(String id) { - this.id = id; - return this; - } - } - - - public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String hasOneParentChildId) { - super(id, hasOneParentChildId); - - } - - @Override - public CopyOfBuilder hasOneParentChildId(String hasOneParentChildId) { - return (CopyOfBuilder) super.hasOneParentChildId(hasOneParentChildId); - } - } - -} - -/** This is an auto generated class representing the HasOneChild type in your schema. */ -@SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"HasOneChildren\\", hasLazySupport = true) -@Index(name = \\"undefined\\", fields = {\\"id\\"}) -public final class HasOneChild implements Model { - public static final HasOneChildPath rootPath = new HasOneChildPath(\\"root\\", false, null); - public static final QueryField ID = field(\\"HasOneChild\\", \\"id\\"); - public static final QueryField CONTENT = field(\\"HasOneChild\\", \\"content\\"); - private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"String\\") String content; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - public String getId() { - return id; - } - - public String getContent() { - return content; - } - - public Temporal.DateTime getCreatedAt() { - return createdAt; - } - - public Temporal.DateTime getUpdatedAt() { - return updatedAt; - } - - private HasOneChild(String id, String content) { - this.id = id; - this.content = content; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if(obj == null || getClass() != obj.getClass()) { - return false; - } else { - HasOneChild hasOneChild = (HasOneChild) obj; - return ObjectsCompat.equals(getId(), hasOneChild.getId()) && - ObjectsCompat.equals(getContent(), hasOneChild.getContent()) && - ObjectsCompat.equals(getCreatedAt(), hasOneChild.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), hasOneChild.getUpdatedAt()); - } - } - - @Override - public int hashCode() { - return new StringBuilder() - .append(getId()) - .append(getContent()) - .append(getCreatedAt()) - .append(getUpdatedAt()) - .toString() - .hashCode(); - } - - @Override - public String toString() { - return new StringBuilder() - .append(\\"HasOneChild {\\") - .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) - .append(\\"}\\") - .toString(); - } - - public static BuildStep builder() { - return new Builder(); - } - - /** - * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. - * This is a convenience method to return an instance of the object with only its ID populated - * to be used in the context of a parameter in a delete mutation or referencing a foreign key - * in a relationship. - * @param id the id of the existing item this instance will represent - * @return an instance of this model with only ID populated - */ - public static HasOneChild justId(String id) { - return new HasOneChild( - id, - null - ); - } - - public CopyOfBuilder copyOfBuilder() { - return new CopyOfBuilder(id, - content); - } - public interface BuildStep { - HasOneChild build(); - BuildStep id(String id); - BuildStep content(String content); - } - - - public static class Builder implements BuildStep { - private String id; - private String content; - public Builder() { - - } - - private Builder(String id, String content) { - this.id = id; - this.content = content; - } - - @Override - public HasOneChild build() { - String id = this.id != null ? this.id : UUID.randomUUID().toString(); - - return new HasOneChild( - id, - content); - } - - @Override - public BuildStep content(String content) { - this.content = content; - return this; - } - - /** - * @param id id - * @return Current Builder instance, for fluent method chaining - */ - public BuildStep id(String id) { - this.id = id; - return this; - } - } - - - public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String content) { - super(id, content); - - } - - @Override - public CopyOfBuilder content(String content) { - return (CopyOfBuilder) super.content(content); - } - } - -} -" -`; - -exports[`AppSyncModelVisitor should generate for CompositePKParent and (CompositePK, Implicit, StrangeExplicit, ChildSansBelongsTo) Child models 1`] = ` -"package com.amplifyframework.datastore.generated.model; - -import com.amplifyframework.core.model.annotations.HasMany; -import com.amplifyframework.core.model.ModelList; -import com.amplifyframework.core.model.temporal.Temporal; -import com.amplifyframework.core.model.annotations.BelongsTo; -import com.amplifyframework.core.model.ModelReference; -import com.amplifyframework.core.model.LoadedModelReferenceImpl; - -import java.util.List; -import java.util.UUID; -import java.util.Objects; - -import androidx.core.util.ObjectsCompat; - -import com.amplifyframework.core.model.Model; -import com.amplifyframework.core.model.annotations.Index; -import com.amplifyframework.core.model.annotations.ModelConfig; -import com.amplifyframework.core.model.annotations.ModelField; -import com.amplifyframework.core.model.query.predicate.QueryField; - -import static com.amplifyframework.core.model.query.predicate.QueryField.field; - -/** This is an auto generated class representing the CompositePKParent type in your schema. */ -@SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"CompositePKParents\\", hasLazySupport = true) -@Index(name = \\"undefined\\", fields = {\\"customId\\",\\"content\\"}) -public final class CompositePKParent implements Model { - public static final CompositePKParentPath rootPath = new CompositePKParentPath(\\"root\\", false, null); - public static final QueryField ID = field(\\"CompositePKParent\\", \\"id\\"); - public static final QueryField CUSTOM_ID = field(\\"CompositePKParent\\", \\"customId\\"); - public static final QueryField CONTENT = field(\\"CompositePKParent\\", \\"content\\"); - private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String customId; - private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"CompositePKChild\\") @HasMany(associatedWith = \\"parent\\", type = CompositePKChild.class) ModelList children = null; - private final @ModelField(targetType=\\"ImplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = ImplicitChild.class) ModelList implicitChildren = null; - private final @ModelField(targetType=\\"StrangeExplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = StrangeExplicitChild.class) ModelList strangeChildren = null; - private final @ModelField(targetType=\\"ChildSansBelongsTo\\") @HasMany(associatedWith = \\"compositePKParentChildrenSansBelongsToId\\", type = ChildSansBelongsTo.class) ModelList childrenSansBelongsTo = null; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - public String getId() { - return id; - } - - public String getCustomId() { - return customId; - } - - public String getContent() { - return content; - } - - public ModelList getChildren() { - return children; - } - - public ModelList getImplicitChildren() { - return implicitChildren; - } - - public ModelList getStrangeChildren() { - return strangeChildren; - } - - public ModelList getChildrenSansBelongsTo() { - return childrenSansBelongsTo; - } - - public Temporal.DateTime getCreatedAt() { - return createdAt; - } - - public Temporal.DateTime getUpdatedAt() { - return updatedAt; - } - - private CompositePKParent(String id, String customId, String content) { - this.id = id; - this.customId = customId; - this.content = content; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if(obj == null || getClass() != obj.getClass()) { - return false; - } else { - CompositePKParent compositePkParent = (CompositePKParent) obj; - return ObjectsCompat.equals(getId(), compositePkParent.getId()) && - ObjectsCompat.equals(getCustomId(), compositePkParent.getCustomId()) && - ObjectsCompat.equals(getContent(), compositePkParent.getContent()) && - ObjectsCompat.equals(getCreatedAt(), compositePkParent.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), compositePkParent.getUpdatedAt()); - } - } - - @Override - public int hashCode() { - return new StringBuilder() - .append(getId()) - .append(getCustomId()) - .append(getContent()) - .append(getCreatedAt()) - .append(getUpdatedAt()) - .toString() - .hashCode(); - } - - @Override - public String toString() { - return new StringBuilder() - .append(\\"CompositePKParent {\\") - .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"customId=\\" + String.valueOf(getCustomId()) + \\", \\") - .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) - .append(\\"}\\") - .toString(); - } - - public static CustomIdStep builder() { - return new Builder(); - } - - /** - * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. - * This is a convenience method to return an instance of the object with only its ID populated - * to be used in the context of a parameter in a delete mutation or referencing a foreign key - * in a relationship. - * @param id the id of the existing item this instance will represent - * @return an instance of this model with only ID populated - */ - public static CompositePKParent justId(String id) { - return new CompositePKParent( - id, - null, - null - ); - } - - public CopyOfBuilder copyOfBuilder() { - return new CopyOfBuilder(id, - customId, - content); - } - public interface CustomIdStep { - ContentStep customId(String customId); - } - - - public interface ContentStep { - BuildStep content(String content); - } - - - public interface BuildStep { - CompositePKParent build(); - BuildStep id(String id); - } - - - public static class Builder implements CustomIdStep, ContentStep, BuildStep { - private String id; - private String customId; - private String content; - public Builder() { - - } - - private Builder(String id, String customId, String content) { - this.id = id; - this.customId = customId; - this.content = content; - } - - @Override - public CompositePKParent build() { - String id = this.id != null ? this.id : UUID.randomUUID().toString(); - - return new CompositePKParent( - id, - customId, - content); - } - - @Override - public ContentStep customId(String customId) { - Objects.requireNonNull(customId); - this.customId = customId; - return this; - } - - @Override - public BuildStep content(String content) { - Objects.requireNonNull(content); - this.content = content; - return this; - } - - /** - * @param id id - * @return Current Builder instance, for fluent method chaining - */ - public BuildStep id(String id) { - this.id = id; - return this; - } - } - - - public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String customId, String content) { - super(id, customId, content); - Objects.requireNonNull(customId); - Objects.requireNonNull(content); - } - - @Override - public CopyOfBuilder customId(String customId) { - return (CopyOfBuilder) super.customId(customId); - } - - @Override - public CopyOfBuilder content(String content) { - return (CopyOfBuilder) super.content(content); - } - } - -} - -/** This is an auto generated class representing the CompositePKChild type in your schema. */ -@SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"CompositePKChildren\\", hasLazySupport = true) -@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) -@Index(name = \\"byParent\\", fields = {\\"parentId\\",\\"parentTitle\\"}) -public final class CompositePKChild implements Model { - public static final CompositePKChildPath rootPath = new CompositePKChildPath(\\"root\\", false, null); - public static final QueryField ID = field(\\"CompositePKChild\\", \\"id\\"); - public static final QueryField CHILD_ID = field(\\"CompositePKChild\\", \\"childId\\"); - public static final QueryField CONTENT = field(\\"CompositePKChild\\", \\"content\\"); - public static final QueryField PARENT = field(\\"CompositePKChild\\", \\"parentId\\"); - public static final QueryField PARENT_TITLE = field(\\"CompositePKChild\\", \\"parentTitle\\"); - private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; - private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"CompositePKParent\\") @BelongsTo(targetName = \\"parentId\\", type = CompositePKParent.class) ModelReference parent; - private final @ModelField(targetType=\\"String\\") String parentTitle; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - public String getId() { - return id; - } - - public String getChildId() { - return childId; - } - - public String getContent() { - return content; - } - - public ModelReference getParent() { - return parent; - } - - public String getParentTitle() { - return parentTitle; - } - - public Temporal.DateTime getCreatedAt() { - return createdAt; - } - - public Temporal.DateTime getUpdatedAt() { - return updatedAt; - } - - private CompositePKChild(String id, String childId, String content, ModelReference parent, String parentTitle) { - this.id = id; - this.childId = childId; - this.content = content; - this.parent = parent; - this.parentTitle = parentTitle; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if(obj == null || getClass() != obj.getClass()) { - return false; - } else { - CompositePKChild compositePkChild = (CompositePKChild) obj; - return ObjectsCompat.equals(getId(), compositePkChild.getId()) && - ObjectsCompat.equals(getChildId(), compositePkChild.getChildId()) && - ObjectsCompat.equals(getContent(), compositePkChild.getContent()) && - ObjectsCompat.equals(getParent(), compositePkChild.getParent()) && - ObjectsCompat.equals(getParentTitle(), compositePkChild.getParentTitle()) && - ObjectsCompat.equals(getCreatedAt(), compositePkChild.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), compositePkChild.getUpdatedAt()); - } - } - - @Override - public int hashCode() { - return new StringBuilder() - .append(getId()) - .append(getChildId()) - .append(getContent()) - .append(getParent()) - .append(getParentTitle()) - .append(getCreatedAt()) - .append(getUpdatedAt()) - .toString() - .hashCode(); - } - - @Override - public String toString() { - return new StringBuilder() - .append(\\"CompositePKChild {\\") - .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") - .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") - .append(\\"parentTitle=\\" + String.valueOf(getParentTitle()) + \\", \\") - .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) - .append(\\"}\\") - .toString(); - } - - public static ChildIdStep builder() { - return new Builder(); - } - - /** - * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. - * This is a convenience method to return an instance of the object with only its ID populated - * to be used in the context of a parameter in a delete mutation or referencing a foreign key - * in a relationship. - * @param id the id of the existing item this instance will represent - * @return an instance of this model with only ID populated - */ - public static CompositePKChild justId(String id) { - return new CompositePKChild( - id, - null, - null, - null, - null - ); - } - - public CopyOfBuilder copyOfBuilder() { - return new CopyOfBuilder(id, - childId, - content, - parent, - parentTitle); - } - public interface ChildIdStep { - ContentStep childId(String childId); - } - - - public interface ContentStep { - BuildStep content(String content); - } - - - public interface BuildStep { - CompositePKChild build(); - BuildStep id(String id); - BuildStep parent(CompositePKParent parent); - BuildStep parentTitle(String parentTitle); - } - - - public static class Builder implements ChildIdStep, ContentStep, BuildStep { - private String id; - private String childId; - private String content; - private ModelReference parent; - private String parentTitle; - public Builder() { - - } - - private Builder(String id, String childId, String content, ModelReference parent, String parentTitle) { - this.id = id; - this.childId = childId; - this.content = content; - this.parent = parent; - this.parentTitle = parentTitle; - } - - @Override - public CompositePKChild build() { - String id = this.id != null ? this.id : UUID.randomUUID().toString(); - - return new CompositePKChild( - id, - childId, - content, - parent, - parentTitle); - } - - @Override - public ContentStep childId(String childId) { - Objects.requireNonNull(childId); - this.childId = childId; - return this; - } - - @Override - public BuildStep content(String content) { - Objects.requireNonNull(content); - this.content = content; - return this; - } - - @Override - public BuildStep parent(CompositePKParent parent) { - this.parent = new LoadedModelReferenceImpl<>(parent); - return this; - } - - @Override - public BuildStep parentTitle(String parentTitle) { - this.parentTitle = parentTitle; - return this; - } - - /** - * @param id id - * @return Current Builder instance, for fluent method chaining - */ - public BuildStep id(String id) { - this.id = id; - return this; - } - } - - - public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String childId, String content, ModelReference parent, String parentTitle) { - super(id, childId, content, parent, parentTitle); - Objects.requireNonNull(childId); - Objects.requireNonNull(content); - } - - @Override - public CopyOfBuilder childId(String childId) { - return (CopyOfBuilder) super.childId(childId); - } - - @Override - public CopyOfBuilder content(String content) { - return (CopyOfBuilder) super.content(content); - } - - @Override - public CopyOfBuilder parent(CompositePKParent parent) { - return (CopyOfBuilder) super.parent(parent); - } - - @Override - public CopyOfBuilder parentTitle(String parentTitle) { - return (CopyOfBuilder) super.parentTitle(parentTitle); - } - } - -} - -/** This is an auto generated class representing the ImplicitChild type in your schema. */ -@SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"ImplicitChildren\\", hasLazySupport = true) -@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) -public final class ImplicitChild implements Model { - public static final ImplicitChildPath rootPath = new ImplicitChildPath(\\"root\\", false, null); - public static final QueryField ID = field(\\"ImplicitChild\\", \\"id\\"); - public static final QueryField CHILD_ID = field(\\"ImplicitChild\\", \\"childId\\"); - public static final QueryField CONTENT = field(\\"ImplicitChild\\", \\"content\\"); - public static final QueryField PARENT = field(\\"ImplicitChild\\", \\"compositePKParentImplicitChildrenId\\"); - private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; - private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"compositePKParentImplicitChildrenId\\", type = CompositePKParent.class) ModelReference parent; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - public String getId() { - return id; - } - - public String getChildId() { - return childId; - } - - public String getContent() { - return content; - } - - public ModelReference getParent() { - return parent; - } - - public Temporal.DateTime getCreatedAt() { - return createdAt; - } - - public Temporal.DateTime getUpdatedAt() { - return updatedAt; - } - - private ImplicitChild(String id, String childId, String content, ModelReference parent) { - this.id = id; - this.childId = childId; - this.content = content; - this.parent = parent; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if(obj == null || getClass() != obj.getClass()) { - return false; - } else { - ImplicitChild implicitChild = (ImplicitChild) obj; - return ObjectsCompat.equals(getId(), implicitChild.getId()) && - ObjectsCompat.equals(getChildId(), implicitChild.getChildId()) && - ObjectsCompat.equals(getContent(), implicitChild.getContent()) && - ObjectsCompat.equals(getParent(), implicitChild.getParent()) && - ObjectsCompat.equals(getCreatedAt(), implicitChild.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), implicitChild.getUpdatedAt()); - } - } - - @Override - public int hashCode() { - return new StringBuilder() - .append(getId()) - .append(getChildId()) - .append(getContent()) - .append(getParent()) - .append(getCreatedAt()) - .append(getUpdatedAt()) - .toString() - .hashCode(); - } - - @Override - public String toString() { - return new StringBuilder() - .append(\\"ImplicitChild {\\") - .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") - .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") - .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) - .append(\\"}\\") - .toString(); - } - - public static ChildIdStep builder() { - return new Builder(); - } - - /** - * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. - * This is a convenience method to return an instance of the object with only its ID populated - * to be used in the context of a parameter in a delete mutation or referencing a foreign key - * in a relationship. - * @param id the id of the existing item this instance will represent - * @return an instance of this model with only ID populated - */ - public static ImplicitChild justId(String id) { - return new ImplicitChild( - id, - null, - null, - null - ); - } - - public CopyOfBuilder copyOfBuilder() { - return new CopyOfBuilder(id, - childId, - content, - parent); - } - public interface ChildIdStep { - ContentStep childId(String childId); - } - - - public interface ContentStep { - ParentStep content(String content); - } - - - public interface ParentStep { - BuildStep parent(CompositePKParent parent); - } - - - public interface BuildStep { - ImplicitChild build(); - BuildStep id(String id); - } - - - public static class Builder implements ChildIdStep, ContentStep, ParentStep, BuildStep { - private String id; - private String childId; - private String content; - private ModelReference parent; - public Builder() { - - } - - private Builder(String id, String childId, String content, ModelReference parent) { - this.id = id; - this.childId = childId; - this.content = content; - this.parent = parent; - } - - @Override - public ImplicitChild build() { - String id = this.id != null ? this.id : UUID.randomUUID().toString(); - - return new ImplicitChild( - id, - childId, - content, - parent); - } - - @Override - public ContentStep childId(String childId) { - Objects.requireNonNull(childId); - this.childId = childId; - return this; - } - - @Override - public ParentStep content(String content) { - Objects.requireNonNull(content); - this.content = content; - return this; - } - - @Override - public BuildStep parent(CompositePKParent parent) { - Objects.requireNonNull(parent); - this.parent = new LoadedModelReferenceImpl<>(parent); - return this; - } - - /** - * @param id id - * @return Current Builder instance, for fluent method chaining - */ - public BuildStep id(String id) { - this.id = id; - return this; - } - } - - - public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String childId, String content, ModelReference parent) { - super(id, childId, content, parent); - Objects.requireNonNull(childId); - Objects.requireNonNull(content); - Objects.requireNonNull(parent); - } - - @Override - public CopyOfBuilder childId(String childId) { - return (CopyOfBuilder) super.childId(childId); - } - - @Override - public CopyOfBuilder content(String content) { - return (CopyOfBuilder) super.content(content); - } - - @Override - public CopyOfBuilder parent(CompositePKParent parent) { - return (CopyOfBuilder) super.parent(parent); - } - } - -} - -/** This is an auto generated class representing the StrangeExplicitChild type in your schema. */ -@SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"StrangeExplicitChildren\\", hasLazySupport = true) -@Index(name = \\"undefined\\", fields = {\\"strangeId\\",\\"content\\"}) -@Index(name = \\"byCompositePKParentX\\", fields = {\\"strangeParentId\\",\\"strangeParentTitle\\"}) -public final class StrangeExplicitChild implements Model { - public static final StrangeExplicitChildPath rootPath = new StrangeExplicitChildPath(\\"root\\", false, null); - public static final QueryField ID = field(\\"StrangeExplicitChild\\", \\"id\\"); - public static final QueryField STRANGE_ID = field(\\"StrangeExplicitChild\\", \\"strangeId\\"); - public static final QueryField CONTENT = field(\\"StrangeExplicitChild\\", \\"content\\"); - public static final QueryField PARENT = field(\\"StrangeExplicitChild\\", \\"strangeParentId\\"); - public static final QueryField STRANGE_PARENT_TITLE = field(\\"StrangeExplicitChild\\", \\"strangeParentTitle\\"); - private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String strangeId; - private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"strangeParentId\\", type = CompositePKParent.class) ModelReference parent; - private final @ModelField(targetType=\\"String\\") String strangeParentTitle; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - public String getId() { - return id; - } - - public String getStrangeId() { - return strangeId; - } - - public String getContent() { - return content; - } - - public ModelReference getParent() { - return parent; - } - - public String getStrangeParentTitle() { - return strangeParentTitle; - } - - public Temporal.DateTime getCreatedAt() { - return createdAt; - } - - public Temporal.DateTime getUpdatedAt() { - return updatedAt; - } - - private StrangeExplicitChild(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { - this.id = id; - this.strangeId = strangeId; - this.content = content; - this.parent = parent; - this.strangeParentTitle = strangeParentTitle; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if(obj == null || getClass() != obj.getClass()) { - return false; - } else { - StrangeExplicitChild strangeExplicitChild = (StrangeExplicitChild) obj; - return ObjectsCompat.equals(getId(), strangeExplicitChild.getId()) && - ObjectsCompat.equals(getStrangeId(), strangeExplicitChild.getStrangeId()) && - ObjectsCompat.equals(getContent(), strangeExplicitChild.getContent()) && - ObjectsCompat.equals(getParent(), strangeExplicitChild.getParent()) && - ObjectsCompat.equals(getStrangeParentTitle(), strangeExplicitChild.getStrangeParentTitle()) && - ObjectsCompat.equals(getCreatedAt(), strangeExplicitChild.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), strangeExplicitChild.getUpdatedAt()); - } - } - - @Override - public int hashCode() { - return new StringBuilder() - .append(getId()) - .append(getStrangeId()) - .append(getContent()) - .append(getParent()) - .append(getStrangeParentTitle()) - .append(getCreatedAt()) - .append(getUpdatedAt()) - .toString() - .hashCode(); - } - - @Override - public String toString() { - return new StringBuilder() - .append(\\"StrangeExplicitChild {\\") - .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"strangeId=\\" + String.valueOf(getStrangeId()) + \\", \\") - .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") - .append(\\"strangeParentTitle=\\" + String.valueOf(getStrangeParentTitle()) + \\", \\") - .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) - .append(\\"}\\") - .toString(); - } - - public static StrangeIdStep builder() { - return new Builder(); - } - - /** - * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. - * This is a convenience method to return an instance of the object with only its ID populated - * to be used in the context of a parameter in a delete mutation or referencing a foreign key - * in a relationship. - * @param id the id of the existing item this instance will represent - * @return an instance of this model with only ID populated - */ - public static StrangeExplicitChild justId(String id) { - return new StrangeExplicitChild( - id, - null, - null, - null, - null - ); - } - - public CopyOfBuilder copyOfBuilder() { - return new CopyOfBuilder(id, - strangeId, - content, - parent, - strangeParentTitle); - } - public interface StrangeIdStep { - ContentStep strangeId(String strangeId); - } - - - public interface ContentStep { - ParentStep content(String content); - } - - - public interface ParentStep { - BuildStep parent(CompositePKParent parent); - } - - - public interface BuildStep { - StrangeExplicitChild build(); - BuildStep id(String id); - BuildStep strangeParentTitle(String strangeParentTitle); - } - - - public static class Builder implements StrangeIdStep, ContentStep, ParentStep, BuildStep { - private String id; - private String strangeId; - private String content; - private ModelReference parent; - private String strangeParentTitle; - public Builder() { - - } - - private Builder(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { - this.id = id; - this.strangeId = strangeId; - this.content = content; - this.parent = parent; - this.strangeParentTitle = strangeParentTitle; - } - - @Override - public StrangeExplicitChild build() { - String id = this.id != null ? this.id : UUID.randomUUID().toString(); - - return new StrangeExplicitChild( - id, - strangeId, - content, - parent, - strangeParentTitle); - } - - @Override - public ContentStep strangeId(String strangeId) { - Objects.requireNonNull(strangeId); - this.strangeId = strangeId; - return this; - } - - @Override - public ParentStep content(String content) { - Objects.requireNonNull(content); - this.content = content; - return this; - } - - @Override - public BuildStep parent(CompositePKParent parent) { - Objects.requireNonNull(parent); - this.parent = new LoadedModelReferenceImpl<>(parent); - return this; - } - - @Override - public BuildStep strangeParentTitle(String strangeParentTitle) { - this.strangeParentTitle = strangeParentTitle; - return this; - } - - /** - * @param id id - * @return Current Builder instance, for fluent method chaining - */ - public BuildStep id(String id) { - this.id = id; - return this; - } - } - - - public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { - super(id, strangeId, content, parent, strangeParentTitle); - Objects.requireNonNull(strangeId); - Objects.requireNonNull(content); - Objects.requireNonNull(parent); - } - - @Override - public CopyOfBuilder strangeId(String strangeId) { - return (CopyOfBuilder) super.strangeId(strangeId); - } - - @Override - public CopyOfBuilder content(String content) { - return (CopyOfBuilder) super.content(content); - } - - @Override - public CopyOfBuilder parent(CompositePKParent parent) { - return (CopyOfBuilder) super.parent(parent); - } - - @Override - public CopyOfBuilder strangeParentTitle(String strangeParentTitle) { - return (CopyOfBuilder) super.strangeParentTitle(strangeParentTitle); - } - } - -} - -/** This is an auto generated class representing the ChildSansBelongsTo type in your schema. */ -@SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"ChildSansBelongsTos\\", hasLazySupport = true) -@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) -@Index(name = \\"byParent\\", fields = {\\"compositePKParentChildrenSansBelongsToCustomId\\",\\"compositePKParentChildrenSansBelongsToContent\\"}) -public final class ChildSansBelongsTo implements Model { - public static final ChildSansBelongsToPath rootPath = new ChildSansBelongsToPath(\\"root\\", false, null); - public static final QueryField ID = field(\\"ChildSansBelongsTo\\", \\"id\\"); - public static final QueryField CHILD_ID = field(\\"ChildSansBelongsTo\\", \\"childId\\"); - public static final QueryField CONTENT = field(\\"ChildSansBelongsTo\\", \\"content\\"); - public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CUSTOM_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToCustomId\\"); - public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CONTENT = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToContent\\"); - public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToId\\"); - private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; - private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String compositePKParentChildrenSansBelongsToCustomId; - private final @ModelField(targetType=\\"String\\") String compositePKParentChildrenSansBelongsToContent; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; - private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - private final @ModelField(targetType=\\"ID\\") String compositePKParentChildrenSansBelongsToId; - public String getId() { - return id; - } - - public String getChildId() { - return childId; - } - - public String getContent() { - return content; - } - - public String getCompositePkParentChildrenSansBelongsToCustomId() { - return compositePKParentChildrenSansBelongsToCustomId; - } - - public String getCompositePkParentChildrenSansBelongsToContent() { - return compositePKParentChildrenSansBelongsToContent; - } - - public Temporal.DateTime getCreatedAt() { - return createdAt; - } - - public Temporal.DateTime getUpdatedAt() { - return updatedAt; - } - - public String getCompositePkParentChildrenSansBelongsToId() { - return compositePKParentChildrenSansBelongsToId; - } - - private ChildSansBelongsTo(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { - this.id = id; - this.childId = childId; - this.content = content; - this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; - this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; - this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if(obj == null || getClass() != obj.getClass()) { - return false; - } else { - ChildSansBelongsTo childSansBelongsTo = (ChildSansBelongsTo) obj; - return ObjectsCompat.equals(getId(), childSansBelongsTo.getId()) && - ObjectsCompat.equals(getChildId(), childSansBelongsTo.getChildId()) && - ObjectsCompat.equals(getContent(), childSansBelongsTo.getContent()) && - ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToCustomId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToCustomId()) && - ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToContent(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToContent()) && - ObjectsCompat.equals(getCreatedAt(), childSansBelongsTo.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), childSansBelongsTo.getUpdatedAt()) && - ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToId()); - } - } - - @Override - public int hashCode() { - return new StringBuilder() - .append(getId()) - .append(getChildId()) - .append(getContent()) - .append(getCompositePkParentChildrenSansBelongsToCustomId()) - .append(getCompositePkParentChildrenSansBelongsToContent()) - .append(getCreatedAt()) - .append(getUpdatedAt()) - .append(getCompositePkParentChildrenSansBelongsToId()) - .toString() - .hashCode(); - } - - @Override - public String toString() { - return new StringBuilder() - .append(\\"ChildSansBelongsTo {\\") - .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") - .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"compositePKParentChildrenSansBelongsToCustomId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToCustomId()) + \\", \\") - .append(\\"compositePKParentChildrenSansBelongsToContent=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToContent()) + \\", \\") - .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") - .append(\\"compositePKParentChildrenSansBelongsToId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToId())) - .append(\\"}\\") - .toString(); - } - - public static ChildIdStep builder() { - return new Builder(); - } - - /** - * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. - * This is a convenience method to return an instance of the object with only its ID populated - * to be used in the context of a parameter in a delete mutation or referencing a foreign key - * in a relationship. - * @param id the id of the existing item this instance will represent - * @return an instance of this model with only ID populated - */ - public static ChildSansBelongsTo justId(String id) { - return new ChildSansBelongsTo( - id, - null, - null, - null, - null, - null - ); - } - - public CopyOfBuilder copyOfBuilder() { - return new CopyOfBuilder(id, - childId, - content, - compositePKParentChildrenSansBelongsToCustomId, - compositePKParentChildrenSansBelongsToContent, - compositePKParentChildrenSansBelongsToId); - } - public interface ChildIdStep { - ContentStep childId(String childId); - } - - - public interface ContentStep { - CompositePkParentChildrenSansBelongsToCustomIdStep content(String content); - } - - - public interface CompositePkParentChildrenSansBelongsToCustomIdStep { - BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId); - } - - - public interface BuildStep { - ChildSansBelongsTo build(); - BuildStep id(String id); - BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent); - BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId); - } - - - public static class Builder implements ChildIdStep, ContentStep, CompositePkParentChildrenSansBelongsToCustomIdStep, BuildStep { - private String id; - private String childId; - private String content; - private String compositePKParentChildrenSansBelongsToCustomId; - private String compositePKParentChildrenSansBelongsToContent; - private String compositePKParentChildrenSansBelongsToId; - public Builder() { - - } - - private Builder(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { - this.id = id; - this.childId = childId; - this.content = content; - this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; - this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; - this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; - } - - @Override - public ChildSansBelongsTo build() { - String id = this.id != null ? this.id : UUID.randomUUID().toString(); - - return new ChildSansBelongsTo( - id, - childId, - content, - compositePKParentChildrenSansBelongsToCustomId, - compositePKParentChildrenSansBelongsToContent, - compositePKParentChildrenSansBelongsToId); - } - - @Override - public ContentStep childId(String childId) { - Objects.requireNonNull(childId); - this.childId = childId; - return this; - } - - @Override - public CompositePkParentChildrenSansBelongsToCustomIdStep content(String content) { - Objects.requireNonNull(content); - this.content = content; - return this; - } - - @Override - public BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { - Objects.requireNonNull(compositePkParentChildrenSansBelongsToCustomId); - this.compositePKParentChildrenSansBelongsToCustomId = compositePkParentChildrenSansBelongsToCustomId; - return this; - } - - @Override - public BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { - this.compositePKParentChildrenSansBelongsToContent = compositePkParentChildrenSansBelongsToContent; - return this; - } - - @Override - public BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { - this.compositePKParentChildrenSansBelongsToId = compositePkParentChildrenSansBelongsToId; - return this; - } - - /** - * @param id id - * @return Current Builder instance, for fluent method chaining - */ - public BuildStep id(String id) { - this.id = id; - return this; - } - } - - public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, String childId, String content, String compositePkParentChildrenSansBelongsToCustomId, String compositePkParentChildrenSansBelongsToContent, String compositePkParentChildrenSansBelongsToId) { super(id, childId, content, compositePKParentChildrenSansBelongsToCustomId, compositePKParentChildrenSansBelongsToContent, compositePKParentChildrenSansBelongsToId); diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap index c0a2087d9..b973bf217 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap @@ -7988,6 +7988,16 @@ public final class MyObject implements Model { private String id; private List tutorial; private List formCues; + public Builder() { + + } + + private Builder(String id, List tutorial, List formCues) { + this.id = id; + this.tutorial = tutorial; + this.formCues = formCues; + } + @Override public MyObject build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); @@ -8025,9 +8035,9 @@ public final class MyObject implements Model { public final class CopyOfBuilder extends Builder { private CopyOfBuilder(String id, List tutorial, List formCues) { - super.id(id); - super.tutorial(tutorial) - .formCues(formCues); + super(id, tutorial, formCues); + Objects.requireNonNull(tutorial); + Objects.requireNonNull(formCues); } @Override From 1fb66442f67d8b0ce4dacb0cea360940cfa313d1 Mon Sep 17 00:00:00 2001 From: tjroach Date: Mon, 25 Sep 2023 12:17:47 -0400 Subject: [PATCH 21/30] Add targetNames to belongsTo --- .../visitors/__snapshots__/appsync-java-visitor.test.ts.snap | 2 +- .../src/visitors/appsync-java-visitor.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap index b973bf217..7a37765e7 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap @@ -468,7 +468,7 @@ public final class Project implements Model { public static final QueryField PROJECT_TEAM_NAME = field(\\"Project\\", \\"projectTeamName\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String projectId; private final @ModelField(targetType=\\"String\\", isRequired = true) String name; - private final @ModelField(targetType=\\"Team\\") @HasOne(associatedWith = \\"project\\", type = Team.class) Team team = null; + private final @ModelField(targetType=\\"Team\\") @HasOne(associatedWith = \\"project\\", targetNames = {\\"projectTeamTeamId\\", \\"projectTeamName\\"}, type = Team.class) Team team = null; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; private final @ModelField(targetType=\\"ID\\") String projectTeamTeamId; diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index ccf7b20e6..b9eba486d 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -1111,6 +1111,10 @@ export class AppSyncModelJavaVisitor< case CodeGenConnectionType.HAS_ONE: connectionDirectiveName = 'HasOne'; connectionArguments.push(`associatedWith = "${this.getFieldName(connectionInfo.associatedWith)}"`); + if (this.isCustomPKEnabled()) { + const hasOneTargetNamesArgs = `targetNames = {${connectionInfo.targetNames.map(target => `"${target}"`).join(', ')}}`; + connectionArguments.push(hasOneTargetNamesArgs); + } break; case CodeGenConnectionType.HAS_MANY: connectionDirectiveName = 'HasMany'; From 1a0e6b412a112d12902212091bedb755a0cc5365 Mon Sep 17 00:00:00 2001 From: Michael Law <1365977+lawmicha@users.noreply.github.com> Date: Wed, 27 Sep 2023 15:54:36 -0400 Subject: [PATCH 22/30] Create manyToMany join model path files --- .../appsync-modelgen-plugin/src/preset.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index caece11e2..6c0449a22 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -4,6 +4,7 @@ import { join } from 'path'; import { JAVA_SCALAR_MAP, SWIFT_SCALAR_MAP, TYPESCRIPT_SCALAR_MAP, DART_SCALAR_MAP, METADATA_SCALAR_MAP } from './scalars'; import { LOADER_CLASS_NAME, GENERATED_PACKAGE_NAME } from './configs/java-config'; import { graphqlName, toUpper } from 'graphql-transformer-common'; +import { ObjectTypeDefinitionNode, StringValueNode } from "graphql/language/ast"; const APPSYNC_DATA_STORE_CODEGEN_TARGETS = ['java', 'swift', 'javascript', 'typescript', 'dart', 'introspection']; @@ -81,6 +82,38 @@ const generateJavaPreset = ( }, }); } + + // Create ModelPath's for manyToMany's join model. + // Type cast to ObjectTypeDefinition to access `fields`. + if (model.kind === Kind.OBJECT_TYPE_DEFINITION) { + const modelObject = model as ObjectTypeDefinitionNode; + + // For each field, find all fields that are directives of type "manyToMany" + modelObject?.fields?.forEach(field => { + const manyToManyDirectives = field.directives?.filter(directive => directive.name.value === "manyToMany"); + + // For each "manyToMany" directive, find the "relationName" Argument's value. This is the name of the join model. + manyToManyDirectives?.forEach(manyToManyDirective => { + const argument = manyToManyDirective.arguments?.find(argument => argument.name.value === "relationName"); + if (argument?.value.kind === "StringValue") { + const stringValue = argument?.value as StringValueNode; + let joinModelName = graphqlName(toUpper(stringValue.value)); + + // Create the Join model's Model Path file. + config.push({ + ...options, + filename: join(...modelFolder, `${joinModelName}Path.java`), + config: { + ...options.config, + scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, + generate: 'metadata', + selectedType: joinModelName, + }, + }); + } + }); + }); + } } }); From 840a1977905f7c005073645e8425daed9d155230 Mon Sep 17 00:00:00 2001 From: tjroach Date: Thu, 28 Sep 2023 10:28:33 -0400 Subject: [PATCH 23/30] Update API.md --- packages/appsync-modelgen-plugin/API.md | 1 + packages/graphql-generator/API.md | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/appsync-modelgen-plugin/API.md b/packages/appsync-modelgen-plugin/API.md index 842815169..7d3a4d3be 100644 --- a/packages/appsync-modelgen-plugin/API.md +++ b/packages/appsync-modelgen-plugin/API.md @@ -16,6 +16,7 @@ export const addToSchema: (config: AppSyncModelPluginConfig) => string; export type AppSyncModelCodeGenPresetConfig = { overrideOutputDir: string | null; target: Target; + isDataStoreEnabled?: boolean; }; // @public (undocumented) diff --git a/packages/graphql-generator/API.md b/packages/graphql-generator/API.md index 75571257c..b24bec8b8 100644 --- a/packages/graphql-generator/API.md +++ b/packages/graphql-generator/API.md @@ -20,6 +20,7 @@ export type GenerateModelsOptions = { schema: string; target: ModelsTarget; directives: string; + isDataStoreEnabled?: boolean; generateIndexRules?: boolean; emitAuthProvider?: boolean; useExperimentalPipelinedTransformer?: boolean; From de9450b03c6eeb6c1cc7c1b9872f4f84723f7083 Mon Sep 17 00:00:00 2001 From: Michael Law <1365977+lawmicha@users.noreply.github.com> Date: Thu, 28 Sep 2023 12:25:17 -0400 Subject: [PATCH 24/30] add more test cases --- ...java-api-lazyload-css-visitor.test.ts.snap | 5724 +++++++++++++---- ...sync-java-api-lazyload-css-visitor.test.ts | 91 + 2 files changed, 4609 insertions(+), 1206 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap index df63d44ab..6fd6f205b 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-api-lazyload-css-visitor.test.ts.snap @@ -699,7 +699,7 @@ public final class HasOneChild implements Model { " `; -exports[`AppSyncModelVisitor API only should generate for CompositePKParent and (CompositePK, Implicit, StrangeExplicit, ChildSansBelongsTo) Child models 1`] = ` +exports[`AppSyncModelVisitor API only should generate for Blog, Post, and Comment models 1`] = ` "package com.amplifyframework.datastore.generated.model; import com.amplifyframework.core.model.annotations.HasMany; @@ -723,50 +723,35 @@ import com.amplifyframework.core.model.query.predicate.QueryField; import static com.amplifyframework.core.model.query.predicate.QueryField.field; -/** This is an auto generated class representing the CompositePKParent type in your schema. */ +/** This is an auto generated class representing the Blog type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"CompositePKParents\\", hasLazySupport = true) -@Index(name = \\"undefined\\", fields = {\\"customId\\",\\"content\\"}) -public final class CompositePKParent implements Model { - public static final CompositePKParentPath rootPath = new CompositePKParentPath(\\"root\\", false, null); - public static final QueryField ID = field(\\"CompositePKParent\\", \\"id\\"); - public static final QueryField CUSTOM_ID = field(\\"CompositePKParent\\", \\"customId\\"); - public static final QueryField CONTENT = field(\\"CompositePKParent\\", \\"content\\"); +@ModelConfig(pluralName = \\"Blogs\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"blogId\\"}) +public final class Blog implements Model { + public static final BlogPath rootPath = new BlogPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"Blog\\", \\"id\\"); + public static final QueryField BLOG_ID = field(\\"Blog\\", \\"blogId\\"); + public static final QueryField NAME = field(\\"Blog\\", \\"name\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String customId; - private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"CompositePKChild\\") @HasMany(associatedWith = \\"parent\\", type = CompositePKChild.class) ModelList children = null; - private final @ModelField(targetType=\\"ImplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = ImplicitChild.class) ModelList implicitChildren = null; - private final @ModelField(targetType=\\"StrangeExplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = StrangeExplicitChild.class) ModelList strangeChildren = null; - private final @ModelField(targetType=\\"ChildSansBelongsTo\\") @HasMany(associatedWith = \\"compositePKParentChildrenSansBelongsToId\\", type = ChildSansBelongsTo.class) ModelList childrenSansBelongsTo = null; + private final @ModelField(targetType=\\"String\\", isRequired = true) String blogId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String name; + private final @ModelField(targetType=\\"Post\\", isRequired = true) @HasMany(associatedWith = \\"blog\\", type = Post.class) ModelList posts = null; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; public String getId() { return id; } - public String getCustomId() { - return customId; - } - - public String getContent() { - return content; - } - - public ModelList getChildren() { - return children; - } - - public ModelList getImplicitChildren() { - return implicitChildren; + public String getBlogId() { + return blogId; } - public ModelList getStrangeChildren() { - return strangeChildren; + public String getName() { + return name; } - public ModelList getChildrenSansBelongsTo() { - return childrenSansBelongsTo; + public ModelList getPosts() { + return posts; } public Temporal.DateTime getCreatedAt() { @@ -777,10 +762,10 @@ public final class CompositePKParent implements Model { return updatedAt; } - private CompositePKParent(String id, String customId, String content) { + private Blog(String id, String blogId, String name) { this.id = id; - this.customId = customId; - this.content = content; + this.blogId = blogId; + this.name = name; } @Override @@ -790,12 +775,12 @@ public final class CompositePKParent implements Model { } else if(obj == null || getClass() != obj.getClass()) { return false; } else { - CompositePKParent compositePkParent = (CompositePKParent) obj; - return ObjectsCompat.equals(getId(), compositePkParent.getId()) && - ObjectsCompat.equals(getCustomId(), compositePkParent.getCustomId()) && - ObjectsCompat.equals(getContent(), compositePkParent.getContent()) && - ObjectsCompat.equals(getCreatedAt(), compositePkParent.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), compositePkParent.getUpdatedAt()); + Blog blog = (Blog) obj; + return ObjectsCompat.equals(getId(), blog.getId()) && + ObjectsCompat.equals(getBlogId(), blog.getBlogId()) && + ObjectsCompat.equals(getName(), blog.getName()) && + ObjectsCompat.equals(getCreatedAt(), blog.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), blog.getUpdatedAt()); } } @@ -803,8 +788,8 @@ public final class CompositePKParent implements Model { public int hashCode() { return new StringBuilder() .append(getId()) - .append(getCustomId()) - .append(getContent()) + .append(getBlogId()) + .append(getName()) .append(getCreatedAt()) .append(getUpdatedAt()) .toString() @@ -814,17 +799,17 @@ public final class CompositePKParent implements Model { @Override public String toString() { return new StringBuilder() - .append(\\"CompositePKParent {\\") + .append(\\"Blog {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"customId=\\" + String.valueOf(getCustomId()) + \\", \\") - .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"blogId=\\" + String.valueOf(getBlogId()) + \\", \\") + .append(\\"name=\\" + String.valueOf(getName()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) .append(\\"}\\") .toString(); } - public static CustomIdStep builder() { + public static BlogIdStep builder() { return new Builder(); } @@ -836,8 +821,8 @@ public final class CompositePKParent implements Model { * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated */ - public static CompositePKParent justId(String id) { - return new CompositePKParent( + public static Blog justId(String id) { + return new Blog( id, null, null @@ -846,60 +831,60 @@ public final class CompositePKParent implements Model { public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - customId, - content); + blogId, + name); } - public interface CustomIdStep { - ContentStep customId(String customId); + public interface BlogIdStep { + NameStep blogId(String blogId); } - public interface ContentStep { - BuildStep content(String content); + public interface NameStep { + BuildStep name(String name); } public interface BuildStep { - CompositePKParent build(); + Blog build(); BuildStep id(String id); } - public static class Builder implements CustomIdStep, ContentStep, BuildStep { + public static class Builder implements BlogIdStep, NameStep, BuildStep { private String id; - private String customId; - private String content; + private String blogId; + private String name; public Builder() { } - private Builder(String id, String customId, String content) { + private Builder(String id, String blogId, String name) { this.id = id; - this.customId = customId; - this.content = content; + this.blogId = blogId; + this.name = name; } @Override - public CompositePKParent build() { + public Blog build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); - return new CompositePKParent( + return new Blog( id, - customId, - content); + blogId, + name); } @Override - public ContentStep customId(String customId) { - Objects.requireNonNull(customId); - this.customId = customId; + public NameStep blogId(String blogId) { + Objects.requireNonNull(blogId); + this.blogId = blogId; return this; } @Override - public BuildStep content(String content) { - Objects.requireNonNull(content); - this.content = content; + public BuildStep name(String name) { + Objects.requireNonNull(name); + this.name = name; return this; } @@ -915,62 +900,60 @@ public final class CompositePKParent implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String customId, String content) { - super(id, customId, content); - Objects.requireNonNull(customId); - Objects.requireNonNull(content); + private CopyOfBuilder(String id, String blogId, String name) { + super(id, blogId, name); + Objects.requireNonNull(blogId); + Objects.requireNonNull(name); } @Override - public CopyOfBuilder customId(String customId) { - return (CopyOfBuilder) super.customId(customId); + public CopyOfBuilder blogId(String blogId) { + return (CopyOfBuilder) super.blogId(blogId); } @Override - public CopyOfBuilder content(String content) { - return (CopyOfBuilder) super.content(content); + public CopyOfBuilder name(String name) { + return (CopyOfBuilder) super.name(name); } } } -/** This is an auto generated class representing the CompositePKChild type in your schema. */ +/** This is an auto generated class representing the Post type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"CompositePKChildren\\", hasLazySupport = true) -@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) -@Index(name = \\"byParent\\", fields = {\\"parentId\\",\\"parentTitle\\"}) -public final class CompositePKChild implements Model { - public static final CompositePKChildPath rootPath = new CompositePKChildPath(\\"root\\", false, null); - public static final QueryField ID = field(\\"CompositePKChild\\", \\"id\\"); - public static final QueryField CHILD_ID = field(\\"CompositePKChild\\", \\"childId\\"); - public static final QueryField CONTENT = field(\\"CompositePKChild\\", \\"content\\"); - public static final QueryField PARENT = field(\\"CompositePKChild\\", \\"parentId\\"); - public static final QueryField PARENT_TITLE = field(\\"CompositePKChild\\", \\"parentTitle\\"); +@ModelConfig(pluralName = \\"Posts\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"postId\\",\\"title\\"}) +public final class Post implements Model { + public static final PostPath rootPath = new PostPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"Post\\", \\"id\\"); + public static final QueryField POST_ID = field(\\"Post\\", \\"postId\\"); + public static final QueryField TITLE = field(\\"Post\\", \\"title\\"); + public static final QueryField BLOG = field(\\"Post\\", \\"blogPostsId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; - private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"CompositePKParent\\") @BelongsTo(targetName = \\"parentId\\", type = CompositePKParent.class) ModelReference parent; - private final @ModelField(targetType=\\"String\\") String parentTitle; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String postId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String title; + private final @ModelField(targetType=\\"Blog\\", isRequired = true) @BelongsTo(targetName = \\"blogPostsId\\", type = Blog.class) ModelReference blog; + private final @ModelField(targetType=\\"Comment\\", isRequired = true) @HasMany(associatedWith = \\"post\\", type = Comment.class) ModelList comments = null; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; public String getId() { return id; } - public String getChildId() { - return childId; + public String getPostId() { + return postId; } - public String getContent() { - return content; + public String getTitle() { + return title; } - public ModelReference getParent() { - return parent; + public ModelReference getBlog() { + return blog; } - public String getParentTitle() { - return parentTitle; + public ModelList getComments() { + return comments; } public Temporal.DateTime getCreatedAt() { @@ -981,12 +964,11 @@ public final class CompositePKChild implements Model { return updatedAt; } - private CompositePKChild(String id, String childId, String content, ModelReference parent, String parentTitle) { + private Post(String id, String postId, String title, ModelReference blog) { this.id = id; - this.childId = childId; - this.content = content; - this.parent = parent; - this.parentTitle = parentTitle; + this.postId = postId; + this.title = title; + this.blog = blog; } @Override @@ -996,14 +978,13 @@ public final class CompositePKChild implements Model { } else if(obj == null || getClass() != obj.getClass()) { return false; } else { - CompositePKChild compositePkChild = (CompositePKChild) obj; - return ObjectsCompat.equals(getId(), compositePkChild.getId()) && - ObjectsCompat.equals(getChildId(), compositePkChild.getChildId()) && - ObjectsCompat.equals(getContent(), compositePkChild.getContent()) && - ObjectsCompat.equals(getParent(), compositePkChild.getParent()) && - ObjectsCompat.equals(getParentTitle(), compositePkChild.getParentTitle()) && - ObjectsCompat.equals(getCreatedAt(), compositePkChild.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), compositePkChild.getUpdatedAt()); + Post post = (Post) obj; + return ObjectsCompat.equals(getId(), post.getId()) && + ObjectsCompat.equals(getPostId(), post.getPostId()) && + ObjectsCompat.equals(getTitle(), post.getTitle()) && + ObjectsCompat.equals(getBlog(), post.getBlog()) && + ObjectsCompat.equals(getCreatedAt(), post.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), post.getUpdatedAt()); } } @@ -1011,10 +992,9 @@ public final class CompositePKChild implements Model { public int hashCode() { return new StringBuilder() .append(getId()) - .append(getChildId()) - .append(getContent()) - .append(getParent()) - .append(getParentTitle()) + .append(getPostId()) + .append(getTitle()) + .append(getBlog()) .append(getCreatedAt()) .append(getUpdatedAt()) .toString() @@ -1024,19 +1004,18 @@ public final class CompositePKChild implements Model { @Override public String toString() { return new StringBuilder() - .append(\\"CompositePKChild {\\") + .append(\\"Post {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") - .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") - .append(\\"parentTitle=\\" + String.valueOf(getParentTitle()) + \\", \\") + .append(\\"postId=\\" + String.valueOf(getPostId()) + \\", \\") + .append(\\"title=\\" + String.valueOf(getTitle()) + \\", \\") + .append(\\"blog=\\" + String.valueOf(getBlog()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) .append(\\"}\\") .toString(); } - public static ChildIdStep builder() { + public static PostIdStep builder() { return new Builder(); } @@ -1048,94 +1027,87 @@ public final class CompositePKChild implements Model { * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated */ - public static CompositePKChild justId(String id) { - return new CompositePKChild( + public static Post justId(String id) { + return new Post( id, null, null, - null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - childId, - content, - parent, - parentTitle); + postId, + title, + blog); } - public interface ChildIdStep { - ContentStep childId(String childId); + public interface PostIdStep { + TitleStep postId(String postId); } - public interface ContentStep { - BuildStep content(String content); + public interface TitleStep { + BlogStep title(String title); + } + + + public interface BlogStep { + BuildStep blog(Blog blog); } public interface BuildStep { - CompositePKChild build(); + Post build(); BuildStep id(String id); - BuildStep parent(CompositePKParent parent); - BuildStep parentTitle(String parentTitle); } - public static class Builder implements ChildIdStep, ContentStep, BuildStep { + public static class Builder implements PostIdStep, TitleStep, BlogStep, BuildStep { private String id; - private String childId; - private String content; - private ModelReference parent; - private String parentTitle; + private String postId; + private String title; + private ModelReference blog; public Builder() { } - private Builder(String id, String childId, String content, ModelReference parent, String parentTitle) { + private Builder(String id, String postId, String title, ModelReference blog) { this.id = id; - this.childId = childId; - this.content = content; - this.parent = parent; - this.parentTitle = parentTitle; + this.postId = postId; + this.title = title; + this.blog = blog; } @Override - public CompositePKChild build() { + public Post build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); - return new CompositePKChild( + return new Post( id, - childId, - content, - parent, - parentTitle); + postId, + title, + blog); } @Override - public ContentStep childId(String childId) { - Objects.requireNonNull(childId); - this.childId = childId; - return this; - } - - @Override - public BuildStep content(String content) { - Objects.requireNonNull(content); - this.content = content; + public TitleStep postId(String postId) { + Objects.requireNonNull(postId); + this.postId = postId; return this; } @Override - public BuildStep parent(CompositePKParent parent) { - this.parent = new LoadedModelReferenceImpl<>(parent); + public BlogStep title(String title) { + Objects.requireNonNull(title); + this.title = title; return this; } @Override - public BuildStep parentTitle(String parentTitle) { - this.parentTitle = parentTitle; + public BuildStep blog(Blog blog) { + Objects.requireNonNull(blog); + this.blog = new LoadedModelReferenceImpl<>(blog); return this; } @@ -1151,65 +1123,61 @@ public final class CompositePKChild implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String childId, String content, ModelReference parent, String parentTitle) { - super(id, childId, content, parent, parentTitle); - Objects.requireNonNull(childId); - Objects.requireNonNull(content); - } - - @Override - public CopyOfBuilder childId(String childId) { - return (CopyOfBuilder) super.childId(childId); + private CopyOfBuilder(String id, String postId, String title, ModelReference blog) { + super(id, postId, title, blog); + Objects.requireNonNull(postId); + Objects.requireNonNull(title); + Objects.requireNonNull(blog); } @Override - public CopyOfBuilder content(String content) { - return (CopyOfBuilder) super.content(content); + public CopyOfBuilder postId(String postId) { + return (CopyOfBuilder) super.postId(postId); } @Override - public CopyOfBuilder parent(CompositePKParent parent) { - return (CopyOfBuilder) super.parent(parent); + public CopyOfBuilder title(String title) { + return (CopyOfBuilder) super.title(title); } @Override - public CopyOfBuilder parentTitle(String parentTitle) { - return (CopyOfBuilder) super.parentTitle(parentTitle); + public CopyOfBuilder blog(Blog blog) { + return (CopyOfBuilder) super.blog(blog); } } } -/** This is an auto generated class representing the ImplicitChild type in your schema. */ +/** This is an auto generated class representing the Comment type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"ImplicitChildren\\", hasLazySupport = true) -@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) -public final class ImplicitChild implements Model { - public static final ImplicitChildPath rootPath = new ImplicitChildPath(\\"root\\", false, null); - public static final QueryField ID = field(\\"ImplicitChild\\", \\"id\\"); - public static final QueryField CHILD_ID = field(\\"ImplicitChild\\", \\"childId\\"); - public static final QueryField CONTENT = field(\\"ImplicitChild\\", \\"content\\"); - public static final QueryField PARENT = field(\\"ImplicitChild\\", \\"compositePKParentImplicitChildrenId\\"); +@ModelConfig(pluralName = \\"Comments\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"commentId\\",\\"content\\"}) +public final class Comment implements Model { + public static final CommentPath rootPath = new CommentPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"Comment\\", \\"id\\"); + public static final QueryField COMMENT_ID = field(\\"Comment\\", \\"commentId\\"); + public static final QueryField CONTENT = field(\\"Comment\\", \\"content\\"); + public static final QueryField POST = field(\\"Comment\\", \\"postCommentsId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String commentId; private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"compositePKParentImplicitChildrenId\\", type = CompositePKParent.class) ModelReference parent; + private final @ModelField(targetType=\\"Post\\", isRequired = true) @BelongsTo(targetName = \\"postCommentsId\\", type = Post.class) ModelReference post; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; public String getId() { return id; } - public String getChildId() { - return childId; + public String getCommentId() { + return commentId; } public String getContent() { return content; } - public ModelReference getParent() { - return parent; + public ModelReference getPost() { + return post; } public Temporal.DateTime getCreatedAt() { @@ -1220,11 +1188,11 @@ public final class ImplicitChild implements Model { return updatedAt; } - private ImplicitChild(String id, String childId, String content, ModelReference parent) { + private Comment(String id, String commentId, String content, ModelReference post) { this.id = id; - this.childId = childId; + this.commentId = commentId; this.content = content; - this.parent = parent; + this.post = post; } @Override @@ -1234,13 +1202,13 @@ public final class ImplicitChild implements Model { } else if(obj == null || getClass() != obj.getClass()) { return false; } else { - ImplicitChild implicitChild = (ImplicitChild) obj; - return ObjectsCompat.equals(getId(), implicitChild.getId()) && - ObjectsCompat.equals(getChildId(), implicitChild.getChildId()) && - ObjectsCompat.equals(getContent(), implicitChild.getContent()) && - ObjectsCompat.equals(getParent(), implicitChild.getParent()) && - ObjectsCompat.equals(getCreatedAt(), implicitChild.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), implicitChild.getUpdatedAt()); + Comment comment = (Comment) obj; + return ObjectsCompat.equals(getId(), comment.getId()) && + ObjectsCompat.equals(getCommentId(), comment.getCommentId()) && + ObjectsCompat.equals(getContent(), comment.getContent()) && + ObjectsCompat.equals(getPost(), comment.getPost()) && + ObjectsCompat.equals(getCreatedAt(), comment.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), comment.getUpdatedAt()); } } @@ -1248,9 +1216,9 @@ public final class ImplicitChild implements Model { public int hashCode() { return new StringBuilder() .append(getId()) - .append(getChildId()) + .append(getCommentId()) .append(getContent()) - .append(getParent()) + .append(getPost()) .append(getCreatedAt()) .append(getUpdatedAt()) .toString() @@ -1260,18 +1228,18 @@ public final class ImplicitChild implements Model { @Override public String toString() { return new StringBuilder() - .append(\\"ImplicitChild {\\") + .append(\\"Comment {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") + .append(\\"commentId=\\" + String.valueOf(getCommentId()) + \\", \\") .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"post=\\" + String.valueOf(getPost()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) .append(\\"}\\") .toString(); } - public static ChildIdStep builder() { + public static CommentIdStep builder() { return new Builder(); } @@ -1283,8 +1251,8 @@ public final class ImplicitChild implements Model { * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated */ - public static ImplicitChild justId(String id) { - return new ImplicitChild( + public static Comment justId(String id) { + return new Comment( id, null, null, @@ -1294,76 +1262,76 @@ public final class ImplicitChild implements Model { public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - childId, + commentId, content, - parent); + post); } - public interface ChildIdStep { - ContentStep childId(String childId); + public interface CommentIdStep { + ContentStep commentId(String commentId); } public interface ContentStep { - ParentStep content(String content); + PostStep content(String content); } - public interface ParentStep { - BuildStep parent(CompositePKParent parent); + public interface PostStep { + BuildStep post(Post post); } public interface BuildStep { - ImplicitChild build(); + Comment build(); BuildStep id(String id); } - public static class Builder implements ChildIdStep, ContentStep, ParentStep, BuildStep { + public static class Builder implements CommentIdStep, ContentStep, PostStep, BuildStep { private String id; - private String childId; + private String commentId; private String content; - private ModelReference parent; + private ModelReference post; public Builder() { } - private Builder(String id, String childId, String content, ModelReference parent) { + private Builder(String id, String commentId, String content, ModelReference post) { this.id = id; - this.childId = childId; + this.commentId = commentId; this.content = content; - this.parent = parent; + this.post = post; } @Override - public ImplicitChild build() { + public Comment build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); - return new ImplicitChild( + return new Comment( id, - childId, + commentId, content, - parent); + post); } @Override - public ContentStep childId(String childId) { - Objects.requireNonNull(childId); - this.childId = childId; + public ContentStep commentId(String commentId) { + Objects.requireNonNull(commentId); + this.commentId = commentId; return this; } @Override - public ParentStep content(String content) { + public PostStep content(String content) { Objects.requireNonNull(content); this.content = content; return this; } @Override - public BuildStep parent(CompositePKParent parent) { - Objects.requireNonNull(parent); - this.parent = new LoadedModelReferenceImpl<>(parent); + public BuildStep post(Post post) { + Objects.requireNonNull(post); + this.post = new LoadedModelReferenceImpl<>(post); return this; } @@ -1379,16 +1347,16 @@ public final class ImplicitChild implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String childId, String content, ModelReference parent) { - super(id, childId, content, parent); - Objects.requireNonNull(childId); + private CopyOfBuilder(String id, String commentId, String content, ModelReference post) { + super(id, commentId, content, post); + Objects.requireNonNull(commentId); Objects.requireNonNull(content); - Objects.requireNonNull(parent); + Objects.requireNonNull(post); } @Override - public CopyOfBuilder childId(String childId) { - return (CopyOfBuilder) super.childId(childId); + public CopyOfBuilder commentId(String commentId) { + return (CopyOfBuilder) super.commentId(commentId); } @Override @@ -1397,50 +1365,83 @@ public final class ImplicitChild implements Model { } @Override - public CopyOfBuilder parent(CompositePKParent parent) { - return (CopyOfBuilder) super.parent(parent); + public CopyOfBuilder post(Post post) { + return (CopyOfBuilder) super.post(post); } } } - -/** This is an auto generated class representing the StrangeExplicitChild type in your schema. */ +" +`; + +exports[`AppSyncModelVisitor API only should generate for CompositePKParent and (CompositePK, Implicit, StrangeExplicit, ChildSansBelongsTo) Child models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.ModelList; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the CompositePKParent type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"StrangeExplicitChildren\\", hasLazySupport = true) -@Index(name = \\"undefined\\", fields = {\\"strangeId\\",\\"content\\"}) -@Index(name = \\"byCompositePKParentX\\", fields = {\\"strangeParentId\\",\\"strangeParentTitle\\"}) -public final class StrangeExplicitChild implements Model { - public static final StrangeExplicitChildPath rootPath = new StrangeExplicitChildPath(\\"root\\", false, null); - public static final QueryField ID = field(\\"StrangeExplicitChild\\", \\"id\\"); - public static final QueryField STRANGE_ID = field(\\"StrangeExplicitChild\\", \\"strangeId\\"); - public static final QueryField CONTENT = field(\\"StrangeExplicitChild\\", \\"content\\"); - public static final QueryField PARENT = field(\\"StrangeExplicitChild\\", \\"strangeParentId\\"); - public static final QueryField STRANGE_PARENT_TITLE = field(\\"StrangeExplicitChild\\", \\"strangeParentTitle\\"); +@ModelConfig(pluralName = \\"CompositePKParents\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"customId\\",\\"content\\"}) +public final class CompositePKParent implements Model { + public static final CompositePKParentPath rootPath = new CompositePKParentPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"CompositePKParent\\", \\"id\\"); + public static final QueryField CUSTOM_ID = field(\\"CompositePKParent\\", \\"customId\\"); + public static final QueryField CONTENT = field(\\"CompositePKParent\\", \\"content\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String strangeId; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String customId; private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"strangeParentId\\", type = CompositePKParent.class) ModelReference parent; - private final @ModelField(targetType=\\"String\\") String strangeParentTitle; + private final @ModelField(targetType=\\"CompositePKChild\\") @HasMany(associatedWith = \\"parent\\", type = CompositePKChild.class) ModelList children = null; + private final @ModelField(targetType=\\"ImplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = ImplicitChild.class) ModelList implicitChildren = null; + private final @ModelField(targetType=\\"StrangeExplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = StrangeExplicitChild.class) ModelList strangeChildren = null; + private final @ModelField(targetType=\\"ChildSansBelongsTo\\") @HasMany(associatedWith = \\"compositePKParentChildrenSansBelongsToId\\", type = ChildSansBelongsTo.class) ModelList childrenSansBelongsTo = null; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; public String getId() { return id; } - public String getStrangeId() { - return strangeId; + public String getCustomId() { + return customId; } public String getContent() { return content; } - public ModelReference getParent() { - return parent; + public ModelList getChildren() { + return children; } - public String getStrangeParentTitle() { - return strangeParentTitle; + public ModelList getImplicitChildren() { + return implicitChildren; + } + + public ModelList getStrangeChildren() { + return strangeChildren; + } + + public ModelList getChildrenSansBelongsTo() { + return childrenSansBelongsTo; } public Temporal.DateTime getCreatedAt() { @@ -1451,12 +1452,10 @@ public final class StrangeExplicitChild implements Model { return updatedAt; } - private StrangeExplicitChild(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { + private CompositePKParent(String id, String customId, String content) { this.id = id; - this.strangeId = strangeId; + this.customId = customId; this.content = content; - this.parent = parent; - this.strangeParentTitle = strangeParentTitle; } @Override @@ -1466,14 +1465,12 @@ public final class StrangeExplicitChild implements Model { } else if(obj == null || getClass() != obj.getClass()) { return false; } else { - StrangeExplicitChild strangeExplicitChild = (StrangeExplicitChild) obj; - return ObjectsCompat.equals(getId(), strangeExplicitChild.getId()) && - ObjectsCompat.equals(getStrangeId(), strangeExplicitChild.getStrangeId()) && - ObjectsCompat.equals(getContent(), strangeExplicitChild.getContent()) && - ObjectsCompat.equals(getParent(), strangeExplicitChild.getParent()) && - ObjectsCompat.equals(getStrangeParentTitle(), strangeExplicitChild.getStrangeParentTitle()) && - ObjectsCompat.equals(getCreatedAt(), strangeExplicitChild.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), strangeExplicitChild.getUpdatedAt()); + CompositePKParent compositePkParent = (CompositePKParent) obj; + return ObjectsCompat.equals(getId(), compositePkParent.getId()) && + ObjectsCompat.equals(getCustomId(), compositePkParent.getCustomId()) && + ObjectsCompat.equals(getContent(), compositePkParent.getContent()) && + ObjectsCompat.equals(getCreatedAt(), compositePkParent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), compositePkParent.getUpdatedAt()); } } @@ -1481,10 +1478,8 @@ public final class StrangeExplicitChild implements Model { public int hashCode() { return new StringBuilder() .append(getId()) - .append(getStrangeId()) + .append(getCustomId()) .append(getContent()) - .append(getParent()) - .append(getStrangeParentTitle()) .append(getCreatedAt()) .append(getUpdatedAt()) .toString() @@ -1494,19 +1489,17 @@ public final class StrangeExplicitChild implements Model { @Override public String toString() { return new StringBuilder() - .append(\\"StrangeExplicitChild {\\") + .append(\\"CompositePKParent {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"strangeId=\\" + String.valueOf(getStrangeId()) + \\", \\") + .append(\\"customId=\\" + String.valueOf(getCustomId()) + \\", \\") .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") - .append(\\"strangeParentTitle=\\" + String.valueOf(getStrangeParentTitle()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) .append(\\"}\\") .toString(); } - public static StrangeIdStep builder() { + public static CustomIdStep builder() { return new Builder(); } @@ -1518,102 +1511,73 @@ public final class StrangeExplicitChild implements Model { * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated */ - public static StrangeExplicitChild justId(String id) { - return new StrangeExplicitChild( + public static CompositePKParent justId(String id) { + return new CompositePKParent( id, null, - null, - null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - strangeId, - content, - parent, - strangeParentTitle); + customId, + content); } - public interface StrangeIdStep { - ContentStep strangeId(String strangeId); + public interface CustomIdStep { + ContentStep customId(String customId); } public interface ContentStep { - ParentStep content(String content); - } - - - public interface ParentStep { - BuildStep parent(CompositePKParent parent); + BuildStep content(String content); } public interface BuildStep { - StrangeExplicitChild build(); + CompositePKParent build(); BuildStep id(String id); - BuildStep strangeParentTitle(String strangeParentTitle); } - public static class Builder implements StrangeIdStep, ContentStep, ParentStep, BuildStep { + public static class Builder implements CustomIdStep, ContentStep, BuildStep { private String id; - private String strangeId; + private String customId; private String content; - private ModelReference parent; - private String strangeParentTitle; public Builder() { } - private Builder(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { + private Builder(String id, String customId, String content) { this.id = id; - this.strangeId = strangeId; + this.customId = customId; this.content = content; - this.parent = parent; - this.strangeParentTitle = strangeParentTitle; } @Override - public StrangeExplicitChild build() { + public CompositePKParent build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); - return new StrangeExplicitChild( + return new CompositePKParent( id, - strangeId, - content, - parent, - strangeParentTitle); + customId, + content); } @Override - public ContentStep strangeId(String strangeId) { - Objects.requireNonNull(strangeId); - this.strangeId = strangeId; + public ContentStep customId(String customId) { + Objects.requireNonNull(customId); + this.customId = customId; return this; } @Override - public ParentStep content(String content) { + public BuildStep content(String content) { Objects.requireNonNull(content); this.content = content; return this; } - @Override - public BuildStep parent(CompositePKParent parent) { - Objects.requireNonNull(parent); - this.parent = new LoadedModelReferenceImpl<>(parent); - return this; - } - - @Override - public BuildStep strangeParentTitle(String strangeParentTitle) { - this.strangeParentTitle = strangeParentTitle; - return this; - } - /** * @param id id * @return Current Builder instance, for fluent method chaining @@ -1626,57 +1590,44 @@ public final class StrangeExplicitChild implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { - super(id, strangeId, content, parent, strangeParentTitle); - Objects.requireNonNull(strangeId); + private CopyOfBuilder(String id, String customId, String content) { + super(id, customId, content); + Objects.requireNonNull(customId); Objects.requireNonNull(content); - Objects.requireNonNull(parent); } @Override - public CopyOfBuilder strangeId(String strangeId) { - return (CopyOfBuilder) super.strangeId(strangeId); + public CopyOfBuilder customId(String customId) { + return (CopyOfBuilder) super.customId(customId); } @Override public CopyOfBuilder content(String content) { return (CopyOfBuilder) super.content(content); } - - @Override - public CopyOfBuilder parent(CompositePKParent parent) { - return (CopyOfBuilder) super.parent(parent); - } - - @Override - public CopyOfBuilder strangeParentTitle(String strangeParentTitle) { - return (CopyOfBuilder) super.strangeParentTitle(strangeParentTitle); - } } } -/** This is an auto generated class representing the ChildSansBelongsTo type in your schema. */ +/** This is an auto generated class representing the CompositePKChild type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"ChildSansBelongsTos\\", hasLazySupport = true) +@ModelConfig(pluralName = \\"CompositePKChildren\\", hasLazySupport = true) @Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) -@Index(name = \\"byParent\\", fields = {\\"compositePKParentChildrenSansBelongsToCustomId\\",\\"compositePKParentChildrenSansBelongsToContent\\"}) -public final class ChildSansBelongsTo implements Model { - public static final ChildSansBelongsToPath rootPath = new ChildSansBelongsToPath(\\"root\\", false, null); - public static final QueryField ID = field(\\"ChildSansBelongsTo\\", \\"id\\"); - public static final QueryField CHILD_ID = field(\\"ChildSansBelongsTo\\", \\"childId\\"); - public static final QueryField CONTENT = field(\\"ChildSansBelongsTo\\", \\"content\\"); - public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CUSTOM_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToCustomId\\"); - public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CONTENT = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToContent\\"); - public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToId\\"); +@Index(name = \\"byParent\\", fields = {\\"parentId\\",\\"parentTitle\\"}) +public final class CompositePKChild implements Model { + public static final CompositePKChildPath rootPath = new CompositePKChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"CompositePKChild\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"CompositePKChild\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"CompositePKChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"CompositePKChild\\", \\"parentId\\"); + public static final QueryField PARENT_TITLE = field(\\"CompositePKChild\\", \\"parentTitle\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String compositePKParentChildrenSansBelongsToCustomId; - private final @ModelField(targetType=\\"String\\") String compositePKParentChildrenSansBelongsToContent; + private final @ModelField(targetType=\\"CompositePKParent\\") @BelongsTo(targetName = \\"parentId\\", type = CompositePKParent.class) ModelReference parent; + private final @ModelField(targetType=\\"String\\") String parentTitle; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - private final @ModelField(targetType=\\"ID\\") String compositePKParentChildrenSansBelongsToId; public String getId() { return id; } @@ -1689,12 +1640,12 @@ public final class ChildSansBelongsTo implements Model { return content; } - public String getCompositePkParentChildrenSansBelongsToCustomId() { - return compositePKParentChildrenSansBelongsToCustomId; + public ModelReference getParent() { + return parent; } - public String getCompositePkParentChildrenSansBelongsToContent() { - return compositePKParentChildrenSansBelongsToContent; + public String getParentTitle() { + return parentTitle; } public Temporal.DateTime getCreatedAt() { @@ -1705,17 +1656,12 @@ public final class ChildSansBelongsTo implements Model { return updatedAt; } - public String getCompositePkParentChildrenSansBelongsToId() { - return compositePKParentChildrenSansBelongsToId; - } - - private ChildSansBelongsTo(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { + private CompositePKChild(String id, String childId, String content, ModelReference parent, String parentTitle) { this.id = id; this.childId = childId; this.content = content; - this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; - this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; - this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; + this.parent = parent; + this.parentTitle = parentTitle; } @Override @@ -1725,29 +1671,27 @@ public final class ChildSansBelongsTo implements Model { } else if(obj == null || getClass() != obj.getClass()) { return false; } else { - ChildSansBelongsTo childSansBelongsTo = (ChildSansBelongsTo) obj; - return ObjectsCompat.equals(getId(), childSansBelongsTo.getId()) && - ObjectsCompat.equals(getChildId(), childSansBelongsTo.getChildId()) && - ObjectsCompat.equals(getContent(), childSansBelongsTo.getContent()) && - ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToCustomId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToCustomId()) && - ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToContent(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToContent()) && - ObjectsCompat.equals(getCreatedAt(), childSansBelongsTo.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), childSansBelongsTo.getUpdatedAt()) && - ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToId()); - } - } - - @Override - public int hashCode() { - return new StringBuilder() + CompositePKChild compositePkChild = (CompositePKChild) obj; + return ObjectsCompat.equals(getId(), compositePkChild.getId()) && + ObjectsCompat.equals(getChildId(), compositePkChild.getChildId()) && + ObjectsCompat.equals(getContent(), compositePkChild.getContent()) && + ObjectsCompat.equals(getParent(), compositePkChild.getParent()) && + ObjectsCompat.equals(getParentTitle(), compositePkChild.getParentTitle()) && + ObjectsCompat.equals(getCreatedAt(), compositePkChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), compositePkChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() .append(getId()) .append(getChildId()) .append(getContent()) - .append(getCompositePkParentChildrenSansBelongsToCustomId()) - .append(getCompositePkParentChildrenSansBelongsToContent()) + .append(getParent()) + .append(getParentTitle()) .append(getCreatedAt()) .append(getUpdatedAt()) - .append(getCompositePkParentChildrenSansBelongsToId()) .toString() .hashCode(); } @@ -1755,15 +1699,14 @@ public final class ChildSansBelongsTo implements Model { @Override public String toString() { return new StringBuilder() - .append(\\"ChildSansBelongsTo {\\") + .append(\\"CompositePKChild {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"compositePKParentChildrenSansBelongsToCustomId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToCustomId()) + \\", \\") - .append(\\"compositePKParentChildrenSansBelongsToContent=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"parentTitle=\\" + String.valueOf(getParentTitle()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") - .append(\\"compositePKParentChildrenSansBelongsToId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToId())) + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) .append(\\"}\\") .toString(); } @@ -1780,13 +1723,12 @@ public final class ChildSansBelongsTo implements Model { * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated */ - public static ChildSansBelongsTo justId(String id) { - return new ChildSansBelongsTo( + public static CompositePKChild justId(String id) { + return new CompositePKChild( id, null, null, null, - null, null ); } @@ -1795,9 +1737,8 @@ public final class ChildSansBelongsTo implements Model { return new CopyOfBuilder(id, childId, content, - compositePKParentChildrenSansBelongsToCustomId, - compositePKParentChildrenSansBelongsToContent, - compositePKParentChildrenSansBelongsToId); + parent, + parentTitle); } public interface ChildIdStep { ContentStep childId(String childId); @@ -1805,54 +1746,46 @@ public final class ChildSansBelongsTo implements Model { public interface ContentStep { - CompositePkParentChildrenSansBelongsToCustomIdStep content(String content); - } - - - public interface CompositePkParentChildrenSansBelongsToCustomIdStep { - BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId); + BuildStep content(String content); } public interface BuildStep { - ChildSansBelongsTo build(); + CompositePKChild build(); BuildStep id(String id); - BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent); - BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId); + BuildStep parent(CompositePKParent parent); + BuildStep parentTitle(String parentTitle); } - public static class Builder implements ChildIdStep, ContentStep, CompositePkParentChildrenSansBelongsToCustomIdStep, BuildStep { + public static class Builder implements ChildIdStep, ContentStep, BuildStep { private String id; private String childId; private String content; - private String compositePKParentChildrenSansBelongsToCustomId; - private String compositePKParentChildrenSansBelongsToContent; - private String compositePKParentChildrenSansBelongsToId; + private ModelReference parent; + private String parentTitle; public Builder() { } - private Builder(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { + private Builder(String id, String childId, String content, ModelReference parent, String parentTitle) { this.id = id; this.childId = childId; this.content = content; - this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; - this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; - this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; + this.parent = parent; + this.parentTitle = parentTitle; } @Override - public ChildSansBelongsTo build() { + public CompositePKChild build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); - return new ChildSansBelongsTo( + return new CompositePKChild( id, childId, content, - compositePKParentChildrenSansBelongsToCustomId, - compositePKParentChildrenSansBelongsToContent, - compositePKParentChildrenSansBelongsToId); + parent, + parentTitle); } @Override @@ -1863,28 +1796,21 @@ public final class ChildSansBelongsTo implements Model { } @Override - public CompositePkParentChildrenSansBelongsToCustomIdStep content(String content) { + public BuildStep content(String content) { Objects.requireNonNull(content); this.content = content; return this; } @Override - public BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { - Objects.requireNonNull(compositePkParentChildrenSansBelongsToCustomId); - this.compositePKParentChildrenSansBelongsToCustomId = compositePkParentChildrenSansBelongsToCustomId; - return this; - } - - @Override - public BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { - this.compositePKParentChildrenSansBelongsToContent = compositePkParentChildrenSansBelongsToContent; + public BuildStep parent(CompositePKParent parent) { + this.parent = new LoadedModelReferenceImpl<>(parent); return this; } @Override - public BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { - this.compositePKParentChildrenSansBelongsToId = compositePkParentChildrenSansBelongsToId; + public BuildStep parentTitle(String parentTitle) { + this.parentTitle = parentTitle; return this; } @@ -1900,11 +1826,10 @@ public final class ChildSansBelongsTo implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String childId, String content, String compositePkParentChildrenSansBelongsToCustomId, String compositePkParentChildrenSansBelongsToContent, String compositePkParentChildrenSansBelongsToId) { - super(id, childId, content, compositePKParentChildrenSansBelongsToCustomId, compositePKParentChildrenSansBelongsToContent, compositePKParentChildrenSansBelongsToId); + private CopyOfBuilder(String id, String childId, String content, ModelReference parent, String parentTitle) { + super(id, childId, content, parent, parentTitle); Objects.requireNonNull(childId); Objects.requireNonNull(content); - Objects.requireNonNull(compositePKParentChildrenSansBelongsToCustomId); } @Override @@ -1918,68 +1843,48 @@ public final class ChildSansBelongsTo implements Model { } @Override - public CopyOfBuilder compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { - return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToCustomId(compositePkParentChildrenSansBelongsToCustomId); - } - - @Override - public CopyOfBuilder compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { - return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToContent(compositePkParentChildrenSansBelongsToContent); + public CopyOfBuilder parent(CompositePKParent parent) { + return (CopyOfBuilder) super.parent(parent); } @Override - public CopyOfBuilder compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { - return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToId(compositePkParentChildrenSansBelongsToId); + public CopyOfBuilder parentTitle(String parentTitle) { + return (CopyOfBuilder) super.parentTitle(parentTitle); } } } -" -`; - -exports[`AppSyncModelVisitor DataStore Enabled Should generate for DefaultPKParent DefaultPKChild models 1`] = ` -"package com.amplifyframework.datastore.generated.model; - -import com.amplifyframework.core.model.annotations.HasMany; -import com.amplifyframework.core.model.temporal.Temporal; -import com.amplifyframework.core.model.annotations.BelongsTo; - -import java.util.List; -import java.util.UUID; -import java.util.Objects; - -import androidx.core.util.ObjectsCompat; - -import com.amplifyframework.core.model.Model; -import com.amplifyframework.core.model.annotations.Index; -import com.amplifyframework.core.model.annotations.ModelConfig; -import com.amplifyframework.core.model.annotations.ModelField; -import com.amplifyframework.core.model.query.predicate.QueryField; - -import static com.amplifyframework.core.model.query.predicate.QueryField.field; -/** This is an auto generated class representing the DefaultPKParent type in your schema. */ +/** This is an auto generated class representing the ImplicitChild type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"DefaultPKParents\\") -@Index(name = \\"undefined\\", fields = {\\"id\\"}) -public final class DefaultPKParent implements Model { - public static final QueryField ID = field(\\"DefaultPKParent\\", \\"id\\"); - public static final QueryField CONTENT = field(\\"DefaultPKParent\\", \\"content\\"); +@ModelConfig(pluralName = \\"ImplicitChildren\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) +public final class ImplicitChild implements Model { + public static final ImplicitChildPath rootPath = new ImplicitChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"ImplicitChild\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"ImplicitChild\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"ImplicitChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"ImplicitChild\\", \\"compositePKParentImplicitChildrenId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"String\\") String content; - private final @ModelField(targetType=\\"DefaultPKChild\\") @HasMany(associatedWith = \\"parent\\", type = DefaultPKChild.class) List children = null; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"compositePKParentImplicitChildrenId\\", type = CompositePKParent.class) ModelReference parent; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; public String getId() { return id; } + public String getChildId() { + return childId; + } + public String getContent() { return content; } - public List getChildren() { - return children; + public ModelReference getParent() { + return parent; } public Temporal.DateTime getCreatedAt() { @@ -1990,9 +1895,11 @@ public final class DefaultPKParent implements Model { return updatedAt; } - private DefaultPKParent(String id, String content) { + private ImplicitChild(String id, String childId, String content, ModelReference parent) { this.id = id; + this.childId = childId; this.content = content; + this.parent = parent; } @Override @@ -2002,11 +1909,13 @@ public final class DefaultPKParent implements Model { } else if(obj == null || getClass() != obj.getClass()) { return false; } else { - DefaultPKParent defaultPkParent = (DefaultPKParent) obj; - return ObjectsCompat.equals(getId(), defaultPkParent.getId()) && - ObjectsCompat.equals(getContent(), defaultPkParent.getContent()) && - ObjectsCompat.equals(getCreatedAt(), defaultPkParent.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), defaultPkParent.getUpdatedAt()); + ImplicitChild implicitChild = (ImplicitChild) obj; + return ObjectsCompat.equals(getId(), implicitChild.getId()) && + ObjectsCompat.equals(getChildId(), implicitChild.getChildId()) && + ObjectsCompat.equals(getContent(), implicitChild.getContent()) && + ObjectsCompat.equals(getParent(), implicitChild.getParent()) && + ObjectsCompat.equals(getCreatedAt(), implicitChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), implicitChild.getUpdatedAt()); } } @@ -2014,7 +1923,9 @@ public final class DefaultPKParent implements Model { public int hashCode() { return new StringBuilder() .append(getId()) + .append(getChildId()) .append(getContent()) + .append(getParent()) .append(getCreatedAt()) .append(getUpdatedAt()) .toString() @@ -2024,16 +1935,18 @@ public final class DefaultPKParent implements Model { @Override public String toString() { return new StringBuilder() - .append(\\"DefaultPKParent {\\") + .append(\\"ImplicitChild {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) .append(\\"}\\") .toString(); } - public static BuildStep builder() { + public static ChildIdStep builder() { return new Builder(); } @@ -2045,51 +1958,90 @@ public final class DefaultPKParent implements Model { * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated */ - public static DefaultPKParent justId(String id) { - return new DefaultPKParent( + public static ImplicitChild justId(String id) { + return new ImplicitChild( id, + null, + null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - content); + childId, + content, + parent); + } + public interface ChildIdStep { + ContentStep childId(String childId); + } + + + public interface ContentStep { + ParentStep content(String content); + } + + + public interface ParentStep { + BuildStep parent(CompositePKParent parent); } + + public interface BuildStep { - DefaultPKParent build(); + ImplicitChild build(); BuildStep id(String id); - BuildStep content(String content); } - public static class Builder implements BuildStep { + public static class Builder implements ChildIdStep, ContentStep, ParentStep, BuildStep { private String id; + private String childId; private String content; + private ModelReference parent; public Builder() { } - private Builder(String id, String content) { + private Builder(String id, String childId, String content, ModelReference parent) { this.id = id; + this.childId = childId; this.content = content; + this.parent = parent; } @Override - public DefaultPKParent build() { + public ImplicitChild build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); - return new DefaultPKParent( + return new ImplicitChild( id, - content); + childId, + content, + parent); } @Override - public BuildStep content(String content) { + public ContentStep childId(String childId) { + Objects.requireNonNull(childId); + this.childId = childId; + return this; + } + + @Override + public ParentStep content(String content) { + Objects.requireNonNull(content); this.content = content; return this; } + @Override + public BuildStep parent(CompositePKParent parent) { + Objects.requireNonNull(parent); + this.parent = new LoadedModelReferenceImpl<>(parent); + return this; + } + /** * @param id id * @return Current Builder instance, for fluent method chaining @@ -2102,44 +2054,70 @@ public final class DefaultPKParent implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String content) { - super(id, content); - + private CopyOfBuilder(String id, String childId, String content, ModelReference parent) { + super(id, childId, content, parent); + Objects.requireNonNull(childId); + Objects.requireNonNull(content); + Objects.requireNonNull(parent); } @Override - public CopyOfBuilder content(String content) { - return (CopyOfBuilder) super.content(content); - } + public CopyOfBuilder childId(String childId) { + return (CopyOfBuilder) super.childId(childId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(CompositePKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } } } -/** This is an auto generated class representing the DefaultPKChild type in your schema. */ +/** This is an auto generated class representing the StrangeExplicitChild type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"DefaultPKChildren\\") -@Index(name = \\"undefined\\", fields = {\\"id\\"}) -public final class DefaultPKChild implements Model { - public static final QueryField ID = field(\\"DefaultPKChild\\", \\"id\\"); - public static final QueryField CONTENT = field(\\"DefaultPKChild\\", \\"content\\"); - public static final QueryField PARENT = field(\\"DefaultPKChild\\", \\"defaultPKParentChildrenId\\"); +@ModelConfig(pluralName = \\"StrangeExplicitChildren\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"strangeId\\",\\"content\\"}) +@Index(name = \\"byCompositePKParentX\\", fields = {\\"strangeParentId\\",\\"strangeParentTitle\\"}) +public final class StrangeExplicitChild implements Model { + public static final StrangeExplicitChildPath rootPath = new StrangeExplicitChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"StrangeExplicitChild\\", \\"id\\"); + public static final QueryField STRANGE_ID = field(\\"StrangeExplicitChild\\", \\"strangeId\\"); + public static final QueryField CONTENT = field(\\"StrangeExplicitChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"StrangeExplicitChild\\", \\"strangeParentId\\"); + public static final QueryField STRANGE_PARENT_TITLE = field(\\"StrangeExplicitChild\\", \\"strangeParentTitle\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"String\\") String content; - private final @ModelField(targetType=\\"DefaultPKParent\\") @BelongsTo(targetName = \\"defaultPKParentChildrenId\\", type = DefaultPKParent.class) DefaultPKParent parent; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String strangeId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"strangeParentId\\", type = CompositePKParent.class) ModelReference parent; + private final @ModelField(targetType=\\"String\\") String strangeParentTitle; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; public String getId() { return id; } + public String getStrangeId() { + return strangeId; + } + public String getContent() { return content; } - public DefaultPKParent getParent() { + public ModelReference getParent() { return parent; } + public String getStrangeParentTitle() { + return strangeParentTitle; + } + public Temporal.DateTime getCreatedAt() { return createdAt; } @@ -2148,10 +2126,12 @@ public final class DefaultPKChild implements Model { return updatedAt; } - private DefaultPKChild(String id, String content, DefaultPKParent parent) { + private StrangeExplicitChild(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { this.id = id; + this.strangeId = strangeId; this.content = content; this.parent = parent; + this.strangeParentTitle = strangeParentTitle; } @Override @@ -2161,12 +2141,14 @@ public final class DefaultPKChild implements Model { } else if(obj == null || getClass() != obj.getClass()) { return false; } else { - DefaultPKChild defaultPkChild = (DefaultPKChild) obj; - return ObjectsCompat.equals(getId(), defaultPkChild.getId()) && - ObjectsCompat.equals(getContent(), defaultPkChild.getContent()) && - ObjectsCompat.equals(getParent(), defaultPkChild.getParent()) && - ObjectsCompat.equals(getCreatedAt(), defaultPkChild.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), defaultPkChild.getUpdatedAt()); + StrangeExplicitChild strangeExplicitChild = (StrangeExplicitChild) obj; + return ObjectsCompat.equals(getId(), strangeExplicitChild.getId()) && + ObjectsCompat.equals(getStrangeId(), strangeExplicitChild.getStrangeId()) && + ObjectsCompat.equals(getContent(), strangeExplicitChild.getContent()) && + ObjectsCompat.equals(getParent(), strangeExplicitChild.getParent()) && + ObjectsCompat.equals(getStrangeParentTitle(), strangeExplicitChild.getStrangeParentTitle()) && + ObjectsCompat.equals(getCreatedAt(), strangeExplicitChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), strangeExplicitChild.getUpdatedAt()); } } @@ -2174,8 +2156,10 @@ public final class DefaultPKChild implements Model { public int hashCode() { return new StringBuilder() .append(getId()) + .append(getStrangeId()) .append(getContent()) .append(getParent()) + .append(getStrangeParentTitle()) .append(getCreatedAt()) .append(getUpdatedAt()) .toString() @@ -2185,17 +2169,19 @@ public final class DefaultPKChild implements Model { @Override public String toString() { return new StringBuilder() - .append(\\"DefaultPKChild {\\") + .append(\\"StrangeExplicitChild {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"strangeId=\\" + String.valueOf(getStrangeId()) + \\", \\") .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"strangeParentTitle=\\" + String.valueOf(getStrangeParentTitle()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) .append(\\"}\\") .toString(); } - public static BuildStep builder() { + public static StrangeIdStep builder() { return new Builder(); } @@ -2207,60 +2193,99 @@ public final class DefaultPKChild implements Model { * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated */ - public static DefaultPKChild justId(String id) { - return new DefaultPKChild( + public static StrangeExplicitChild justId(String id) { + return new StrangeExplicitChild( id, null, + null, + null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, + strangeId, content, - parent); + parent, + strangeParentTitle); + } + public interface StrangeIdStep { + ContentStep strangeId(String strangeId); + } + + + public interface ContentStep { + ParentStep content(String content); + } + + + public interface ParentStep { + BuildStep parent(CompositePKParent parent); } + + public interface BuildStep { - DefaultPKChild build(); + StrangeExplicitChild build(); BuildStep id(String id); - BuildStep content(String content); - BuildStep parent(DefaultPKParent parent); + BuildStep strangeParentTitle(String strangeParentTitle); } - public static class Builder implements BuildStep { + public static class Builder implements StrangeIdStep, ContentStep, ParentStep, BuildStep { private String id; + private String strangeId; private String content; - private DefaultPKParent parent; + private ModelReference parent; + private String strangeParentTitle; public Builder() { } - private Builder(String id, String content, DefaultPKParent parent) { + private Builder(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { this.id = id; + this.strangeId = strangeId; this.content = content; this.parent = parent; + this.strangeParentTitle = strangeParentTitle; } @Override - public DefaultPKChild build() { + public StrangeExplicitChild build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); - return new DefaultPKChild( + return new StrangeExplicitChild( id, + strangeId, content, - parent); + parent, + strangeParentTitle); } @Override - public BuildStep content(String content) { + public ContentStep strangeId(String strangeId) { + Objects.requireNonNull(strangeId); + this.strangeId = strangeId; + return this; + } + + @Override + public ParentStep content(String content) { + Objects.requireNonNull(content); this.content = content; return this; } @Override - public BuildStep parent(DefaultPKParent parent) { - this.parent = parent; + public BuildStep parent(CompositePKParent parent) { + Objects.requireNonNull(parent); + this.parent = new LoadedModelReferenceImpl<>(parent); + return this; + } + + @Override + public BuildStep strangeParentTitle(String strangeParentTitle) { + this.strangeParentTitle = strangeParentTitle; return this; } @@ -2276,9 +2301,16 @@ public final class DefaultPKChild implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String content, DefaultPKParent parent) { - super(id, content, parent); - + private CopyOfBuilder(String id, String strangeId, String content, ModelReference parent, String strangeParentTitle) { + super(id, strangeId, content, parent, strangeParentTitle); + Objects.requireNonNull(strangeId); + Objects.requireNonNull(content); + Objects.requireNonNull(parent); + } + + @Override + public CopyOfBuilder strangeId(String strangeId) { + return (CopyOfBuilder) super.strangeId(strangeId); } @Override @@ -2287,53 +2319,57 @@ public final class DefaultPKChild implements Model { } @Override - public CopyOfBuilder parent(DefaultPKParent parent) { + public CopyOfBuilder parent(CompositePKParent parent) { return (CopyOfBuilder) super.parent(parent); } + + @Override + public CopyOfBuilder strangeParentTitle(String strangeParentTitle) { + return (CopyOfBuilder) super.strangeParentTitle(strangeParentTitle); + } } } -" -`; - -exports[`AppSyncModelVisitor DataStore Enabled Should generate for HasOneParent HasOneChild models 1`] = ` -"package com.amplifyframework.datastore.generated.model; - -import com.amplifyframework.core.model.annotations.HasOne; -import com.amplifyframework.core.model.temporal.Temporal; - -import java.util.List; -import java.util.UUID; -import java.util.Objects; - -import androidx.core.util.ObjectsCompat; -import com.amplifyframework.core.model.Model; -import com.amplifyframework.core.model.annotations.Index; -import com.amplifyframework.core.model.annotations.ModelConfig; -import com.amplifyframework.core.model.annotations.ModelField; -import com.amplifyframework.core.model.query.predicate.QueryField; - -import static com.amplifyframework.core.model.query.predicate.QueryField.field; - -/** This is an auto generated class representing the HasOneParent type in your schema. */ +/** This is an auto generated class representing the ChildSansBelongsTo type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"HasOneParents\\") -@Index(name = \\"undefined\\", fields = {\\"id\\"}) -public final class HasOneParent implements Model { - public static final QueryField ID = field(\\"HasOneParent\\", \\"id\\"); - public static final QueryField HAS_ONE_PARENT_CHILD_ID = field(\\"HasOneParent\\", \\"hasOneParentChildId\\"); +@ModelConfig(pluralName = \\"ChildSansBelongsTos\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) +@Index(name = \\"byParent\\", fields = {\\"compositePKParentChildrenSansBelongsToCustomId\\",\\"compositePKParentChildrenSansBelongsToContent\\"}) +public final class ChildSansBelongsTo implements Model { + public static final ChildSansBelongsToPath rootPath = new ChildSansBelongsToPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"ChildSansBelongsTo\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"ChildSansBelongsTo\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"ChildSansBelongsTo\\", \\"content\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CUSTOM_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToCustomId\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CONTENT = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToContent\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"HasOneChild\\") @HasOne(associatedWith = \\"id\\", type = HasOneChild.class) HasOneChild child = null; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String compositePKParentChildrenSansBelongsToCustomId; + private final @ModelField(targetType=\\"String\\") String compositePKParentChildrenSansBelongsToContent; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - private final @ModelField(targetType=\\"ID\\") String hasOneParentChildId; + private final @ModelField(targetType=\\"ID\\") String compositePKParentChildrenSansBelongsToId; public String getId() { return id; } - public HasOneChild getChild() { - return child; + public String getChildId() { + return childId; + } + + public String getContent() { + return content; + } + + public String getCompositePkParentChildrenSansBelongsToCustomId() { + return compositePKParentChildrenSansBelongsToCustomId; + } + + public String getCompositePkParentChildrenSansBelongsToContent() { + return compositePKParentChildrenSansBelongsToContent; } public Temporal.DateTime getCreatedAt() { @@ -2344,13 +2380,17 @@ public final class HasOneParent implements Model { return updatedAt; } - public String getHasOneParentChildId() { - return hasOneParentChildId; + public String getCompositePkParentChildrenSansBelongsToId() { + return compositePKParentChildrenSansBelongsToId; } - private HasOneParent(String id, String hasOneParentChildId) { + private ChildSansBelongsTo(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { this.id = id; - this.hasOneParentChildId = hasOneParentChildId; + this.childId = childId; + this.content = content; + this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; + this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; + this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; } @Override @@ -2360,11 +2400,15 @@ public final class HasOneParent implements Model { } else if(obj == null || getClass() != obj.getClass()) { return false; } else { - HasOneParent hasOneParent = (HasOneParent) obj; - return ObjectsCompat.equals(getId(), hasOneParent.getId()) && - ObjectsCompat.equals(getCreatedAt(), hasOneParent.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), hasOneParent.getUpdatedAt()) && - ObjectsCompat.equals(getHasOneParentChildId(), hasOneParent.getHasOneParentChildId()); + ChildSansBelongsTo childSansBelongsTo = (ChildSansBelongsTo) obj; + return ObjectsCompat.equals(getId(), childSansBelongsTo.getId()) && + ObjectsCompat.equals(getChildId(), childSansBelongsTo.getChildId()) && + ObjectsCompat.equals(getContent(), childSansBelongsTo.getContent()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToCustomId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToCustomId()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToContent(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToContent()) && + ObjectsCompat.equals(getCreatedAt(), childSansBelongsTo.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), childSansBelongsTo.getUpdatedAt()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToId()); } } @@ -2372,9 +2416,3331 @@ public final class HasOneParent implements Model { public int hashCode() { return new StringBuilder() .append(getId()) + .append(getChildId()) + .append(getContent()) + .append(getCompositePkParentChildrenSansBelongsToCustomId()) + .append(getCompositePkParentChildrenSansBelongsToContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .append(getCompositePkParentChildrenSansBelongsToId()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"ChildSansBelongsTo {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToCustomId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToCustomId()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToContent=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToId())) + .append(\\"}\\") + .toString(); + } + + public static ChildIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static ChildSansBelongsTo justId(String id) { + return new ChildSansBelongsTo( + id, + null, + null, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + childId, + content, + compositePKParentChildrenSansBelongsToCustomId, + compositePKParentChildrenSansBelongsToContent, + compositePKParentChildrenSansBelongsToId); + } + public interface ChildIdStep { + ContentStep childId(String childId); + } + + + public interface ContentStep { + CompositePkParentChildrenSansBelongsToCustomIdStep content(String content); + } + + + public interface CompositePkParentChildrenSansBelongsToCustomIdStep { + BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId); + } + + + public interface BuildStep { + ChildSansBelongsTo build(); + BuildStep id(String id); + BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent); + BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId); + } + + + public static class Builder implements ChildIdStep, ContentStep, CompositePkParentChildrenSansBelongsToCustomIdStep, BuildStep { + private String id; + private String childId; + private String content; + private String compositePKParentChildrenSansBelongsToCustomId; + private String compositePKParentChildrenSansBelongsToContent; + private String compositePKParentChildrenSansBelongsToId; + public Builder() { + + } + + private Builder(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { + this.id = id; + this.childId = childId; + this.content = content; + this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; + this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; + this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; + } + + @Override + public ChildSansBelongsTo build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new ChildSansBelongsTo( + id, + childId, + content, + compositePKParentChildrenSansBelongsToCustomId, + compositePKParentChildrenSansBelongsToContent, + compositePKParentChildrenSansBelongsToId); + } + + @Override + public ContentStep childId(String childId) { + Objects.requireNonNull(childId); + this.childId = childId; + return this; + } + + @Override + public CompositePkParentChildrenSansBelongsToCustomIdStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { + Objects.requireNonNull(compositePkParentChildrenSansBelongsToCustomId); + this.compositePKParentChildrenSansBelongsToCustomId = compositePkParentChildrenSansBelongsToCustomId; + return this; + } + + @Override + public BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { + this.compositePKParentChildrenSansBelongsToContent = compositePkParentChildrenSansBelongsToContent; + return this; + } + + @Override + public BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { + this.compositePKParentChildrenSansBelongsToId = compositePkParentChildrenSansBelongsToId; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String childId, String content, String compositePkParentChildrenSansBelongsToCustomId, String compositePkParentChildrenSansBelongsToContent, String compositePkParentChildrenSansBelongsToId) { + super(id, childId, content, compositePKParentChildrenSansBelongsToCustomId, compositePKParentChildrenSansBelongsToContent, compositePKParentChildrenSansBelongsToId); + Objects.requireNonNull(childId); + Objects.requireNonNull(content); + Objects.requireNonNull(compositePKParentChildrenSansBelongsToCustomId); + } + + @Override + public CopyOfBuilder childId(String childId) { + return (CopyOfBuilder) super.childId(childId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToCustomId(compositePkParentChildrenSansBelongsToCustomId); + } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToContent(compositePkParentChildrenSansBelongsToContent); + } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToId(compositePkParentChildrenSansBelongsToId); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor API only should generate for Parent, HasOneChild, HasManyChild models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasOne; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.ModelList; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.annotations.BelongsTo; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Parent type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Parents\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class Parent implements Model { + public static final ParentPath rootPath = new ParentPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"Parent\\", \\"id\\"); + public static final QueryField PARENT_CHILD_ID = field(\\"Parent\\", \\"parentChildId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"HasOneChild\\") @HasOne(associatedWith = \\"id\\", type = HasOneChild.class) ModelReference child = null; + private final @ModelField(targetType=\\"HasManyChild\\") @HasMany(associatedWith = \\"parent\\", type = HasManyChild.class) ModelList children = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + private final @ModelField(targetType=\\"ID\\") String parentChildId; + public String getId() { + return id; + } + + public ModelReference getChild() { + return child; + } + + public ModelList getChildren() { + return children; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + public String getParentChildId() { + return parentChildId; + } + + private Parent(String id, String parentChildId) { + this.id = id; + this.parentChildId = parentChildId; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Parent parent = (Parent) obj; + return ObjectsCompat.equals(getId(), parent.getId()) && + ObjectsCompat.equals(getCreatedAt(), parent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), parent.getUpdatedAt()) && + ObjectsCompat.equals(getParentChildId(), parent.getParentChildId()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .append(getParentChildId()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Parent {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") + .append(\\"parentChildId=\\" + String.valueOf(getParentChildId())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Parent justId(String id) { + return new Parent( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + parentChildId); + } + public interface BuildStep { + Parent build(); + BuildStep id(String id); + BuildStep parentChildId(String parentChildId); + } + + + public static class Builder implements BuildStep { + private String id; + private String parentChildId; + public Builder() { + + } + + private Builder(String id, String parentChildId) { + this.id = id; + this.parentChildId = parentChildId; + } + + @Override + public Parent build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Parent( + id, + parentChildId); + } + + @Override + public BuildStep parentChildId(String parentChildId) { + this.parentChildId = parentChildId; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String parentChildId) { + super(id, parentChildId); + + } + + @Override + public CopyOfBuilder parentChildId(String parentChildId) { + return (CopyOfBuilder) super.parentChildId(parentChildId); + } + } + +} + +/** This is an auto generated class representing the HasOneChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"HasOneChildren\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class HasOneChild implements Model { + public static final HasOneChildPath rootPath = new HasOneChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"HasOneChild\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"HasOneChild\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private HasOneChild(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + HasOneChild hasOneChild = (HasOneChild) obj; + return ObjectsCompat.equals(getId(), hasOneChild.getId()) && + ObjectsCompat.equals(getContent(), hasOneChild.getContent()) && + ObjectsCompat.equals(getCreatedAt(), hasOneChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), hasOneChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"HasOneChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static HasOneChild justId(String id) { + return new HasOneChild( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content); + } + public interface BuildStep { + HasOneChild build(); + BuildStep id(String id); + BuildStep content(String content); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + public Builder() { + + } + + private Builder(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public HasOneChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new HasOneChild( + id, + content); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content) { + super(id, content); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + +} + +/** This is an auto generated class representing the HasManyChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"HasManyChildren\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class HasManyChild implements Model { + public static final HasManyChildPath rootPath = new HasManyChildPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"HasManyChild\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"HasManyChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"HasManyChild\\", \\"parentChildrenId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"Parent\\") @BelongsTo(targetName = \\"parentChildrenId\\", type = Parent.class) ModelReference parent; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public ModelReference getParent() { + return parent; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private HasManyChild(String id, String content, ModelReference parent) { + this.id = id; + this.content = content; + this.parent = parent; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + HasManyChild hasManyChild = (HasManyChild) obj; + return ObjectsCompat.equals(getId(), hasManyChild.getId()) && + ObjectsCompat.equals(getContent(), hasManyChild.getContent()) && + ObjectsCompat.equals(getParent(), hasManyChild.getParent()) && + ObjectsCompat.equals(getCreatedAt(), hasManyChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), hasManyChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getParent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"HasManyChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static HasManyChild justId(String id) { + return new HasManyChild( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content, + parent); + } + public interface BuildStep { + HasManyChild build(); + BuildStep id(String id); + BuildStep content(String content); + BuildStep parent(Parent parent); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + private ModelReference parent; + public Builder() { + + } + + private Builder(String id, String content, ModelReference parent) { + this.id = id; + this.content = content; + this.parent = parent; + } + + @Override + public HasManyChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new HasManyChild( + id, + content, + parent); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + @Override + public BuildStep parent(Parent parent) { + this.parent = new LoadedModelReferenceImpl<>(parent); + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content, ModelReference parent) { + super(id, content, parent); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(Parent parent) { + return (CopyOfBuilder) super.parent(parent); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor API only should generate for Project and Team models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasOne; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.annotations.BelongsTo; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Project type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Projects\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"projectId\\",\\"name\\"}) +public final class Project implements Model { + public static final ProjectPath rootPath = new ProjectPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"Project\\", \\"id\\"); + public static final QueryField PROJECT_ID = field(\\"Project\\", \\"projectId\\"); + public static final QueryField NAME = field(\\"Project\\", \\"name\\"); + public static final QueryField PROJECT_TEAM_ID = field(\\"Project\\", \\"projectTeamId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String projectId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String name; + private final @ModelField(targetType=\\"Team\\") @HasOne(associatedWith = \\"teamId\\", type = Team.class) ModelReference team = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + private final @ModelField(targetType=\\"ID\\") String projectTeamId; + public String getId() { + return id; + } + + public String getProjectId() { + return projectId; + } + + public String getName() { + return name; + } + + public ModelReference getTeam() { + return team; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + public String getProjectTeamId() { + return projectTeamId; + } + + private Project(String id, String projectId, String name, String projectTeamId) { + this.id = id; + this.projectId = projectId; + this.name = name; + this.projectTeamId = projectTeamId; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Project project = (Project) obj; + return ObjectsCompat.equals(getId(), project.getId()) && + ObjectsCompat.equals(getProjectId(), project.getProjectId()) && + ObjectsCompat.equals(getName(), project.getName()) && + ObjectsCompat.equals(getCreatedAt(), project.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), project.getUpdatedAt()) && + ObjectsCompat.equals(getProjectTeamId(), project.getProjectTeamId()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getProjectId()) + .append(getName()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .append(getProjectTeamId()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Project {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"projectId=\\" + String.valueOf(getProjectId()) + \\", \\") + .append(\\"name=\\" + String.valueOf(getName()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") + .append(\\"projectTeamId=\\" + String.valueOf(getProjectTeamId())) + .append(\\"}\\") + .toString(); + } + + public static ProjectIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Project justId(String id) { + return new Project( + id, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + projectId, + name, + projectTeamId); + } + public interface ProjectIdStep { + NameStep projectId(String projectId); + } + + + public interface NameStep { + BuildStep name(String name); + } + + + public interface BuildStep { + Project build(); + BuildStep id(String id); + BuildStep projectTeamId(String projectTeamId); + } + + + public static class Builder implements ProjectIdStep, NameStep, BuildStep { + private String id; + private String projectId; + private String name; + private String projectTeamId; + public Builder() { + + } + + private Builder(String id, String projectId, String name, String projectTeamId) { + this.id = id; + this.projectId = projectId; + this.name = name; + this.projectTeamId = projectTeamId; + } + + @Override + public Project build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Project( + id, + projectId, + name, + projectTeamId); + } + + @Override + public NameStep projectId(String projectId) { + Objects.requireNonNull(projectId); + this.projectId = projectId; + return this; + } + + @Override + public BuildStep name(String name) { + Objects.requireNonNull(name); + this.name = name; + return this; + } + + @Override + public BuildStep projectTeamId(String projectTeamId) { + this.projectTeamId = projectTeamId; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String projectId, String name, String projectTeamId) { + super(id, projectId, name, projectTeamId); + Objects.requireNonNull(projectId); + Objects.requireNonNull(name); + } + + @Override + public CopyOfBuilder projectId(String projectId) { + return (CopyOfBuilder) super.projectId(projectId); + } + + @Override + public CopyOfBuilder name(String name) { + return (CopyOfBuilder) super.name(name); + } + + @Override + public CopyOfBuilder projectTeamId(String projectTeamId) { + return (CopyOfBuilder) super.projectTeamId(projectTeamId); + } + } + +} + +/** This is an auto generated class representing the Team type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Teams\\", hasLazySupport = true) +@Index(name = \\"undefined\\", fields = {\\"teamId\\",\\"name\\"}) +public final class Team implements Model { + public static final TeamPath rootPath = new TeamPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"Team\\", \\"id\\"); + public static final QueryField TEAM_ID = field(\\"Team\\", \\"teamId\\"); + public static final QueryField NAME = field(\\"Team\\", \\"name\\"); + public static final QueryField PROJECT = field(\\"Team\\", \\"teamProjectId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String teamId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String name; + private final @ModelField(targetType=\\"Project\\") @BelongsTo(targetName = \\"teamProjectId\\", type = Project.class) ModelReference project; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getTeamId() { + return teamId; + } + + public String getName() { + return name; + } + + public ModelReference getProject() { + return project; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Team(String id, String teamId, String name, ModelReference project) { + this.id = id; + this.teamId = teamId; + this.name = name; + this.project = project; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Team team = (Team) obj; + return ObjectsCompat.equals(getId(), team.getId()) && + ObjectsCompat.equals(getTeamId(), team.getTeamId()) && + ObjectsCompat.equals(getName(), team.getName()) && + ObjectsCompat.equals(getProject(), team.getProject()) && + ObjectsCompat.equals(getCreatedAt(), team.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), team.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getTeamId()) + .append(getName()) + .append(getProject()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Team {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"teamId=\\" + String.valueOf(getTeamId()) + \\", \\") + .append(\\"name=\\" + String.valueOf(getName()) + \\", \\") + .append(\\"project=\\" + String.valueOf(getProject()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static TeamIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Team justId(String id) { + return new Team( + id, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + teamId, + name, + project); + } + public interface TeamIdStep { + NameStep teamId(String teamId); + } + + + public interface NameStep { + BuildStep name(String name); + } + + + public interface BuildStep { + Team build(); + BuildStep id(String id); + BuildStep project(Project project); + } + + + public static class Builder implements TeamIdStep, NameStep, BuildStep { + private String id; + private String teamId; + private String name; + private ModelReference project; + public Builder() { + + } + + private Builder(String id, String teamId, String name, ModelReference project) { + this.id = id; + this.teamId = teamId; + this.name = name; + this.project = project; + } + + @Override + public Team build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Team( + id, + teamId, + name, + project); + } + + @Override + public NameStep teamId(String teamId) { + Objects.requireNonNull(teamId); + this.teamId = teamId; + return this; + } + + @Override + public BuildStep name(String name) { + Objects.requireNonNull(name); + this.name = name; + return this; + } + + @Override + public BuildStep project(Project project) { + this.project = new LoadedModelReferenceImpl<>(project); + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String teamId, String name, ModelReference project) { + super(id, teamId, name, project); + Objects.requireNonNull(teamId); + Objects.requireNonNull(name); + } + + @Override + public CopyOfBuilder teamId(String teamId) { + return (CopyOfBuilder) super.teamId(teamId); + } + + @Override + public CopyOfBuilder name(String name) { + return (CopyOfBuilder) super.name(name); + } + + @Override + public CopyOfBuilder project(Project project) { + return (CopyOfBuilder) super.project(project); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor DataStore Enabled Should generate for DefaultPKParent DefaultPKChild models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.annotations.BelongsTo; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the DefaultPKParent type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"DefaultPKParents\\") +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class DefaultPKParent implements Model { + public static final QueryField ID = field(\\"DefaultPKParent\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"DefaultPKParent\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"DefaultPKChild\\") @HasMany(associatedWith = \\"parent\\", type = DefaultPKChild.class) List children = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public List getChildren() { + return children; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private DefaultPKParent(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + DefaultPKParent defaultPkParent = (DefaultPKParent) obj; + return ObjectsCompat.equals(getId(), defaultPkParent.getId()) && + ObjectsCompat.equals(getContent(), defaultPkParent.getContent()) && + ObjectsCompat.equals(getCreatedAt(), defaultPkParent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), defaultPkParent.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"DefaultPKParent {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static DefaultPKParent justId(String id) { + return new DefaultPKParent( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content); + } + public interface BuildStep { + DefaultPKParent build(); + BuildStep id(String id); + BuildStep content(String content); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + public Builder() { + + } + + private Builder(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public DefaultPKParent build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new DefaultPKParent( + id, + content); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content) { + super(id, content); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + +} + +/** This is an auto generated class representing the DefaultPKChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"DefaultPKChildren\\") +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class DefaultPKChild implements Model { + public static final QueryField ID = field(\\"DefaultPKChild\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"DefaultPKChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"DefaultPKChild\\", \\"defaultPKParentChildrenId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"DefaultPKParent\\") @BelongsTo(targetName = \\"defaultPKParentChildrenId\\", type = DefaultPKParent.class) DefaultPKParent parent; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public DefaultPKParent getParent() { + return parent; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private DefaultPKChild(String id, String content, DefaultPKParent parent) { + this.id = id; + this.content = content; + this.parent = parent; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + DefaultPKChild defaultPkChild = (DefaultPKChild) obj; + return ObjectsCompat.equals(getId(), defaultPkChild.getId()) && + ObjectsCompat.equals(getContent(), defaultPkChild.getContent()) && + ObjectsCompat.equals(getParent(), defaultPkChild.getParent()) && + ObjectsCompat.equals(getCreatedAt(), defaultPkChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), defaultPkChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getParent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"DefaultPKChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static DefaultPKChild justId(String id) { + return new DefaultPKChild( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content, + parent); + } + public interface BuildStep { + DefaultPKChild build(); + BuildStep id(String id); + BuildStep content(String content); + BuildStep parent(DefaultPKParent parent); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + private DefaultPKParent parent; + public Builder() { + + } + + private Builder(String id, String content, DefaultPKParent parent) { + this.id = id; + this.content = content; + this.parent = parent; + } + + @Override + public DefaultPKChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new DefaultPKChild( + id, + content, + parent); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + @Override + public BuildStep parent(DefaultPKParent parent) { + this.parent = parent; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content, DefaultPKParent parent) { + super(id, content, parent); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(DefaultPKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor DataStore Enabled Should generate for HasOneParent HasOneChild models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasOne; +import com.amplifyframework.core.model.temporal.Temporal; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the HasOneParent type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"HasOneParents\\") +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class HasOneParent implements Model { + public static final QueryField ID = field(\\"HasOneParent\\", \\"id\\"); + public static final QueryField HAS_ONE_PARENT_CHILD_ID = field(\\"HasOneParent\\", \\"hasOneParentChildId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"HasOneChild\\") @HasOne(associatedWith = \\"id\\", type = HasOneChild.class) HasOneChild child = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + private final @ModelField(targetType=\\"ID\\") String hasOneParentChildId; + public String getId() { + return id; + } + + public HasOneChild getChild() { + return child; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + public String getHasOneParentChildId() { + return hasOneParentChildId; + } + + private HasOneParent(String id, String hasOneParentChildId) { + this.id = id; + this.hasOneParentChildId = hasOneParentChildId; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + HasOneParent hasOneParent = (HasOneParent) obj; + return ObjectsCompat.equals(getId(), hasOneParent.getId()) && + ObjectsCompat.equals(getCreatedAt(), hasOneParent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), hasOneParent.getUpdatedAt()) && + ObjectsCompat.equals(getHasOneParentChildId(), hasOneParent.getHasOneParentChildId()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .append(getHasOneParentChildId()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"HasOneParent {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") + .append(\\"hasOneParentChildId=\\" + String.valueOf(getHasOneParentChildId())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static HasOneParent justId(String id) { + return new HasOneParent( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + hasOneParentChildId); + } + public interface BuildStep { + HasOneParent build(); + BuildStep id(String id); + BuildStep hasOneParentChildId(String hasOneParentChildId); + } + + + public static class Builder implements BuildStep { + private String id; + private String hasOneParentChildId; + public Builder() { + + } + + private Builder(String id, String hasOneParentChildId) { + this.id = id; + this.hasOneParentChildId = hasOneParentChildId; + } + + @Override + public HasOneParent build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new HasOneParent( + id, + hasOneParentChildId); + } + + @Override + public BuildStep hasOneParentChildId(String hasOneParentChildId) { + this.hasOneParentChildId = hasOneParentChildId; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String hasOneParentChildId) { + super(id, hasOneParentChildId); + + } + + @Override + public CopyOfBuilder hasOneParentChildId(String hasOneParentChildId) { + return (CopyOfBuilder) super.hasOneParentChildId(hasOneParentChildId); + } + } + +} + +/** This is an auto generated class representing the HasOneChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"HasOneChildren\\") +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class HasOneChild implements Model { + public static final QueryField ID = field(\\"HasOneChild\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"HasOneChild\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private HasOneChild(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + HasOneChild hasOneChild = (HasOneChild) obj; + return ObjectsCompat.equals(getId(), hasOneChild.getId()) && + ObjectsCompat.equals(getContent(), hasOneChild.getContent()) && + ObjectsCompat.equals(getCreatedAt(), hasOneChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), hasOneChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"HasOneChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static HasOneChild justId(String id) { + return new HasOneChild( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content); + } + public interface BuildStep { + HasOneChild build(); + BuildStep id(String id); + BuildStep content(String content); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + public Builder() { + + } + + private Builder(String id, String content) { + this.id = id; + this.content = content; + } + + @Override + public HasOneChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new HasOneChild( + id, + content); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content) { + super(id, content); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor DataStore Enabled should generate for Blog, Post, and Comment models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.annotations.BelongsTo; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Blog type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Blogs\\") +@Index(name = \\"undefined\\", fields = {\\"blogId\\"}) +public final class Blog implements Model { + public static final QueryField ID = field(\\"Blog\\", \\"id\\"); + public static final QueryField BLOG_ID = field(\\"Blog\\", \\"blogId\\"); + public static final QueryField NAME = field(\\"Blog\\", \\"name\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\", isRequired = true) String blogId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String name; + private final @ModelField(targetType=\\"Post\\", isRequired = true) @HasMany(associatedWith = \\"blog\\", type = Post.class) List posts = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getBlogId() { + return blogId; + } + + public String getName() { + return name; + } + + public List getPosts() { + return posts; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Blog(String id, String blogId, String name) { + this.id = id; + this.blogId = blogId; + this.name = name; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Blog blog = (Blog) obj; + return ObjectsCompat.equals(getId(), blog.getId()) && + ObjectsCompat.equals(getBlogId(), blog.getBlogId()) && + ObjectsCompat.equals(getName(), blog.getName()) && + ObjectsCompat.equals(getCreatedAt(), blog.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), blog.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getBlogId()) + .append(getName()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Blog {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"blogId=\\" + String.valueOf(getBlogId()) + \\", \\") + .append(\\"name=\\" + String.valueOf(getName()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BlogIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Blog justId(String id) { + return new Blog( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + blogId, + name); + } + public interface BlogIdStep { + NameStep blogId(String blogId); + } + + + public interface NameStep { + BuildStep name(String name); + } + + + public interface BuildStep { + Blog build(); + BuildStep id(String id); + } + + + public static class Builder implements BlogIdStep, NameStep, BuildStep { + private String id; + private String blogId; + private String name; + public Builder() { + + } + + private Builder(String id, String blogId, String name) { + this.id = id; + this.blogId = blogId; + this.name = name; + } + + @Override + public Blog build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Blog( + id, + blogId, + name); + } + + @Override + public NameStep blogId(String blogId) { + Objects.requireNonNull(blogId); + this.blogId = blogId; + return this; + } + + @Override + public BuildStep name(String name) { + Objects.requireNonNull(name); + this.name = name; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String blogId, String name) { + super(id, blogId, name); + Objects.requireNonNull(blogId); + Objects.requireNonNull(name); + } + + @Override + public CopyOfBuilder blogId(String blogId) { + return (CopyOfBuilder) super.blogId(blogId); + } + + @Override + public CopyOfBuilder name(String name) { + return (CopyOfBuilder) super.name(name); + } + } + +} + +/** This is an auto generated class representing the Post type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Posts\\") +@Index(name = \\"undefined\\", fields = {\\"postId\\",\\"title\\"}) +public final class Post implements Model { + public static final QueryField ID = field(\\"Post\\", \\"id\\"); + public static final QueryField POST_ID = field(\\"Post\\", \\"postId\\"); + public static final QueryField TITLE = field(\\"Post\\", \\"title\\"); + public static final QueryField BLOG = field(\\"Post\\", \\"blogPostsId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String postId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String title; + private final @ModelField(targetType=\\"Blog\\", isRequired = true) @BelongsTo(targetName = \\"blogPostsId\\", type = Blog.class) Blog blog; + private final @ModelField(targetType=\\"Comment\\", isRequired = true) @HasMany(associatedWith = \\"post\\", type = Comment.class) List comments = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getPostId() { + return postId; + } + + public String getTitle() { + return title; + } + + public Blog getBlog() { + return blog; + } + + public List getComments() { + return comments; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Post(String id, String postId, String title, Blog blog) { + this.id = id; + this.postId = postId; + this.title = title; + this.blog = blog; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Post post = (Post) obj; + return ObjectsCompat.equals(getId(), post.getId()) && + ObjectsCompat.equals(getPostId(), post.getPostId()) && + ObjectsCompat.equals(getTitle(), post.getTitle()) && + ObjectsCompat.equals(getBlog(), post.getBlog()) && + ObjectsCompat.equals(getCreatedAt(), post.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), post.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getPostId()) + .append(getTitle()) + .append(getBlog()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Post {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"postId=\\" + String.valueOf(getPostId()) + \\", \\") + .append(\\"title=\\" + String.valueOf(getTitle()) + \\", \\") + .append(\\"blog=\\" + String.valueOf(getBlog()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static PostIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Post justId(String id) { + return new Post( + id, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + postId, + title, + blog); + } + public interface PostIdStep { + TitleStep postId(String postId); + } + + + public interface TitleStep { + BlogStep title(String title); + } + + + public interface BlogStep { + BuildStep blog(Blog blog); + } + + + public interface BuildStep { + Post build(); + BuildStep id(String id); + } + + + public static class Builder implements PostIdStep, TitleStep, BlogStep, BuildStep { + private String id; + private String postId; + private String title; + private Blog blog; + public Builder() { + + } + + private Builder(String id, String postId, String title, Blog blog) { + this.id = id; + this.postId = postId; + this.title = title; + this.blog = blog; + } + + @Override + public Post build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Post( + id, + postId, + title, + blog); + } + + @Override + public TitleStep postId(String postId) { + Objects.requireNonNull(postId); + this.postId = postId; + return this; + } + + @Override + public BlogStep title(String title) { + Objects.requireNonNull(title); + this.title = title; + return this; + } + + @Override + public BuildStep blog(Blog blog) { + Objects.requireNonNull(blog); + this.blog = blog; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String postId, String title, Blog blog) { + super(id, postId, title, blog); + Objects.requireNonNull(postId); + Objects.requireNonNull(title); + Objects.requireNonNull(blog); + } + + @Override + public CopyOfBuilder postId(String postId) { + return (CopyOfBuilder) super.postId(postId); + } + + @Override + public CopyOfBuilder title(String title) { + return (CopyOfBuilder) super.title(title); + } + + @Override + public CopyOfBuilder blog(Blog blog) { + return (CopyOfBuilder) super.blog(blog); + } + } + +} + +/** This is an auto generated class representing the Comment type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Comments\\") +@Index(name = \\"undefined\\", fields = {\\"commentId\\",\\"content\\"}) +public final class Comment implements Model { + public static final QueryField ID = field(\\"Comment\\", \\"id\\"); + public static final QueryField COMMENT_ID = field(\\"Comment\\", \\"commentId\\"); + public static final QueryField CONTENT = field(\\"Comment\\", \\"content\\"); + public static final QueryField POST = field(\\"Comment\\", \\"postCommentsId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String commentId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"Post\\", isRequired = true) @BelongsTo(targetName = \\"postCommentsId\\", type = Post.class) Post post; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getCommentId() { + return commentId; + } + + public String getContent() { + return content; + } + + public Post getPost() { + return post; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Comment(String id, String commentId, String content, Post post) { + this.id = id; + this.commentId = commentId; + this.content = content; + this.post = post; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Comment comment = (Comment) obj; + return ObjectsCompat.equals(getId(), comment.getId()) && + ObjectsCompat.equals(getCommentId(), comment.getCommentId()) && + ObjectsCompat.equals(getContent(), comment.getContent()) && + ObjectsCompat.equals(getPost(), comment.getPost()) && + ObjectsCompat.equals(getCreatedAt(), comment.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), comment.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getCommentId()) + .append(getContent()) + .append(getPost()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Comment {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"commentId=\\" + String.valueOf(getCommentId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"post=\\" + String.valueOf(getPost()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static CommentIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Comment justId(String id) { + return new Comment( + id, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + commentId, + content, + post); + } + public interface CommentIdStep { + ContentStep commentId(String commentId); + } + + + public interface ContentStep { + PostStep content(String content); + } + + + public interface PostStep { + BuildStep post(Post post); + } + + + public interface BuildStep { + Comment build(); + BuildStep id(String id); + } + + + public static class Builder implements CommentIdStep, ContentStep, PostStep, BuildStep { + private String id; + private String commentId; + private String content; + private Post post; + public Builder() { + + } + + private Builder(String id, String commentId, String content, Post post) { + this.id = id; + this.commentId = commentId; + this.content = content; + this.post = post; + } + + @Override + public Comment build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Comment( + id, + commentId, + content, + post); + } + + @Override + public ContentStep commentId(String commentId) { + Objects.requireNonNull(commentId); + this.commentId = commentId; + return this; + } + + @Override + public PostStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep post(Post post) { + Objects.requireNonNull(post); + this.post = post; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String commentId, String content, Post post) { + super(id, commentId, content, post); + Objects.requireNonNull(commentId); + Objects.requireNonNull(content); + Objects.requireNonNull(post); + } + + @Override + public CopyOfBuilder commentId(String commentId) { + return (CopyOfBuilder) super.commentId(commentId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder post(Post post) { + return (CopyOfBuilder) super.post(post); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor DataStore Enabled should generate for CompositePKParent and (CompositePK, Implicit, StrangeExplicit, ChildSansBelongsTo) Child models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.annotations.BelongsTo; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the CompositePKParent type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"CompositePKParents\\") +@Index(name = \\"undefined\\", fields = {\\"customId\\",\\"content\\"}) +public final class CompositePKParent implements Model { + public static final QueryField ID = field(\\"CompositePKParent\\", \\"id\\"); + public static final QueryField CUSTOM_ID = field(\\"CompositePKParent\\", \\"customId\\"); + public static final QueryField CONTENT = field(\\"CompositePKParent\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String customId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKChild\\") @HasMany(associatedWith = \\"parent\\", type = CompositePKChild.class) List children = null; + private final @ModelField(targetType=\\"ImplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = ImplicitChild.class) List implicitChildren = null; + private final @ModelField(targetType=\\"StrangeExplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = StrangeExplicitChild.class) List strangeChildren = null; + private final @ModelField(targetType=\\"ChildSansBelongsTo\\") @HasMany(associatedWith = \\"compositePKParentChildrenSansBelongsToId\\", type = ChildSansBelongsTo.class) List childrenSansBelongsTo = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getCustomId() { + return customId; + } + + public String getContent() { + return content; + } + + public List getChildren() { + return children; + } + + public List getImplicitChildren() { + return implicitChildren; + } + + public List getStrangeChildren() { + return strangeChildren; + } + + public List getChildrenSansBelongsTo() { + return childrenSansBelongsTo; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private CompositePKParent(String id, String customId, String content) { + this.id = id; + this.customId = customId; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + CompositePKParent compositePkParent = (CompositePKParent) obj; + return ObjectsCompat.equals(getId(), compositePkParent.getId()) && + ObjectsCompat.equals(getCustomId(), compositePkParent.getCustomId()) && + ObjectsCompat.equals(getContent(), compositePkParent.getContent()) && + ObjectsCompat.equals(getCreatedAt(), compositePkParent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), compositePkParent.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getCustomId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"CompositePKParent {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"customId=\\" + String.valueOf(getCustomId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static CustomIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static CompositePKParent justId(String id) { + return new CompositePKParent( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + customId, + content); + } + public interface CustomIdStep { + ContentStep customId(String customId); + } + + + public interface ContentStep { + BuildStep content(String content); + } + + + public interface BuildStep { + CompositePKParent build(); + BuildStep id(String id); + } + + + public static class Builder implements CustomIdStep, ContentStep, BuildStep { + private String id; + private String customId; + private String content; + public Builder() { + + } + + private Builder(String id, String customId, String content) { + this.id = id; + this.customId = customId; + this.content = content; + } + + @Override + public CompositePKParent build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new CompositePKParent( + id, + customId, + content); + } + + @Override + public ContentStep customId(String customId) { + Objects.requireNonNull(customId); + this.customId = customId; + return this; + } + + @Override + public BuildStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String customId, String content) { + super(id, customId, content); + Objects.requireNonNull(customId); + Objects.requireNonNull(content); + } + + @Override + public CopyOfBuilder customId(String customId) { + return (CopyOfBuilder) super.customId(customId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + +} + +/** This is an auto generated class representing the CompositePKChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"CompositePKChildren\\") +@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) +@Index(name = \\"byParent\\", fields = {\\"parentId\\",\\"parentTitle\\"}) +public final class CompositePKChild implements Model { + public static final QueryField ID = field(\\"CompositePKChild\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"CompositePKChild\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"CompositePKChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"CompositePKChild\\", \\"parentId\\"); + public static final QueryField PARENT_TITLE = field(\\"CompositePKChild\\", \\"parentTitle\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKParent\\") @BelongsTo(targetName = \\"parentId\\", type = CompositePKParent.class) CompositePKParent parent; + private final @ModelField(targetType=\\"String\\") String parentTitle; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getChildId() { + return childId; + } + + public String getContent() { + return content; + } + + public CompositePKParent getParent() { + return parent; + } + + public String getParentTitle() { + return parentTitle; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private CompositePKChild(String id, String childId, String content, CompositePKParent parent, String parentTitle) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + this.parentTitle = parentTitle; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + CompositePKChild compositePkChild = (CompositePKChild) obj; + return ObjectsCompat.equals(getId(), compositePkChild.getId()) && + ObjectsCompat.equals(getChildId(), compositePkChild.getChildId()) && + ObjectsCompat.equals(getContent(), compositePkChild.getContent()) && + ObjectsCompat.equals(getParent(), compositePkChild.getParent()) && + ObjectsCompat.equals(getParentTitle(), compositePkChild.getParentTitle()) && + ObjectsCompat.equals(getCreatedAt(), compositePkChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), compositePkChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getChildId()) + .append(getContent()) + .append(getParent()) + .append(getParentTitle()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"CompositePKChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"parentTitle=\\" + String.valueOf(getParentTitle()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static ChildIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static CompositePKChild justId(String id) { + return new CompositePKChild( + id, + null, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + childId, + content, + parent, + parentTitle); + } + public interface ChildIdStep { + ContentStep childId(String childId); + } + + + public interface ContentStep { + BuildStep content(String content); + } + + + public interface BuildStep { + CompositePKChild build(); + BuildStep id(String id); + BuildStep parent(CompositePKParent parent); + BuildStep parentTitle(String parentTitle); + } + + + public static class Builder implements ChildIdStep, ContentStep, BuildStep { + private String id; + private String childId; + private String content; + private CompositePKParent parent; + private String parentTitle; + public Builder() { + + } + + private Builder(String id, String childId, String content, CompositePKParent parent, String parentTitle) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + this.parentTitle = parentTitle; + } + + @Override + public CompositePKChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new CompositePKChild( + id, + childId, + content, + parent, + parentTitle); + } + + @Override + public ContentStep childId(String childId) { + Objects.requireNonNull(childId); + this.childId = childId; + return this; + } + + @Override + public BuildStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep parent(CompositePKParent parent) { + this.parent = parent; + return this; + } + + @Override + public BuildStep parentTitle(String parentTitle) { + this.parentTitle = parentTitle; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String childId, String content, CompositePKParent parent, String parentTitle) { + super(id, childId, content, parent, parentTitle); + Objects.requireNonNull(childId); + Objects.requireNonNull(content); + } + + @Override + public CopyOfBuilder childId(String childId) { + return (CopyOfBuilder) super.childId(childId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(CompositePKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + + @Override + public CopyOfBuilder parentTitle(String parentTitle) { + return (CopyOfBuilder) super.parentTitle(parentTitle); + } + } + +} + +/** This is an auto generated class representing the ImplicitChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"ImplicitChildren\\") +@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) +public final class ImplicitChild implements Model { + public static final QueryField ID = field(\\"ImplicitChild\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"ImplicitChild\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"ImplicitChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"ImplicitChild\\", \\"compositePKParentImplicitChildrenId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"compositePKParentImplicitChildrenId\\", type = CompositePKParent.class) CompositePKParent parent; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getChildId() { + return childId; + } + + public String getContent() { + return content; + } + + public CompositePKParent getParent() { + return parent; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private ImplicitChild(String id, String childId, String content, CompositePKParent parent) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + ImplicitChild implicitChild = (ImplicitChild) obj; + return ObjectsCompat.equals(getId(), implicitChild.getId()) && + ObjectsCompat.equals(getChildId(), implicitChild.getChildId()) && + ObjectsCompat.equals(getContent(), implicitChild.getContent()) && + ObjectsCompat.equals(getParent(), implicitChild.getParent()) && + ObjectsCompat.equals(getCreatedAt(), implicitChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), implicitChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getChildId()) + .append(getContent()) + .append(getParent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"ImplicitChild {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static ChildIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static ImplicitChild justId(String id) { + return new ImplicitChild( + id, + null, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + childId, + content, + parent); + } + public interface ChildIdStep { + ContentStep childId(String childId); + } + + + public interface ContentStep { + ParentStep content(String content); + } + + + public interface ParentStep { + BuildStep parent(CompositePKParent parent); + } + + + public interface BuildStep { + ImplicitChild build(); + BuildStep id(String id); + } + + + public static class Builder implements ChildIdStep, ContentStep, ParentStep, BuildStep { + private String id; + private String childId; + private String content; + private CompositePKParent parent; + public Builder() { + + } + + private Builder(String id, String childId, String content, CompositePKParent parent) { + this.id = id; + this.childId = childId; + this.content = content; + this.parent = parent; + } + + @Override + public ImplicitChild build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new ImplicitChild( + id, + childId, + content, + parent); + } + + @Override + public ContentStep childId(String childId) { + Objects.requireNonNull(childId); + this.childId = childId; + return this; + } + + @Override + public ParentStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep parent(CompositePKParent parent) { + Objects.requireNonNull(parent); + this.parent = parent; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String childId, String content, CompositePKParent parent) { + super(id, childId, content, parent); + Objects.requireNonNull(childId); + Objects.requireNonNull(content); + Objects.requireNonNull(parent); + } + + @Override + public CopyOfBuilder childId(String childId) { + return (CopyOfBuilder) super.childId(childId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(CompositePKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + } + +} + +/** This is an auto generated class representing the StrangeExplicitChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"StrangeExplicitChildren\\") +@Index(name = \\"undefined\\", fields = {\\"strangeId\\",\\"content\\"}) +@Index(name = \\"byCompositePKParentX\\", fields = {\\"strangeParentId\\",\\"strangeParentTitle\\"}) +public final class StrangeExplicitChild implements Model { + public static final QueryField ID = field(\\"StrangeExplicitChild\\", \\"id\\"); + public static final QueryField STRANGE_ID = field(\\"StrangeExplicitChild\\", \\"strangeId\\"); + public static final QueryField CONTENT = field(\\"StrangeExplicitChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"StrangeExplicitChild\\", \\"strangeParentId\\"); + public static final QueryField STRANGE_PARENT_TITLE = field(\\"StrangeExplicitChild\\", \\"strangeParentTitle\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String strangeId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"strangeParentId\\", type = CompositePKParent.class) CompositePKParent parent; + private final @ModelField(targetType=\\"String\\") String strangeParentTitle; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + public String getId() { + return id; + } + + public String getStrangeId() { + return strangeId; + } + + public String getContent() { + return content; + } + + public CompositePKParent getParent() { + return parent; + } + + public String getStrangeParentTitle() { + return strangeParentTitle; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private StrangeExplicitChild(String id, String strangeId, String content, CompositePKParent parent, String strangeParentTitle) { + this.id = id; + this.strangeId = strangeId; + this.content = content; + this.parent = parent; + this.strangeParentTitle = strangeParentTitle; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + StrangeExplicitChild strangeExplicitChild = (StrangeExplicitChild) obj; + return ObjectsCompat.equals(getId(), strangeExplicitChild.getId()) && + ObjectsCompat.equals(getStrangeId(), strangeExplicitChild.getStrangeId()) && + ObjectsCompat.equals(getContent(), strangeExplicitChild.getContent()) && + ObjectsCompat.equals(getParent(), strangeExplicitChild.getParent()) && + ObjectsCompat.equals(getStrangeParentTitle(), strangeExplicitChild.getStrangeParentTitle()) && + ObjectsCompat.equals(getCreatedAt(), strangeExplicitChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), strangeExplicitChild.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getStrangeId()) + .append(getContent()) + .append(getParent()) + .append(getStrangeParentTitle()) .append(getCreatedAt()) .append(getUpdatedAt()) - .append(getHasOneParentChildId()) .toString() .hashCode(); } @@ -2382,16 +5748,19 @@ public final class HasOneParent implements Model { @Override public String toString() { return new StringBuilder() - .append(\\"HasOneParent {\\") + .append(\\"StrangeExplicitChild {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"strangeId=\\" + String.valueOf(getStrangeId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") + .append(\\"strangeParentTitle=\\" + String.valueOf(getStrangeParentTitle()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") - .append(\\"hasOneParentChildId=\\" + String.valueOf(getHasOneParentChildId())) + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) .append(\\"}\\") .toString(); } - public static BuildStep builder() { + public static StrangeIdStep builder() { return new Builder(); } @@ -2403,48 +5772,99 @@ public final class HasOneParent implements Model { * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated */ - public static HasOneParent justId(String id) { - return new HasOneParent( + public static StrangeExplicitChild justId(String id) { + return new StrangeExplicitChild( id, + null, + null, + null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - hasOneParentChildId); + strangeId, + content, + parent, + strangeParentTitle); + } + public interface StrangeIdStep { + ContentStep strangeId(String strangeId); + } + + + public interface ContentStep { + ParentStep content(String content); + } + + + public interface ParentStep { + BuildStep parent(CompositePKParent parent); } + + public interface BuildStep { - HasOneParent build(); + StrangeExplicitChild build(); BuildStep id(String id); - BuildStep hasOneParentChildId(String hasOneParentChildId); + BuildStep strangeParentTitle(String strangeParentTitle); } - public static class Builder implements BuildStep { + public static class Builder implements StrangeIdStep, ContentStep, ParentStep, BuildStep { private String id; - private String hasOneParentChildId; + private String strangeId; + private String content; + private CompositePKParent parent; + private String strangeParentTitle; public Builder() { } - private Builder(String id, String hasOneParentChildId) { + private Builder(String id, String strangeId, String content, CompositePKParent parent, String strangeParentTitle) { this.id = id; - this.hasOneParentChildId = hasOneParentChildId; + this.strangeId = strangeId; + this.content = content; + this.parent = parent; + this.strangeParentTitle = strangeParentTitle; } @Override - public HasOneParent build() { + public StrangeExplicitChild build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); - return new HasOneParent( + return new StrangeExplicitChild( id, - hasOneParentChildId); + strangeId, + content, + parent, + strangeParentTitle); } @Override - public BuildStep hasOneParentChildId(String hasOneParentChildId) { - this.hasOneParentChildId = hasOneParentChildId; + public ContentStep strangeId(String strangeId) { + Objects.requireNonNull(strangeId); + this.strangeId = strangeId; + return this; + } + + @Override + public ParentStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep parent(CompositePKParent parent) { + Objects.requireNonNull(parent); + this.parent = parent; + return this; + } + + @Override + public BuildStep strangeParentTitle(String strangeParentTitle) { + this.strangeParentTitle = strangeParentTitle; return this; } @@ -2460,38 +5880,76 @@ public final class HasOneParent implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String hasOneParentChildId) { - super(id, hasOneParentChildId); - + private CopyOfBuilder(String id, String strangeId, String content, CompositePKParent parent, String strangeParentTitle) { + super(id, strangeId, content, parent, strangeParentTitle); + Objects.requireNonNull(strangeId); + Objects.requireNonNull(content); + Objects.requireNonNull(parent); } @Override - public CopyOfBuilder hasOneParentChildId(String hasOneParentChildId) { - return (CopyOfBuilder) super.hasOneParentChildId(hasOneParentChildId); + public CopyOfBuilder strangeId(String strangeId) { + return (CopyOfBuilder) super.strangeId(strangeId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder parent(CompositePKParent parent) { + return (CopyOfBuilder) super.parent(parent); + } + + @Override + public CopyOfBuilder strangeParentTitle(String strangeParentTitle) { + return (CopyOfBuilder) super.strangeParentTitle(strangeParentTitle); } } } -/** This is an auto generated class representing the HasOneChild type in your schema. */ +/** This is an auto generated class representing the ChildSansBelongsTo type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"HasOneChildren\\") -@Index(name = \\"undefined\\", fields = {\\"id\\"}) -public final class HasOneChild implements Model { - public static final QueryField ID = field(\\"HasOneChild\\", \\"id\\"); - public static final QueryField CONTENT = field(\\"HasOneChild\\", \\"content\\"); +@ModelConfig(pluralName = \\"ChildSansBelongsTos\\") +@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) +@Index(name = \\"byParent\\", fields = {\\"compositePKParentChildrenSansBelongsToCustomId\\",\\"compositePKParentChildrenSansBelongsToContent\\"}) +public final class ChildSansBelongsTo implements Model { + public static final QueryField ID = field(\\"ChildSansBelongsTo\\", \\"id\\"); + public static final QueryField CHILD_ID = field(\\"ChildSansBelongsTo\\", \\"childId\\"); + public static final QueryField CONTENT = field(\\"ChildSansBelongsTo\\", \\"content\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CUSTOM_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToCustomId\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CONTENT = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToContent\\"); + public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String compositePKParentChildrenSansBelongsToCustomId; + private final @ModelField(targetType=\\"String\\") String compositePKParentChildrenSansBelongsToContent; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + private final @ModelField(targetType=\\"ID\\") String compositePKParentChildrenSansBelongsToId; public String getId() { return id; } + public String getChildId() { + return childId; + } + public String getContent() { return content; } + public String getCompositePkParentChildrenSansBelongsToCustomId() { + return compositePKParentChildrenSansBelongsToCustomId; + } + + public String getCompositePkParentChildrenSansBelongsToContent() { + return compositePKParentChildrenSansBelongsToContent; + } + public Temporal.DateTime getCreatedAt() { return createdAt; } @@ -2500,9 +5958,17 @@ public final class HasOneChild implements Model { return updatedAt; } - private HasOneChild(String id, String content) { + public String getCompositePkParentChildrenSansBelongsToId() { + return compositePKParentChildrenSansBelongsToId; + } + + private ChildSansBelongsTo(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { this.id = id; + this.childId = childId; this.content = content; + this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; + this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; + this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; } @Override @@ -2512,11 +5978,15 @@ public final class HasOneChild implements Model { } else if(obj == null || getClass() != obj.getClass()) { return false; } else { - HasOneChild hasOneChild = (HasOneChild) obj; - return ObjectsCompat.equals(getId(), hasOneChild.getId()) && - ObjectsCompat.equals(getContent(), hasOneChild.getContent()) && - ObjectsCompat.equals(getCreatedAt(), hasOneChild.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), hasOneChild.getUpdatedAt()); + ChildSansBelongsTo childSansBelongsTo = (ChildSansBelongsTo) obj; + return ObjectsCompat.equals(getId(), childSansBelongsTo.getId()) && + ObjectsCompat.equals(getChildId(), childSansBelongsTo.getChildId()) && + ObjectsCompat.equals(getContent(), childSansBelongsTo.getContent()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToCustomId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToCustomId()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToContent(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToContent()) && + ObjectsCompat.equals(getCreatedAt(), childSansBelongsTo.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), childSansBelongsTo.getUpdatedAt()) && + ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToId()); } } @@ -2524,9 +5994,13 @@ public final class HasOneChild implements Model { public int hashCode() { return new StringBuilder() .append(getId()) + .append(getChildId()) .append(getContent()) + .append(getCompositePkParentChildrenSansBelongsToCustomId()) + .append(getCompositePkParentChildrenSansBelongsToContent()) .append(getCreatedAt()) .append(getUpdatedAt()) + .append(getCompositePkParentChildrenSansBelongsToId()) .toString() .hashCode(); } @@ -2534,16 +6008,20 @@ public final class HasOneChild implements Model { @Override public String toString() { return new StringBuilder() - .append(\\"HasOneChild {\\") + .append(\\"ChildSansBelongsTo {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToCustomId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToCustomId()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToContent=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToContent()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") + .append(\\"compositePKParentChildrenSansBelongsToId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToId())) .append(\\"}\\") .toString(); } - public static BuildStep builder() { + public static ChildIdStep builder() { return new Builder(); } @@ -2555,51 +6033,114 @@ public final class HasOneChild implements Model { * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated */ - public static HasOneChild justId(String id) { - return new HasOneChild( + public static ChildSansBelongsTo justId(String id) { + return new ChildSansBelongsTo( id, + null, + null, + null, + null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - content); + childId, + content, + compositePKParentChildrenSansBelongsToCustomId, + compositePKParentChildrenSansBelongsToContent, + compositePKParentChildrenSansBelongsToId); + } + public interface ChildIdStep { + ContentStep childId(String childId); + } + + + public interface ContentStep { + CompositePkParentChildrenSansBelongsToCustomIdStep content(String content); + } + + + public interface CompositePkParentChildrenSansBelongsToCustomIdStep { + BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId); } + + public interface BuildStep { - HasOneChild build(); + ChildSansBelongsTo build(); BuildStep id(String id); - BuildStep content(String content); + BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent); + BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId); } - public static class Builder implements BuildStep { + public static class Builder implements ChildIdStep, ContentStep, CompositePkParentChildrenSansBelongsToCustomIdStep, BuildStep { private String id; + private String childId; private String content; + private String compositePKParentChildrenSansBelongsToCustomId; + private String compositePKParentChildrenSansBelongsToContent; + private String compositePKParentChildrenSansBelongsToId; public Builder() { } - private Builder(String id, String content) { + private Builder(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { this.id = id; + this.childId = childId; this.content = content; + this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; + this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; + this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; } @Override - public HasOneChild build() { + public ChildSansBelongsTo build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); - return new HasOneChild( + return new ChildSansBelongsTo( id, - content); + childId, + content, + compositePKParentChildrenSansBelongsToCustomId, + compositePKParentChildrenSansBelongsToContent, + compositePKParentChildrenSansBelongsToId); } @Override - public BuildStep content(String content) { + public ContentStep childId(String childId) { + Objects.requireNonNull(childId); + this.childId = childId; + return this; + } + + @Override + public CompositePkParentChildrenSansBelongsToCustomIdStep content(String content) { + Objects.requireNonNull(content); this.content = content; return this; } + @Override + public BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { + Objects.requireNonNull(compositePkParentChildrenSansBelongsToCustomId); + this.compositePKParentChildrenSansBelongsToCustomId = compositePkParentChildrenSansBelongsToCustomId; + return this; + } + + @Override + public BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { + this.compositePKParentChildrenSansBelongsToContent = compositePkParentChildrenSansBelongsToContent; + return this; + } + + @Override + public BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { + this.compositePKParentChildrenSansBelongsToId = compositePkParentChildrenSansBelongsToId; + return this; + } + /** * @param id id * @return Current Builder instance, for fluent method chaining @@ -2612,24 +6153,47 @@ public final class HasOneChild implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String content) { - super(id, content); - + private CopyOfBuilder(String id, String childId, String content, String compositePkParentChildrenSansBelongsToCustomId, String compositePkParentChildrenSansBelongsToContent, String compositePkParentChildrenSansBelongsToId) { + super(id, childId, content, compositePKParentChildrenSansBelongsToCustomId, compositePKParentChildrenSansBelongsToContent, compositePKParentChildrenSansBelongsToId); + Objects.requireNonNull(childId); + Objects.requireNonNull(content); + Objects.requireNonNull(compositePKParentChildrenSansBelongsToCustomId); + } + + @Override + public CopyOfBuilder childId(String childId) { + return (CopyOfBuilder) super.childId(childId); } @Override public CopyOfBuilder content(String content) { return (CopyOfBuilder) super.content(content); } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToCustomId(compositePkParentChildrenSansBelongsToCustomId); + } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToContent(compositePkParentChildrenSansBelongsToContent); + } + + @Override + public CopyOfBuilder compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { + return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToId(compositePkParentChildrenSansBelongsToId); + } } } " `; -exports[`AppSyncModelVisitor DataStore Enabled should generate for CompositePKParent and (CompositePK, Implicit, StrangeExplicit, ChildSansBelongsTo) Child models 1`] = ` +exports[`AppSyncModelVisitor DataStore Enabled should generate for Parent, HasOneChild, HasManyChild models 1`] = ` "package com.amplifyframework.datastore.generated.model; +import com.amplifyframework.core.model.annotations.HasOne; import com.amplifyframework.core.model.annotations.HasMany; import com.amplifyframework.core.model.temporal.Temporal; import com.amplifyframework.core.model.annotations.BelongsTo; @@ -2648,51 +6212,31 @@ import com.amplifyframework.core.model.query.predicate.QueryField; import static com.amplifyframework.core.model.query.predicate.QueryField.field; -/** This is an auto generated class representing the CompositePKParent type in your schema. */ +/** This is an auto generated class representing the Parent type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"CompositePKParents\\") -@Index(name = \\"undefined\\", fields = {\\"customId\\",\\"content\\"}) -public final class CompositePKParent implements Model { - public static final QueryField ID = field(\\"CompositePKParent\\", \\"id\\"); - public static final QueryField CUSTOM_ID = field(\\"CompositePKParent\\", \\"customId\\"); - public static final QueryField CONTENT = field(\\"CompositePKParent\\", \\"content\\"); +@ModelConfig(pluralName = \\"Parents\\") +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class Parent implements Model { + public static final QueryField ID = field(\\"Parent\\", \\"id\\"); + public static final QueryField PARENT_CHILD_ID = field(\\"Parent\\", \\"parentChildId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String customId; - private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"CompositePKChild\\") @HasMany(associatedWith = \\"parent\\", type = CompositePKChild.class) List children = null; - private final @ModelField(targetType=\\"ImplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = ImplicitChild.class) List implicitChildren = null; - private final @ModelField(targetType=\\"StrangeExplicitChild\\") @HasMany(associatedWith = \\"parent\\", type = StrangeExplicitChild.class) List strangeChildren = null; - private final @ModelField(targetType=\\"ChildSansBelongsTo\\") @HasMany(associatedWith = \\"compositePKParentChildrenSansBelongsToId\\", type = ChildSansBelongsTo.class) List childrenSansBelongsTo = null; + private final @ModelField(targetType=\\"HasOneChild\\") @HasOne(associatedWith = \\"id\\", type = HasOneChild.class) HasOneChild child = null; + private final @ModelField(targetType=\\"HasManyChild\\") @HasMany(associatedWith = \\"parent\\", type = HasManyChild.class) List children = null; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + private final @ModelField(targetType=\\"ID\\") String parentChildId; public String getId() { return id; } - public String getCustomId() { - return customId; - } - - public String getContent() { - return content; + public HasOneChild getChild() { + return child; } - public List getChildren() { + public List getChildren() { return children; } - public List getImplicitChildren() { - return implicitChildren; - } - - public List getStrangeChildren() { - return strangeChildren; - } - - public List getChildrenSansBelongsTo() { - return childrenSansBelongsTo; - } - public Temporal.DateTime getCreatedAt() { return createdAt; } @@ -2701,10 +6245,13 @@ public final class CompositePKParent implements Model { return updatedAt; } - private CompositePKParent(String id, String customId, String content) { + public String getParentChildId() { + return parentChildId; + } + + private Parent(String id, String parentChildId) { this.id = id; - this.customId = customId; - this.content = content; + this.parentChildId = parentChildId; } @Override @@ -2714,12 +6261,11 @@ public final class CompositePKParent implements Model { } else if(obj == null || getClass() != obj.getClass()) { return false; } else { - CompositePKParent compositePkParent = (CompositePKParent) obj; - return ObjectsCompat.equals(getId(), compositePkParent.getId()) && - ObjectsCompat.equals(getCustomId(), compositePkParent.getCustomId()) && - ObjectsCompat.equals(getContent(), compositePkParent.getContent()) && - ObjectsCompat.equals(getCreatedAt(), compositePkParent.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), compositePkParent.getUpdatedAt()); + Parent parent = (Parent) obj; + return ObjectsCompat.equals(getId(), parent.getId()) && + ObjectsCompat.equals(getCreatedAt(), parent.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), parent.getUpdatedAt()) && + ObjectsCompat.equals(getParentChildId(), parent.getParentChildId()); } } @@ -2727,10 +6273,9 @@ public final class CompositePKParent implements Model { public int hashCode() { return new StringBuilder() .append(getId()) - .append(getCustomId()) - .append(getContent()) .append(getCreatedAt()) .append(getUpdatedAt()) + .append(getParentChildId()) .toString() .hashCode(); } @@ -2738,17 +6283,16 @@ public final class CompositePKParent implements Model { @Override public String toString() { return new StringBuilder() - .append(\\"CompositePKParent {\\") + .append(\\"Parent {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"customId=\\" + String.valueOf(getCustomId()) + \\", \\") - .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") + .append(\\"parentChildId=\\" + String.valueOf(getParentChildId())) .append(\\"}\\") .toString(); } - public static CustomIdStep builder() { + public static BuildStep builder() { return new Builder(); } @@ -2760,70 +6304,48 @@ public final class CompositePKParent implements Model { * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated */ - public static CompositePKParent justId(String id) { - return new CompositePKParent( + public static Parent justId(String id) { + return new Parent( id, - null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - customId, - content); - } - public interface CustomIdStep { - ContentStep customId(String customId); - } - - - public interface ContentStep { - BuildStep content(String content); + parentChildId); } - - public interface BuildStep { - CompositePKParent build(); + Parent build(); BuildStep id(String id); + BuildStep parentChildId(String parentChildId); } - public static class Builder implements CustomIdStep, ContentStep, BuildStep { + public static class Builder implements BuildStep { private String id; - private String customId; - private String content; + private String parentChildId; public Builder() { } - private Builder(String id, String customId, String content) { + private Builder(String id, String parentChildId) { this.id = id; - this.customId = customId; - this.content = content; + this.parentChildId = parentChildId; } @Override - public CompositePKParent build() { + public Parent build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); - return new CompositePKParent( + return new Parent( id, - customId, - content); - } - - @Override - public ContentStep customId(String customId) { - Objects.requireNonNull(customId); - this.customId = customId; - return this; + parentChildId); } @Override - public BuildStep content(String content) { - Objects.requireNonNull(content); - this.content = content; + public BuildStep parentChildId(String parentChildId) { + this.parentChildId = parentChildId; return this; } @@ -2839,63 +6361,38 @@ public final class CompositePKParent implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String customId, String content) { - super(id, customId, content); - Objects.requireNonNull(customId); - Objects.requireNonNull(content); - } - - @Override - public CopyOfBuilder customId(String customId) { - return (CopyOfBuilder) super.customId(customId); + private CopyOfBuilder(String id, String parentChildId) { + super(id, parentChildId); + } - @Override - public CopyOfBuilder content(String content) { - return (CopyOfBuilder) super.content(content); - } - } - -} - -/** This is an auto generated class representing the CompositePKChild type in your schema. */ -@SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"CompositePKChildren\\") -@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) -@Index(name = \\"byParent\\", fields = {\\"parentId\\",\\"parentTitle\\"}) -public final class CompositePKChild implements Model { - public static final QueryField ID = field(\\"CompositePKChild\\", \\"id\\"); - public static final QueryField CHILD_ID = field(\\"CompositePKChild\\", \\"childId\\"); - public static final QueryField CONTENT = field(\\"CompositePKChild\\", \\"content\\"); - public static final QueryField PARENT = field(\\"CompositePKChild\\", \\"parentId\\"); - public static final QueryField PARENT_TITLE = field(\\"CompositePKChild\\", \\"parentTitle\\"); + @Override + public CopyOfBuilder parentChildId(String parentChildId) { + return (CopyOfBuilder) super.parentChildId(parentChildId); + } + } + +} + +/** This is an auto generated class representing the HasOneChild type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"HasOneChildren\\") +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class HasOneChild implements Model { + public static final QueryField ID = field(\\"HasOneChild\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"HasOneChild\\", \\"content\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; - private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"CompositePKParent\\") @BelongsTo(targetName = \\"parentId\\", type = CompositePKParent.class) CompositePKParent parent; - private final @ModelField(targetType=\\"String\\") String parentTitle; + private final @ModelField(targetType=\\"String\\") String content; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; public String getId() { return id; } - public String getChildId() { - return childId; - } - public String getContent() { return content; } - public CompositePKParent getParent() { - return parent; - } - - public String getParentTitle() { - return parentTitle; - } - public Temporal.DateTime getCreatedAt() { return createdAt; } @@ -2904,12 +6401,9 @@ public final class CompositePKChild implements Model { return updatedAt; } - private CompositePKChild(String id, String childId, String content, CompositePKParent parent, String parentTitle) { + private HasOneChild(String id, String content) { this.id = id; - this.childId = childId; this.content = content; - this.parent = parent; - this.parentTitle = parentTitle; } @Override @@ -2919,14 +6413,11 @@ public final class CompositePKChild implements Model { } else if(obj == null || getClass() != obj.getClass()) { return false; } else { - CompositePKChild compositePkChild = (CompositePKChild) obj; - return ObjectsCompat.equals(getId(), compositePkChild.getId()) && - ObjectsCompat.equals(getChildId(), compositePkChild.getChildId()) && - ObjectsCompat.equals(getContent(), compositePkChild.getContent()) && - ObjectsCompat.equals(getParent(), compositePkChild.getParent()) && - ObjectsCompat.equals(getParentTitle(), compositePkChild.getParentTitle()) && - ObjectsCompat.equals(getCreatedAt(), compositePkChild.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), compositePkChild.getUpdatedAt()); + HasOneChild hasOneChild = (HasOneChild) obj; + return ObjectsCompat.equals(getId(), hasOneChild.getId()) && + ObjectsCompat.equals(getContent(), hasOneChild.getContent()) && + ObjectsCompat.equals(getCreatedAt(), hasOneChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), hasOneChild.getUpdatedAt()); } } @@ -2934,10 +6425,7 @@ public final class CompositePKChild implements Model { public int hashCode() { return new StringBuilder() .append(getId()) - .append(getChildId()) .append(getContent()) - .append(getParent()) - .append(getParentTitle()) .append(getCreatedAt()) .append(getUpdatedAt()) .toString() @@ -2947,19 +6435,16 @@ public final class CompositePKChild implements Model { @Override public String toString() { return new StringBuilder() - .append(\\"CompositePKChild {\\") + .append(\\"HasOneChild {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") - .append(\\"parentTitle=\\" + String.valueOf(getParentTitle()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) .append(\\"}\\") .toString(); } - public static ChildIdStep builder() { + public static BuildStep builder() { return new Builder(); } @@ -2971,97 +6456,51 @@ public final class CompositePKChild implements Model { * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated */ - public static CompositePKChild justId(String id) { - return new CompositePKChild( + public static HasOneChild justId(String id) { + return new HasOneChild( id, - null, - null, - null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - childId, - content, - parent, - parentTitle); - } - public interface ChildIdStep { - ContentStep childId(String childId); - } - - - public interface ContentStep { - BuildStep content(String content); + content); } - - public interface BuildStep { - CompositePKChild build(); + HasOneChild build(); BuildStep id(String id); - BuildStep parent(CompositePKParent parent); - BuildStep parentTitle(String parentTitle); + BuildStep content(String content); } - public static class Builder implements ChildIdStep, ContentStep, BuildStep { + public static class Builder implements BuildStep { private String id; - private String childId; private String content; - private CompositePKParent parent; - private String parentTitle; public Builder() { } - private Builder(String id, String childId, String content, CompositePKParent parent, String parentTitle) { + private Builder(String id, String content) { this.id = id; - this.childId = childId; this.content = content; - this.parent = parent; - this.parentTitle = parentTitle; } @Override - public CompositePKChild build() { + public HasOneChild build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); - return new CompositePKChild( + return new HasOneChild( id, - childId, - content, - parent, - parentTitle); - } - - @Override - public ContentStep childId(String childId) { - Objects.requireNonNull(childId); - this.childId = childId; - return this; + content); } @Override public BuildStep content(String content) { - Objects.requireNonNull(content); this.content = content; return this; } - @Override - public BuildStep parent(CompositePKParent parent) { - this.parent = parent; - return this; - } - - @Override - public BuildStep parentTitle(String parentTitle) { - this.parentTitle = parentTitle; - return this; - } - /** * @param id id * @return Current Builder instance, for fluent method chaining @@ -3074,63 +6513,41 @@ public final class CompositePKChild implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String childId, String content, CompositePKParent parent, String parentTitle) { - super(id, childId, content, parent, parentTitle); - Objects.requireNonNull(childId); - Objects.requireNonNull(content); - } - - @Override - public CopyOfBuilder childId(String childId) { - return (CopyOfBuilder) super.childId(childId); + private CopyOfBuilder(String id, String content) { + super(id, content); + } @Override public CopyOfBuilder content(String content) { return (CopyOfBuilder) super.content(content); } - - @Override - public CopyOfBuilder parent(CompositePKParent parent) { - return (CopyOfBuilder) super.parent(parent); - } - - @Override - public CopyOfBuilder parentTitle(String parentTitle) { - return (CopyOfBuilder) super.parentTitle(parentTitle); - } } } -/** This is an auto generated class representing the ImplicitChild type in your schema. */ +/** This is an auto generated class representing the HasManyChild type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"ImplicitChildren\\") -@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) -public final class ImplicitChild implements Model { - public static final QueryField ID = field(\\"ImplicitChild\\", \\"id\\"); - public static final QueryField CHILD_ID = field(\\"ImplicitChild\\", \\"childId\\"); - public static final QueryField CONTENT = field(\\"ImplicitChild\\", \\"content\\"); - public static final QueryField PARENT = field(\\"ImplicitChild\\", \\"compositePKParentImplicitChildrenId\\"); +@ModelConfig(pluralName = \\"HasManyChildren\\") +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class HasManyChild implements Model { + public static final QueryField ID = field(\\"HasManyChild\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"HasManyChild\\", \\"content\\"); + public static final QueryField PARENT = field(\\"HasManyChild\\", \\"parentChildrenId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; - private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"compositePKParentImplicitChildrenId\\", type = CompositePKParent.class) CompositePKParent parent; + private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"Parent\\") @BelongsTo(targetName = \\"parentChildrenId\\", type = Parent.class) Parent parent; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; public String getId() { return id; } - public String getChildId() { - return childId; - } - public String getContent() { return content; } - public CompositePKParent getParent() { + public Parent getParent() { return parent; } @@ -3142,9 +6559,8 @@ public final class ImplicitChild implements Model { return updatedAt; } - private ImplicitChild(String id, String childId, String content, CompositePKParent parent) { + private HasManyChild(String id, String content, Parent parent) { this.id = id; - this.childId = childId; this.content = content; this.parent = parent; } @@ -3156,13 +6572,12 @@ public final class ImplicitChild implements Model { } else if(obj == null || getClass() != obj.getClass()) { return false; } else { - ImplicitChild implicitChild = (ImplicitChild) obj; - return ObjectsCompat.equals(getId(), implicitChild.getId()) && - ObjectsCompat.equals(getChildId(), implicitChild.getChildId()) && - ObjectsCompat.equals(getContent(), implicitChild.getContent()) && - ObjectsCompat.equals(getParent(), implicitChild.getParent()) && - ObjectsCompat.equals(getCreatedAt(), implicitChild.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), implicitChild.getUpdatedAt()); + HasManyChild hasManyChild = (HasManyChild) obj; + return ObjectsCompat.equals(getId(), hasManyChild.getId()) && + ObjectsCompat.equals(getContent(), hasManyChild.getContent()) && + ObjectsCompat.equals(getParent(), hasManyChild.getParent()) && + ObjectsCompat.equals(getCreatedAt(), hasManyChild.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), hasManyChild.getUpdatedAt()); } } @@ -3170,7 +6585,6 @@ public final class ImplicitChild implements Model { public int hashCode() { return new StringBuilder() .append(getId()) - .append(getChildId()) .append(getContent()) .append(getParent()) .append(getCreatedAt()) @@ -3182,9 +6596,8 @@ public final class ImplicitChild implements Model { @Override public String toString() { return new StringBuilder() - .append(\\"ImplicitChild {\\") + .append(\\"HasManyChild {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") @@ -3193,7 +6606,7 @@ public final class ImplicitChild implements Model { .toString(); } - public static ChildIdStep builder() { + public static BuildStep builder() { return new Builder(); } @@ -3205,86 +6618,59 @@ public final class ImplicitChild implements Model { * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated */ - public static ImplicitChild justId(String id) { - return new ImplicitChild( + public static HasManyChild justId(String id) { + return new HasManyChild( id, null, - null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - childId, content, parent); } - public interface ChildIdStep { - ContentStep childId(String childId); - } - - - public interface ContentStep { - ParentStep content(String content); - } - - - public interface ParentStep { - BuildStep parent(CompositePKParent parent); - } - - public interface BuildStep { - ImplicitChild build(); + HasManyChild build(); BuildStep id(String id); + BuildStep content(String content); + BuildStep parent(Parent parent); } - public static class Builder implements ChildIdStep, ContentStep, ParentStep, BuildStep { + public static class Builder implements BuildStep { private String id; - private String childId; private String content; - private CompositePKParent parent; + private Parent parent; public Builder() { } - private Builder(String id, String childId, String content, CompositePKParent parent) { + private Builder(String id, String content, Parent parent) { this.id = id; - this.childId = childId; this.content = content; this.parent = parent; } @Override - public ImplicitChild build() { + public HasManyChild build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); - return new ImplicitChild( + return new HasManyChild( id, - childId, content, parent); } @Override - public ContentStep childId(String childId) { - Objects.requireNonNull(childId); - this.childId = childId; - return this; - } - - @Override - public ParentStep content(String content) { - Objects.requireNonNull(content); + public BuildStep content(String content) { this.content = content; return this; } @Override - public BuildStep parent(CompositePKParent parent) { - Objects.requireNonNull(parent); + public BuildStep parent(Parent parent) { this.parent = parent; return this; } @@ -3301,16 +6687,9 @@ public final class ImplicitChild implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String childId, String content, CompositePKParent parent) { - super(id, childId, content, parent); - Objects.requireNonNull(childId); - Objects.requireNonNull(content); - Objects.requireNonNull(parent); - } - - @Override - public CopyOfBuilder childId(String childId) { - return (CopyOfBuilder) super.childId(childId); + private CopyOfBuilder(String id, String content, Parent parent) { + super(id, content, parent); + } @Override @@ -3319,49 +6698,66 @@ public final class ImplicitChild implements Model { } @Override - public CopyOfBuilder parent(CompositePKParent parent) { + public CopyOfBuilder parent(Parent parent) { return (CopyOfBuilder) super.parent(parent); } } } +" +`; -/** This is an auto generated class representing the StrangeExplicitChild type in your schema. */ +exports[`AppSyncModelVisitor DataStore Enabled should generate for Project and Team models 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasOne; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.annotations.BelongsTo; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Project type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"StrangeExplicitChildren\\") -@Index(name = \\"undefined\\", fields = {\\"strangeId\\",\\"content\\"}) -@Index(name = \\"byCompositePKParentX\\", fields = {\\"strangeParentId\\",\\"strangeParentTitle\\"}) -public final class StrangeExplicitChild implements Model { - public static final QueryField ID = field(\\"StrangeExplicitChild\\", \\"id\\"); - public static final QueryField STRANGE_ID = field(\\"StrangeExplicitChild\\", \\"strangeId\\"); - public static final QueryField CONTENT = field(\\"StrangeExplicitChild\\", \\"content\\"); - public static final QueryField PARENT = field(\\"StrangeExplicitChild\\", \\"strangeParentId\\"); - public static final QueryField STRANGE_PARENT_TITLE = field(\\"StrangeExplicitChild\\", \\"strangeParentTitle\\"); +@ModelConfig(pluralName = \\"Projects\\") +@Index(name = \\"undefined\\", fields = {\\"projectId\\",\\"name\\"}) +public final class Project implements Model { + public static final QueryField ID = field(\\"Project\\", \\"id\\"); + public static final QueryField PROJECT_ID = field(\\"Project\\", \\"projectId\\"); + public static final QueryField NAME = field(\\"Project\\", \\"name\\"); + public static final QueryField PROJECT_TEAM_ID = field(\\"Project\\", \\"projectTeamId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String strangeId; - private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"CompositePKParent\\", isRequired = true) @BelongsTo(targetName = \\"strangeParentId\\", type = CompositePKParent.class) CompositePKParent parent; - private final @ModelField(targetType=\\"String\\") String strangeParentTitle; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String projectId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String name; + private final @ModelField(targetType=\\"Team\\") @HasOne(associatedWith = \\"teamId\\", type = Team.class) Team team = null; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + private final @ModelField(targetType=\\"ID\\") String projectTeamId; public String getId() { return id; } - public String getStrangeId() { - return strangeId; - } - - public String getContent() { - return content; + public String getProjectId() { + return projectId; } - public CompositePKParent getParent() { - return parent; + public String getName() { + return name; } - public String getStrangeParentTitle() { - return strangeParentTitle; + public Team getTeam() { + return team; } public Temporal.DateTime getCreatedAt() { @@ -3372,12 +6768,15 @@ public final class StrangeExplicitChild implements Model { return updatedAt; } - private StrangeExplicitChild(String id, String strangeId, String content, CompositePKParent parent, String strangeParentTitle) { + public String getProjectTeamId() { + return projectTeamId; + } + + private Project(String id, String projectId, String name, String projectTeamId) { this.id = id; - this.strangeId = strangeId; - this.content = content; - this.parent = parent; - this.strangeParentTitle = strangeParentTitle; + this.projectId = projectId; + this.name = name; + this.projectTeamId = projectTeamId; } @Override @@ -3387,14 +6786,13 @@ public final class StrangeExplicitChild implements Model { } else if(obj == null || getClass() != obj.getClass()) { return false; } else { - StrangeExplicitChild strangeExplicitChild = (StrangeExplicitChild) obj; - return ObjectsCompat.equals(getId(), strangeExplicitChild.getId()) && - ObjectsCompat.equals(getStrangeId(), strangeExplicitChild.getStrangeId()) && - ObjectsCompat.equals(getContent(), strangeExplicitChild.getContent()) && - ObjectsCompat.equals(getParent(), strangeExplicitChild.getParent()) && - ObjectsCompat.equals(getStrangeParentTitle(), strangeExplicitChild.getStrangeParentTitle()) && - ObjectsCompat.equals(getCreatedAt(), strangeExplicitChild.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), strangeExplicitChild.getUpdatedAt()); + Project project = (Project) obj; + return ObjectsCompat.equals(getId(), project.getId()) && + ObjectsCompat.equals(getProjectId(), project.getProjectId()) && + ObjectsCompat.equals(getName(), project.getName()) && + ObjectsCompat.equals(getCreatedAt(), project.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), project.getUpdatedAt()) && + ObjectsCompat.equals(getProjectTeamId(), project.getProjectTeamId()); } } @@ -3402,12 +6800,11 @@ public final class StrangeExplicitChild implements Model { public int hashCode() { return new StringBuilder() .append(getId()) - .append(getStrangeId()) - .append(getContent()) - .append(getParent()) - .append(getStrangeParentTitle()) + .append(getProjectId()) + .append(getName()) .append(getCreatedAt()) .append(getUpdatedAt()) + .append(getProjectTeamId()) .toString() .hashCode(); } @@ -3415,19 +6812,18 @@ public final class StrangeExplicitChild implements Model { @Override public String toString() { return new StringBuilder() - .append(\\"StrangeExplicitChild {\\") + .append(\\"Project {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"strangeId=\\" + String.valueOf(getStrangeId()) + \\", \\") - .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"parent=\\" + String.valueOf(getParent()) + \\", \\") - .append(\\"strangeParentTitle=\\" + String.valueOf(getStrangeParentTitle()) + \\", \\") + .append(\\"projectId=\\" + String.valueOf(getProjectId()) + \\", \\") + .append(\\"name=\\" + String.valueOf(getName()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") + .append(\\"projectTeamId=\\" + String.valueOf(getProjectTeamId())) .append(\\"}\\") .toString(); } - public static StrangeIdStep builder() { + public static ProjectIdStep builder() { return new Builder(); } @@ -3439,99 +6835,82 @@ public final class StrangeExplicitChild implements Model { * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated */ - public static StrangeExplicitChild justId(String id) { - return new StrangeExplicitChild( + public static Project justId(String id) { + return new Project( id, null, null, - null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - strangeId, - content, - parent, - strangeParentTitle); - } - public interface StrangeIdStep { - ContentStep strangeId(String strangeId); + projectId, + name, + projectTeamId); } - - - public interface ContentStep { - ParentStep content(String content); + public interface ProjectIdStep { + NameStep projectId(String projectId); } - public interface ParentStep { - BuildStep parent(CompositePKParent parent); + public interface NameStep { + BuildStep name(String name); } public interface BuildStep { - StrangeExplicitChild build(); + Project build(); BuildStep id(String id); - BuildStep strangeParentTitle(String strangeParentTitle); + BuildStep projectTeamId(String projectTeamId); } - public static class Builder implements StrangeIdStep, ContentStep, ParentStep, BuildStep { + public static class Builder implements ProjectIdStep, NameStep, BuildStep { private String id; - private String strangeId; - private String content; - private CompositePKParent parent; - private String strangeParentTitle; + private String projectId; + private String name; + private String projectTeamId; public Builder() { } - private Builder(String id, String strangeId, String content, CompositePKParent parent, String strangeParentTitle) { + private Builder(String id, String projectId, String name, String projectTeamId) { this.id = id; - this.strangeId = strangeId; - this.content = content; - this.parent = parent; - this.strangeParentTitle = strangeParentTitle; + this.projectId = projectId; + this.name = name; + this.projectTeamId = projectTeamId; } @Override - public StrangeExplicitChild build() { + public Project build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); - return new StrangeExplicitChild( + return new Project( id, - strangeId, - content, - parent, - strangeParentTitle); - } - - @Override - public ContentStep strangeId(String strangeId) { - Objects.requireNonNull(strangeId); - this.strangeId = strangeId; - return this; + projectId, + name, + projectTeamId); } @Override - public ParentStep content(String content) { - Objects.requireNonNull(content); - this.content = content; + public NameStep projectId(String projectId) { + Objects.requireNonNull(projectId); + this.projectId = projectId; return this; } @Override - public BuildStep parent(CompositePKParent parent) { - Objects.requireNonNull(parent); - this.parent = parent; + public BuildStep name(String name) { + Objects.requireNonNull(name); + this.name = name; return this; } @Override - public BuildStep strangeParentTitle(String strangeParentTitle) { - this.strangeParentTitle = strangeParentTitle; + public BuildStep projectTeamId(String projectTeamId) { + this.projectTeamId = projectTeamId; return this; } @@ -3547,74 +6926,59 @@ public final class StrangeExplicitChild implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String strangeId, String content, CompositePKParent parent, String strangeParentTitle) { - super(id, strangeId, content, parent, strangeParentTitle); - Objects.requireNonNull(strangeId); - Objects.requireNonNull(content); - Objects.requireNonNull(parent); + private CopyOfBuilder(String id, String projectId, String name, String projectTeamId) { + super(id, projectId, name, projectTeamId); + Objects.requireNonNull(projectId); + Objects.requireNonNull(name); } @Override - public CopyOfBuilder strangeId(String strangeId) { - return (CopyOfBuilder) super.strangeId(strangeId); - } - - @Override - public CopyOfBuilder content(String content) { - return (CopyOfBuilder) super.content(content); + public CopyOfBuilder projectId(String projectId) { + return (CopyOfBuilder) super.projectId(projectId); } @Override - public CopyOfBuilder parent(CompositePKParent parent) { - return (CopyOfBuilder) super.parent(parent); + public CopyOfBuilder name(String name) { + return (CopyOfBuilder) super.name(name); } @Override - public CopyOfBuilder strangeParentTitle(String strangeParentTitle) { - return (CopyOfBuilder) super.strangeParentTitle(strangeParentTitle); + public CopyOfBuilder projectTeamId(String projectTeamId) { + return (CopyOfBuilder) super.projectTeamId(projectTeamId); } } } -/** This is an auto generated class representing the ChildSansBelongsTo type in your schema. */ +/** This is an auto generated class representing the Team type in your schema. */ @SuppressWarnings(\\"all\\") -@ModelConfig(pluralName = \\"ChildSansBelongsTos\\") -@Index(name = \\"undefined\\", fields = {\\"childId\\",\\"content\\"}) -@Index(name = \\"byParent\\", fields = {\\"compositePKParentChildrenSansBelongsToCustomId\\",\\"compositePKParentChildrenSansBelongsToContent\\"}) -public final class ChildSansBelongsTo implements Model { - public static final QueryField ID = field(\\"ChildSansBelongsTo\\", \\"id\\"); - public static final QueryField CHILD_ID = field(\\"ChildSansBelongsTo\\", \\"childId\\"); - public static final QueryField CONTENT = field(\\"ChildSansBelongsTo\\", \\"content\\"); - public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CUSTOM_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToCustomId\\"); - public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_CONTENT = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToContent\\"); - public static final QueryField COMPOSITE_PK_PARENT_CHILDREN_SANS_BELONGS_TO_ID = field(\\"ChildSansBelongsTo\\", \\"compositePKParentChildrenSansBelongsToId\\"); +@ModelConfig(pluralName = \\"Teams\\") +@Index(name = \\"undefined\\", fields = {\\"teamId\\",\\"name\\"}) +public final class Team implements Model { + public static final QueryField ID = field(\\"Team\\", \\"id\\"); + public static final QueryField TEAM_ID = field(\\"Team\\", \\"teamId\\"); + public static final QueryField NAME = field(\\"Team\\", \\"name\\"); + public static final QueryField PROJECT = field(\\"Team\\", \\"teamProjectId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String childId; - private final @ModelField(targetType=\\"String\\", isRequired = true) String content; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String compositePKParentChildrenSansBelongsToCustomId; - private final @ModelField(targetType=\\"String\\") String compositePKParentChildrenSansBelongsToContent; + private final @ModelField(targetType=\\"ID\\", isRequired = true) String teamId; + private final @ModelField(targetType=\\"String\\", isRequired = true) String name; + private final @ModelField(targetType=\\"Project\\") @BelongsTo(targetName = \\"teamProjectId\\", type = Project.class) Project project; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - private final @ModelField(targetType=\\"ID\\") String compositePKParentChildrenSansBelongsToId; public String getId() { return id; } - public String getChildId() { - return childId; - } - - public String getContent() { - return content; + public String getTeamId() { + return teamId; } - public String getCompositePkParentChildrenSansBelongsToCustomId() { - return compositePKParentChildrenSansBelongsToCustomId; + public String getName() { + return name; } - public String getCompositePkParentChildrenSansBelongsToContent() { - return compositePKParentChildrenSansBelongsToContent; + public Project getProject() { + return project; } public Temporal.DateTime getCreatedAt() { @@ -3625,17 +6989,11 @@ public final class ChildSansBelongsTo implements Model { return updatedAt; } - public String getCompositePkParentChildrenSansBelongsToId() { - return compositePKParentChildrenSansBelongsToId; - } - - private ChildSansBelongsTo(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { + private Team(String id, String teamId, String name, Project project) { this.id = id; - this.childId = childId; - this.content = content; - this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; - this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; - this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; + this.teamId = teamId; + this.name = name; + this.project = project; } @Override @@ -3645,15 +7003,13 @@ public final class ChildSansBelongsTo implements Model { } else if(obj == null || getClass() != obj.getClass()) { return false; } else { - ChildSansBelongsTo childSansBelongsTo = (ChildSansBelongsTo) obj; - return ObjectsCompat.equals(getId(), childSansBelongsTo.getId()) && - ObjectsCompat.equals(getChildId(), childSansBelongsTo.getChildId()) && - ObjectsCompat.equals(getContent(), childSansBelongsTo.getContent()) && - ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToCustomId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToCustomId()) && - ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToContent(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToContent()) && - ObjectsCompat.equals(getCreatedAt(), childSansBelongsTo.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), childSansBelongsTo.getUpdatedAt()) && - ObjectsCompat.equals(getCompositePkParentChildrenSansBelongsToId(), childSansBelongsTo.getCompositePkParentChildrenSansBelongsToId()); + Team team = (Team) obj; + return ObjectsCompat.equals(getId(), team.getId()) && + ObjectsCompat.equals(getTeamId(), team.getTeamId()) && + ObjectsCompat.equals(getName(), team.getName()) && + ObjectsCompat.equals(getProject(), team.getProject()) && + ObjectsCompat.equals(getCreatedAt(), team.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), team.getUpdatedAt()); } } @@ -3661,13 +7017,11 @@ public final class ChildSansBelongsTo implements Model { public int hashCode() { return new StringBuilder() .append(getId()) - .append(getChildId()) - .append(getContent()) - .append(getCompositePkParentChildrenSansBelongsToCustomId()) - .append(getCompositePkParentChildrenSansBelongsToContent()) + .append(getTeamId()) + .append(getName()) + .append(getProject()) .append(getCreatedAt()) .append(getUpdatedAt()) - .append(getCompositePkParentChildrenSansBelongsToId()) .toString() .hashCode(); } @@ -3675,20 +7029,18 @@ public final class ChildSansBelongsTo implements Model { @Override public String toString() { return new StringBuilder() - .append(\\"ChildSansBelongsTo {\\") + .append(\\"Team {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"childId=\\" + String.valueOf(getChildId()) + \\", \\") - .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"compositePKParentChildrenSansBelongsToCustomId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToCustomId()) + \\", \\") - .append(\\"compositePKParentChildrenSansBelongsToContent=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToContent()) + \\", \\") + .append(\\"teamId=\\" + String.valueOf(getTeamId()) + \\", \\") + .append(\\"name=\\" + String.valueOf(getName()) + \\", \\") + .append(\\"project=\\" + String.valueOf(getProject()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") - .append(\\"compositePKParentChildrenSansBelongsToId=\\" + String.valueOf(getCompositePkParentChildrenSansBelongsToId())) + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) .append(\\"}\\") .toString(); } - public static ChildIdStep builder() { + public static TeamIdStep builder() { return new Builder(); } @@ -3700,111 +7052,82 @@ public final class ChildSansBelongsTo implements Model { * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated */ - public static ChildSansBelongsTo justId(String id) { - return new ChildSansBelongsTo( + public static Team justId(String id) { + return new Team( id, null, null, - null, - null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - childId, - content, - compositePKParentChildrenSansBelongsToCustomId, - compositePKParentChildrenSansBelongsToContent, - compositePKParentChildrenSansBelongsToId); - } - public interface ChildIdStep { - ContentStep childId(String childId); + teamId, + name, + project); } - - - public interface ContentStep { - CompositePkParentChildrenSansBelongsToCustomIdStep content(String content); + public interface TeamIdStep { + NameStep teamId(String teamId); } - public interface CompositePkParentChildrenSansBelongsToCustomIdStep { - BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId); + public interface NameStep { + BuildStep name(String name); } public interface BuildStep { - ChildSansBelongsTo build(); + Team build(); BuildStep id(String id); - BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent); - BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId); + BuildStep project(Project project); } - public static class Builder implements ChildIdStep, ContentStep, CompositePkParentChildrenSansBelongsToCustomIdStep, BuildStep { + public static class Builder implements TeamIdStep, NameStep, BuildStep { private String id; - private String childId; - private String content; - private String compositePKParentChildrenSansBelongsToCustomId; - private String compositePKParentChildrenSansBelongsToContent; - private String compositePKParentChildrenSansBelongsToId; + private String teamId; + private String name; + private Project project; public Builder() { } - private Builder(String id, String childId, String content, String compositePKParentChildrenSansBelongsToCustomId, String compositePKParentChildrenSansBelongsToContent, String compositePKParentChildrenSansBelongsToId) { + private Builder(String id, String teamId, String name, Project project) { this.id = id; - this.childId = childId; - this.content = content; - this.compositePKParentChildrenSansBelongsToCustomId = compositePKParentChildrenSansBelongsToCustomId; - this.compositePKParentChildrenSansBelongsToContent = compositePKParentChildrenSansBelongsToContent; - this.compositePKParentChildrenSansBelongsToId = compositePKParentChildrenSansBelongsToId; + this.teamId = teamId; + this.name = name; + this.project = project; } @Override - public ChildSansBelongsTo build() { + public Team build() { String id = this.id != null ? this.id : UUID.randomUUID().toString(); - return new ChildSansBelongsTo( + return new Team( id, - childId, - content, - compositePKParentChildrenSansBelongsToCustomId, - compositePKParentChildrenSansBelongsToContent, - compositePKParentChildrenSansBelongsToId); - } - - @Override - public ContentStep childId(String childId) { - Objects.requireNonNull(childId); - this.childId = childId; - return this; - } - - @Override - public CompositePkParentChildrenSansBelongsToCustomIdStep content(String content) { - Objects.requireNonNull(content); - this.content = content; - return this; + teamId, + name, + project); } @Override - public BuildStep compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { - Objects.requireNonNull(compositePkParentChildrenSansBelongsToCustomId); - this.compositePKParentChildrenSansBelongsToCustomId = compositePkParentChildrenSansBelongsToCustomId; + public NameStep teamId(String teamId) { + Objects.requireNonNull(teamId); + this.teamId = teamId; return this; } @Override - public BuildStep compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { - this.compositePKParentChildrenSansBelongsToContent = compositePkParentChildrenSansBelongsToContent; + public BuildStep name(String name) { + Objects.requireNonNull(name); + this.name = name; return this; } @Override - public BuildStep compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { - this.compositePKParentChildrenSansBelongsToId = compositePkParentChildrenSansBelongsToId; + public BuildStep project(Project project) { + this.project = project; return this; } @@ -3820,36 +7143,25 @@ public final class ChildSansBelongsTo implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String childId, String content, String compositePkParentChildrenSansBelongsToCustomId, String compositePkParentChildrenSansBelongsToContent, String compositePkParentChildrenSansBelongsToId) { - super(id, childId, content, compositePKParentChildrenSansBelongsToCustomId, compositePKParentChildrenSansBelongsToContent, compositePKParentChildrenSansBelongsToId); - Objects.requireNonNull(childId); - Objects.requireNonNull(content); - Objects.requireNonNull(compositePKParentChildrenSansBelongsToCustomId); + private CopyOfBuilder(String id, String teamId, String name, Project project) { + super(id, teamId, name, project); + Objects.requireNonNull(teamId); + Objects.requireNonNull(name); } @Override - public CopyOfBuilder childId(String childId) { - return (CopyOfBuilder) super.childId(childId); - } - - @Override - public CopyOfBuilder content(String content) { - return (CopyOfBuilder) super.content(content); - } - - @Override - public CopyOfBuilder compositePkParentChildrenSansBelongsToCustomId(String compositePkParentChildrenSansBelongsToCustomId) { - return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToCustomId(compositePkParentChildrenSansBelongsToCustomId); + public CopyOfBuilder teamId(String teamId) { + return (CopyOfBuilder) super.teamId(teamId); } @Override - public CopyOfBuilder compositePkParentChildrenSansBelongsToContent(String compositePkParentChildrenSansBelongsToContent) { - return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToContent(compositePkParentChildrenSansBelongsToContent); + public CopyOfBuilder name(String name) { + return (CopyOfBuilder) super.name(name); } @Override - public CopyOfBuilder compositePkParentChildrenSansBelongsToId(String compositePkParentChildrenSansBelongsToId) { - return (CopyOfBuilder) super.compositePkParentChildrenSansBelongsToId(compositePkParentChildrenSansBelongsToId); + public CopyOfBuilder project(Project project) { + return (CopyOfBuilder) super.project(project); } } diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts index 259a66899..2cc7989ca 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-api-lazyload-css-visitor.test.ts @@ -106,6 +106,60 @@ describe('AppSyncModelVisitor', () => { compositePKParentChildrenSansBelongsToContent: String } `; + + const schemaParentHasOneHasManyChild = /* GraphQL */ ` + type Parent @model { + id: ID! @primaryKey + child: HasOneChild @hasOne + children: [HasManyChild] @hasMany + } + + type HasOneChild @model { + id: ID! @primaryKey + content: String + } + + type HasManyChild @model { + id: ID! @primaryKey + content: String + parent: Parent @belongsTo + } + `; + + const schemaProjectTeam = /* GraphQL */ ` + type Project @model { + projectId: ID! @primaryKey(sortKeyFields:["name"]) + name: String! + team: Team @hasOne + } + type Team @model { + teamId: ID! @primaryKey(sortKeyFields:["name"]) + name: String! + project: Project @belongsTo + } + `; + + const schemaBlogPostComment = /* GraphQL */ ` + type Blog @model { + blogId: String! @primaryKey + name: String! + posts: [Post!]! @hasMany + } + + type Post @model { + postId: ID! @primaryKey(sortKeyFields:["title"]) + title: String! + blog: Blog! @belongsTo + comments: [Comment]! @hasMany + } + + type Comment @model { + commentId: ID! @primaryKey(sortKeyFields:["content"]) + content: String! + post: Post! @belongsTo +} + `; + describe('DataStore Enabled', () => { it('Should generate for HasOneParent HasOneChild models', () => { const visitor = getVisitor(schemaHasOneParentChild, undefined, { isDataStoreEnabled: true }); @@ -127,6 +181,24 @@ describe('AppSyncModelVisitor', () => { expect(() => validateJava(generatedCode)).not.toThrow(); expect(generatedCode).toMatchSnapshot(); }); + it('should generate for Parent, HasOneChild, HasManyChild models', () => { + const visitor = getVisitor(schemaParentHasOneHasManyChild, undefined, { isDataStoreEnabled: true }); + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); + it('should generate for Project and Team models', () => { + const visitor = getVisitor(schemaProjectTeam, undefined, { isDataStoreEnabled: true }); + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); + it('should generate for Blog, Post, and Comment models', () => { + const visitor = getVisitor(schemaBlogPostComment, undefined, { isDataStoreEnabled: true }); + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); }); describe('API only', () => { @@ -150,6 +222,25 @@ describe('AppSyncModelVisitor', () => { expect(() => validateJava(generatedCode)).not.toThrow(); expect(generatedCode).toMatchSnapshot(); }); + + it('should generate for Parent, HasOneChild, HasManyChild models', () => { + const visitor = getVisitor(schemaParentHasOneHasManyChild) + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); + it('should generate for Project and Team models', () => { + const visitor = getVisitor(schemaProjectTeam); + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); + it('should generate for Blog, Post, and Comment models', () => { + const visitor = getVisitor(schemaBlogPostComment); + const generatedCode = visitor.generate(); + expect(() => validateJava(generatedCode)).not.toThrow(); + expect(generatedCode).toMatchSnapshot(); + }); }); }); From 0a0ff3d5abe1cf0f60d9d2285d21eacaeccc4328 Mon Sep 17 00:00:00 2001 From: Michael Law <1365977+lawmicha@users.noreply.github.com> Date: Fri, 29 Sep 2023 12:10:51 -0400 Subject: [PATCH 25/30] refactor join model preset code --- .../appsync-modelgen-plugin/src/preset.ts | 50 ++++++------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index ebf8932d7..dabe41c29 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -35,6 +35,7 @@ export type AppSyncModelCodeGenPresetConfig = { const generateJavaPreset = ( options: Types.PresetFnArgs, models: TypeDefinitionNode[], + manyToManyJoinModels: TypeDefinitionNode[], ): Types.GenerateOptions[] => { const config: Types.GenerateOptions[] = []; const modelFolder = options.config.overrideOutputDir @@ -82,38 +83,18 @@ const generateJavaPreset = ( }, }); } - - // Create ModelPath's for manyToMany's join model. - // Type cast to ObjectTypeDefinition to access `fields`. - if (model.kind === Kind.OBJECT_TYPE_DEFINITION) { - const modelObject = model as ObjectTypeDefinitionNode; - - // For each field, find all fields that are directives of type "manyToMany" - modelObject?.fields?.forEach(field => { - const manyToManyDirectives = field.directives?.filter(directive => directive.name.value === "manyToMany"); - - // For each "manyToMany" directive, find the "relationName" Argument's value. This is the name of the join model. - manyToManyDirectives?.forEach(manyToManyDirective => { - const argument = manyToManyDirective.arguments?.find(argument => argument.name.value === "relationName"); - if (argument?.value.kind === "StringValue") { - const stringValue = argument?.value as StringValueNode; - let joinModelName = graphqlName(toUpper(stringValue.value)); - - // Create the Join model's Model Path file. - config.push({ - ...options, - filename: join(...modelFolder, `${joinModelName}Path.java`), - config: { - ...options.config, - scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, - generate: 'metadata', - selectedType: joinModelName, - }, - }); - } - }); + manyToManyJoinModels.forEach(joinModel => { + config.push({ + ...options, + filename: join(...modelFolder, `${joinModel.name.value}Path.java`), + config: { + ...options.config, + scalars: {...JAVA_SCALAR_MAP, ...options.config.scalars}, + generate: 'metadata', + selectedType: joinModel.name.value, + }, }); - } + }); } }); @@ -337,13 +318,14 @@ export const preset: Types.OutputPreset = { (t.kind === 'ObjectTypeDefinition' && !typesToSkip.includes(t.name.value)) || (t.kind === 'EnumTypeDefinition' && !t.name.value.startsWith('__')), ) as any; + const manyToManyModels = generateManyToManyModelStubs(options); if (options.config.usePipelinedTransformer || options.config.transformerVersion === 2) { - models.push(...generateManyToManyModelStubs(options)); + models.push(...manyToManyModels); } - switch (codeGenTarget) { + switch (codeGenTarget) { case 'java': - return generateJavaPreset(options, models); + return generateJavaPreset(options, models, manyToManyModels); case 'swift': return generateSwiftPreset(options, models); case 'javascript': From a2b29aee02d762301f9933be0c54410205fa0a50 Mon Sep 17 00:00:00 2001 From: tjroach Date: Fri, 29 Sep 2023 15:43:40 -0400 Subject: [PATCH 26/30] PR comment --- packages/appsync-modelgen-plugin/src/preset.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index dabe41c29..8f2b0a444 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -43,7 +43,7 @@ const generateJavaPreset = ( : [options.baseOutputDir, ...GENERATED_PACKAGE_NAME.split('.')]; // Only generate lazy models if feature flag enabled and datastore is not being used. - const generateLazyModels = options.config.generateModelsForLazyLoadAndCustomSelectionSet && !options.config.isDataStoreEnabled + const generateAPILazyModels = options.config.generateModelsForLazyLoadAndCustomSelectionSet && !options.config.isDataStoreEnabled models.forEach(model => { const modelName = model.name.value; @@ -69,7 +69,7 @@ const generateJavaPreset = ( }); // Create ModelPath's only if lazy models are generated - if (generateLazyModels) { + if (generateAPILazyModels) { // Create ModelPath if type is @model if (model?.directives?.find((directive) => directive?.name?.value === 'model')) { config.push({ From 018d2534e6dd621c27cd89783820fa0d1411a42d Mon Sep 17 00:00:00 2001 From: tjroach Date: Fri, 29 Sep 2023 15:50:24 -0400 Subject: [PATCH 27/30] pr comment --- packages/appsync-modelgen-plugin/src/preset.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index 8f2b0a444..c2b95db44 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -4,7 +4,6 @@ import { join } from 'path'; import { JAVA_SCALAR_MAP, SWIFT_SCALAR_MAP, TYPESCRIPT_SCALAR_MAP, DART_SCALAR_MAP, METADATA_SCALAR_MAP } from './scalars'; import { LOADER_CLASS_NAME, GENERATED_PACKAGE_NAME } from './configs/java-config'; import { graphqlName, toUpper } from 'graphql-transformer-common'; -import { ObjectTypeDefinitionNode, StringValueNode } from "graphql/language/ast"; const APPSYNC_DATA_STORE_CODEGEN_TARGETS = ['java', 'swift', 'javascript', 'typescript', 'dart', 'introspection']; From bb6c5e79feda42da8ca2eeb9907e1c560ebabd50 Mon Sep 17 00:00:00 2001 From: tjroach Date: Tue, 3 Oct 2023 10:03:20 -0400 Subject: [PATCH 28/30] Fix unnecessary forEach iterations --- .../appsync-modelgen-plugin/src/preset.ts | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index c2b95db44..2a3c1c578 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -44,6 +44,17 @@ const generateJavaPreset = ( // Only generate lazy models if feature flag enabled and datastore is not being used. const generateAPILazyModels = options.config.generateModelsForLazyLoadAndCustomSelectionSet && !options.config.isDataStoreEnabled + // Class loader + config.push({ + ...options, + filename: join(...modelFolder, `${LOADER_CLASS_NAME}.java`), + config: { + ...options.config, + scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, + generate: 'loader', + }, + }); + models.forEach(model => { const modelName = model.name.value; config.push({ @@ -56,17 +67,6 @@ const generateJavaPreset = ( }, }); - // Class loader - config.push({ - ...options, - filename: join(...modelFolder, `${LOADER_CLASS_NAME}.java`), - config: { - ...options.config, - scalars: { ...JAVA_SCALAR_MAP, ...options.config.scalars }, - generate: 'loader', - }, - }); - // Create ModelPath's only if lazy models are generated if (generateAPILazyModels) { // Create ModelPath if type is @model @@ -82,21 +82,25 @@ const generateJavaPreset = ( }, }); } - manyToManyJoinModels.forEach(joinModel => { - config.push({ - ...options, - filename: join(...modelFolder, `${joinModel.name.value}Path.java`), - config: { - ...options.config, - scalars: {...JAVA_SCALAR_MAP, ...options.config.scalars}, - generate: 'metadata', - selectedType: joinModel.name.value, - }, - }); - }); } }); + // Create ModelPath's only if lazy models are generated + if (generateAPILazyModels) { + manyToManyJoinModels.forEach(joinModel => { + config.push({ + ...options, + filename: join(...modelFolder, `${joinModel.name.value}Path.java`), + config: { + ...options.config, + scalars: {...JAVA_SCALAR_MAP, ...options.config.scalars}, + generate: 'metadata', + selectedType: joinModel.name.value, + }, + }); + }); + }; + return config; }; From a0de4071d8dba8cbd2f6cd5ecc6a068b7c3b3a28 Mon Sep 17 00:00:00 2001 From: Tyler Roach Date: Wed, 4 Oct 2023 11:42:06 -0400 Subject: [PATCH 29/30] Update packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts Co-authored-by: Dane Pilcher --- .../src/visitors/appsync-java-visitor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index b9eba486d..1ca583ad4 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -38,7 +38,7 @@ export class AppSyncModelJavaVisitor< // We override lazy generation to also only generate lazy models if data store is disabled protected override isGenerateModelsForLazyLoadAndCustomSelectionSet(): boolean { - return super.isGenerateModelsForLazyLoadAndCustomSelectionSet() && !(this.config.isDataStoreEnabled ?? false); + return super.isGenerateModelsForLazyLoadAndCustomSelectionSet() && !this.config.isDataStoreEnabled; } generate(): string { From 676c0cb8f46395380ff0f7fea80c74d1b15b9779 Mon Sep 17 00:00:00 2001 From: tjroach Date: Wed, 4 Oct 2023 12:20:02 -0400 Subject: [PATCH 30/30] Only add targetNames for HasOne on Android if lazy load support enabled --- .../visitors/__snapshots__/appsync-java-visitor.test.ts.snap | 2 +- .../src/visitors/appsync-java-visitor.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap index 7a37765e7..b973bf217 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap @@ -468,7 +468,7 @@ public final class Project implements Model { public static final QueryField PROJECT_TEAM_NAME = field(\\"Project\\", \\"projectTeamName\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String projectId; private final @ModelField(targetType=\\"String\\", isRequired = true) String name; - private final @ModelField(targetType=\\"Team\\") @HasOne(associatedWith = \\"project\\", targetNames = {\\"projectTeamTeamId\\", \\"projectTeamName\\"}, type = Team.class) Team team = null; + private final @ModelField(targetType=\\"Team\\") @HasOne(associatedWith = \\"project\\", type = Team.class) Team team = null; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; private final @ModelField(targetType=\\"ID\\") String projectTeamTeamId; diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index 1ca583ad4..6a361e61c 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -1111,7 +1111,7 @@ export class AppSyncModelJavaVisitor< case CodeGenConnectionType.HAS_ONE: connectionDirectiveName = 'HasOne'; connectionArguments.push(`associatedWith = "${this.getFieldName(connectionInfo.associatedWith)}"`); - if (this.isCustomPKEnabled()) { + if (this.isCustomPKEnabled() && this.isGenerateModelsForLazyLoadAndCustomSelectionSet()) { const hasOneTargetNamesArgs = `targetNames = {${connectionInfo.targetNames.map(target => `"${target}"`).join(', ')}}`; connectionArguments.push(hasOneTargetNamesArgs); }