Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java code generated by amplify codegen is not compilable #231

Closed
4 tasks done
aladine opened this issue Aug 20, 2021 · 3 comments · Fixed by #260
Closed
4 tasks done

Java code generated by amplify codegen is not compilable #231

aladine opened this issue Aug 20, 2021 · 3 comments · Fixed by #260
Labels
bug Something isn't working Java Target language: Java model-gen Issues on datastore model generation

Comments

@aladine
Copy link

aladine commented Aug 20, 2021

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v16.1.0

Amplify CLI Version

5.3.0

What operating system are you using?

Mac OS

Amplify Codegen Command

codegen models

Describe the bug

My repo has only a simple schema.graphql file
After generate java file for Reference and ReferenceIdTypeEnum class, the Reference.java is not compilable.

Expected behavior

The generated code should compilable

Reproduction steps

  1. Run amplify codegen models in the same directory as schema.graphql
  2. Check the output directory
  3. Verify the class CopyOfBuilder is calling super.id() but there is no id() method in class.

GraphQL schema(s)

# Put schemas below this line
enum ReferenceIdTypeEnum {
    ASIN
    OBJECT_ID
}
type Reference {
    id: String!
    idType: ReferenceIdTypeEnum!
}

Log output


GraphQL schema compiled successfully.

Edit your schema at /Users/dantrong/workspace/src/androidMain/amplify/backend/api/cloudqueue/schema.graphql or place .graphql files in a directory at /Users/dantrong/workspace/src/androidMain/amplify/backend/api/cloudqueue/schema
App not deployed yet.
Successfully generated models. Generated models can be found in /Users/dantrong/workspace/src/androidMain/amplify/backend/api/cloudqueue/app/src/main/java



Additional information

Here is the generated java file for Reference.java

package com.amplifyframework.datastore.generated.model;


import androidx.core.util.ObjectsCompat;

import java.util.Objects;
import java.util.List;

/** This is an auto generated class representing the Reference type in your schema. */
public final class Reference {
  private final String id;
  private final ReferenceIdTypeEnum idType;
  public String getId() {
      return id;
  }
  
  public ReferenceIdTypeEnum getIdType() {
      return idType;
  }
  
  private Reference(String id, ReferenceIdTypeEnum idType) {
    this.id = id;
    this.idType = idType;
  }
  
  @Override
   public boolean equals(Object obj) {
      if (this == obj) {
        return true;
      } else if(obj == null || getClass() != obj.getClass()) {
        return false;
      } else {
      Reference reference = (Reference) obj;
      return ObjectsCompat.equals(getId(), reference.getId()) &&
              ObjectsCompat.equals(getIdType(), reference.getIdType());
      }
  }
  
  @Override
   public int hashCode() {
    return new StringBuilder()
      .append(getId())
      .append(getIdType())
      .toString()
      .hashCode();
  }
  
  public static IdTypeStep builder() {
      return new Builder();
  }
  
  public CopyOfBuilder copyOfBuilder() {
    return new CopyOfBuilder(id,
      idType);
  }
  public interface IdTypeStep {
    BuildStep idType(ReferenceIdTypeEnum idType);
  }
  

  public interface BuildStep {
    Reference build();
  }
  

  public static class Builder implements IdTypeStep, BuildStep {
    private String id;
    private ReferenceIdTypeEnum idType;
    @Override
     public Reference build() {
        
        return new Reference(
          id,
          idType);
    }
    
    @Override
     public BuildStep idType(ReferenceIdTypeEnum idType) {
        Objects.requireNonNull(idType);
        this.idType = idType;
        return this;
    }
  }
  

  public final class CopyOfBuilder extends Builder {
    private CopyOfBuilder(String id, ReferenceIdTypeEnum idType) {
      super.id(id)
        .idType(idType);
    }
    
    @Override
     public CopyOfBuilder id(String id) {
      return (CopyOfBuilder) super.id(id);
    }
    
    @Override
     public CopyOfBuilder idType(ReferenceIdTypeEnum idType) {
      return (CopyOfBuilder) super.idType(idType);
    }
  }
  
}

@AaronZyLee AaronZyLee added Java Target language: Java model-gen Issues on datastore model generation labels Aug 20, 2021
@AaronZyLee AaronZyLee added the bug Something isn't working label Sep 30, 2021
@aladine
Copy link
Author

aladine commented Apr 11, 2022

The issue still exists. When running with the latest awsamplify-cli (npm i -g @aws-amplify/cli at 8.0.0), there is no IdStep interface in the generated file.

@AaronZyLee
Copy link
Contributor

@aladine Could you check out your amplify/cli.json file for the following key-value? The expected value should be as following.

{
  "features": {
    "codegen": {
      "useappsyncmodelgenplugin": true
    }
  }
}

@aladine
Copy link
Author

aladine commented Apr 12, 2022

Thank you, @AaronZyLee.
Surprisingly it works now. I can see my output file generated exactly as the test case in #260

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Java Target language: Java model-gen Issues on datastore model generation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants