Git Product home page Git Product logo

Comments (7)

aoudiamoncef avatar aoudiamoncef commented on June 19, 2024

Hi @ckwong-jebsen
You have to create your own adapter:

       val longCustomTypeAdapter = object : CustomTypeAdapter<Long> {
            override fun encode(value: Long): CustomTypeValue<*> {
                return value.toString() as CustomTypeValue<String>
            }

            override fun decode(value: CustomTypeValue<*>): Long {
                return (value.value as BigDecimal).toLong()
            }
        }

from apollo-client-maven-plugin.

dryst0 avatar dryst0 commented on June 19, 2024
<customTypeMap>
    <DateTime>java.time.LocalDateTime</DateTime>
    <GeoJSONString>java.lang.String</GeoJSONString>
</customTypeMap>

I also encountered the same problem. When it is generating CustomType.java file, it doesn't include the GeoJSONString CustomType.

Here's a snippet of my schema.json file

{
...
},
{
    "kind": "SCALAR",
    "name": "GeoJSONString",
    "description": "A GeoJSON formatted String.\n\n\nCurrently only supports Point GeoJSON type.\n\ne.g.\n\n\"{\n    \"type\": \"Point\",\n    \"coordinates\": [125.6, 10.1]\n}\"\n\n\nSupport for LineString GeoJSON type is under development.\n\n\n\nPlease see https://geojson.org for more info.",
    "fields": null,
    "inputFields": null,
    "interfaces": null,
    "enumValues": null,
     "possibleTypes": null
},
{
...
}

I also tried your suggestion in providing a CustomTypeAdapter but still didn't include the GeoJSONString CustomTypeMap in CustomType.java file upon generation.

public enum CustomType implements ScalarType {
  DATETIME {
    @Override
    public String typeName() {
      return "DateTime";
    }

    @Override
    public String className() {
      return "java.time.LocalDateTime";
    }
  },

  ID {
    @Override
    public String typeName() {
      return "ID";
    }

    @Override
    public String className() {
      return "java.lang.String";
    }
  }
}

Please advise if I did something wrong on my end or recommend how should I be able to fix it.

By the way, appreciate what you did with this plugin, it's a huge lifesaver for one of the projects that I'm involved in.

from apollo-client-maven-plugin.

aoudiamoncef avatar aoudiamoncef commented on June 19, 2024

Hi @dryst0,
have you added adapter's to your ApolloClient instance ?

ApolloClient.builder()
  .serverUrl(serverUrl)
  .addCustomTypeAdapter(CustomType.DATE, dateCustomTypeAdapter)
  .build()

from apollo-client-maven-plugin.

dryst0 avatar dryst0 commented on June 19, 2024

Hi @dryst0,
have you added adapter's to your ApolloClient instance ?

ApolloClient.builder()
  .serverUrl(serverUrl)
  .addCustomTypeAdapter(CustomType.DATE, dateCustomTypeAdapter)
  .build()

Yes, I have also added the custom type adapters to my apolloClient

ApolloClient apolloClient = ApolloClient.builder().serverUrl(impressionsEndpoint)
                .addCustomTypeAdapter(CustomType.DATETIME, dateTimeAdapter)
                .addCustomTypeAdapter(CustomType.GEOJSONSTRING, geojsonCustomTypeAdapter).okHttpClient(client).build();

Only CustomType.DATETIME was included in the auto-generated class file. CustomType.GEOJSONSTRING doesn't exist and therefore my build is failing.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project common: Compilation failure
[ERROR] <redacted> cannot find symbol
[ERROR]   symbol:   variable GEOJSONSTRING
[ERROR]   location: class m.m.m.graphql.client.type.CustomType

from apollo-client-maven-plugin.

aoudiamoncef avatar aoudiamoncef commented on June 19, 2024

I'll try to add a test for this case in next release.

I think that you have to report this issue to the main project which is Apollo Android

It could be an issue with Apollo compiler

thanks

from apollo-client-maven-plugin.

dryst0 avatar dryst0 commented on June 19, 2024

I think that you have to report this issue to the main project which is Apollo Android

Alright. I'll also raise an issue there as well.

Do you have any suggestions to work around this issue in the meanwhile?

I am thinking of copying the generated-sources back to main directory and manually adding the CustomType.GEOJSONSTRING in CustomType.java and commenting out this maven plugin for now until the issue gets resolved.

Thank you also for the quick response.

from apollo-client-maven-plugin.

dryst0 avatar dryst0 commented on June 19, 2024

Just wanted to refer the post-mortem report regarding the issue I've raised here.

apollographql/apollo-kotlin#2721 (comment)

TLDR; Multiple execution section under the same plugin which writes the output on the same directory and overwrites the CustomType.java

Also, thanks for all the help!

from apollo-client-maven-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.