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

"notify" field name does not compile #42

Closed
martinreilent opened this issue Jul 16, 2024 · 5 comments
Closed

"notify" field name does not compile #42

martinreilent opened this issue Jul 16, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@martinreilent
Copy link

STR:

  1. Kobby plugin section in pom.xml
<plugin>
  <groupId>io.github.ermadmi78</groupId>
  <artifactId>kobby-maven-plugin</artifactId>
  <version>4.0.1</version>
  <configuration>
      <schema>
          <scan>
              <includes>
                  <include>**/*.graphqls</include>
                  <include>**/*.graphql</include>
              </includes>
          </scan>
      </schema>
      <kotlin>
          <packageName>generated</packageName>
          <outputDirectory>src/main/kotlin</outputDirectory>
      </kotlin>
  </configuration>
</plugin>
  1. Schema
type Mutation {
  editThing( notify: Boolean! ): Thing
}

type Thing {
  field: String!
  field2: Int!
  notify: Boolean!
}
  1. Run
mvn clean kobby:generate-kotlin && mvn clean compile

Expected
No errors

Actual
[ERROR] .../src/main/kotlin/generated/entity/Thing.kt: (44, 3) Accidental override: The following declarations have the same JVM signature (notify()V):
fun notify(): Unit defined in generated.entity.ThingProjection
[ERROR] .../src/main/kotlin/generated/entity/impl/ThingImpl.kt: (116, 3) Accidental override: The following declarations have the same JVM signature (notify()V):
fun notify(): Unit defined in generated.entity.impl.ThingProjectionImpl


Problem seems to be with creating projections of fields that are with same name as java.lang.Object functions.
Possible workaround currently is to prefix all projection fields

...
<!-- Prefix for projection fields -->
<!-- that are not marked with the directive `@default` -->
<withPrefix></withPrefix>
...

but this looks ugly in the end.

@ermadmi78 ermadmi78 self-assigned this Jul 16, 2024
@ermadmi78 ermadmi78 added the bug Something isn't working label Jul 16, 2024
@ermadmi78
Copy link
Owner

I think that is best to fix in the same style as here #21

@ermadmi78
Copy link
Owner

In addition, it will be necessary to correct all the names of the methods java.lang.Object

@ermadmi78
Copy link
Owner

The temporary workaround is to use kotlin.entity.projection.withPrefix or kotlin.entity.projection.withPostfix plugin settings.

Gradle example:

plugins {
    id("io.github.ermadmi78.kobby") version "4.0.1"
}

kobby {
    kotlin {
        entity {
            projection {
                withPrefix = "with"
            }
        }
    }
}

Maven example:

<plugin>
     <groupId>io.github.ermadmi78</groupId>
     <artifactId>kobby-maven-plugin</artifactId>
     <version>4.0.1</version>
     <executions>
         <execution>
             <phase>generate-sources</phase>
             <goals>
                 <goal>generate-kotlin</goal>
             </goals>
             <configuration>
                 <kotlin>
                     <entity>
                         <projection>
                             <withPrefix>with</withPrefix>
                         </projection>
                     </entity>
                 </kotlin>
             </configuration>
         </execution>
     </executions>
 </plugin>

This plugin setting will add "with" prefix to all generated projection methods.

@ermadmi78
Copy link
Owner

The problem is reproduced for all names that match java.lang.Object method names:

  • getClass
  • hashCode
  • equals
  • clone
  • toString
  • notify
  • notifyAll
  • wait
  • finalize

To fix this problem, Kobby will automatically add prefix "__" to all forbidden projection names.

For example, for type:

type Query {
    getClass: Boolean!
    hashCode: Boolean!
    equals: Boolean!
    clone: Boolean!
    toString: Boolean!
    notify: Boolean!
    notifyAll: Boolean!
    wait: Boolean!
    finalize: Boolean!

    normal: Boolean!
}

Kobby will generate projection:

public interface QueryProjection {
  public fun __getClass(): Unit

  public fun __hashCode(): Unit

  public fun __equals(): Unit

  public fun __clone(): Unit

  public fun __toString(): Unit

  public fun __notify(): Unit

  public fun __notifyAll(): Unit

  public fun __wait(): Unit

  public fun __finalize(): Unit

  public fun normal(): Unit

  public fun __minimize(): Unit {
  }
}

@ermadmi78
Copy link
Owner

Fixed in release 4.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants