Git Product home page Git Product logo

aoudiamoncef / apollo-client-maven-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cox-automotive/apollo-client-maven-plugin

87.0 5.0 27.0 334 KB

Generate a Java/Kotlin GraphQL client based on introspection data and predefined queries.

License: MIT License

Kotlin 98.41% Shell 1.59%
apollo-client graphql graphql-tools graphql-java graphql-client maven-plugin query-generator query-builder graphql-query-builder apollographql apollo

apollo-client-maven-plugin's Introduction

Apollo GraphQL Client Code Generation Maven Plugin

Build Status Download Known Vulnerabilities License: MIT

Maven plugin that calls the Apollo Kotlin compiler to generate your Java/Kotlin sources.

Usage

Apollo 2 support

Getting Started

  1. Add the apollo runtime library to your project’s dependencies:

    <dependencies>
       <dependency>
           <groupId>com.apollographql.apollo3</groupId>
           <artifactId>apollo-runtime</artifactId>
           <version>3.8.2</version>
       </dependency>
    </dependencies>
  2. Add the code generator plugin to your project’s build:

    <plugins>
        <plugin>
            <groupId>com.github.aoudiamoncef</groupId>
            <artifactId>apollo-client-maven-plugin</artifactId>
            <version>7.0.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <services>
                            <example-api>
                                <compilationUnit>
                                    <name>example</name>
                                    <compilerParams>
                                        <schemaPackageName>com.example.graphql.client</schemaPackageName>
                                    </compilerParams>
                                </compilationUnit>
                            </example-api>
                        </services>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
  3. Create a file src/main/graphql/SERVICE_NAME/schema.json with the JSON results of an introspection query, OR you can automatically generate this file by setting introspection.enabled to true and endpointUrl to your GraphQL endpoint. At build time, the plugin will query the server and install this file per the value of schemaFile.

  4. Create files for each query you’d like to generate classes for under src/main/graphql/SERVICE_NAME:

    1. Query file names must match the name of the query they contain

    2. Query files must end with .graphql OR .gql by default.

    3. Any subdirectories under src/main/graphql/SERVICE_NAME are treated as extra package names to append to schemaPackageName in the plugin config.

  5. Run mvn generate-sources to generate classes for your queries.

  6. If you run into compilation issues such as package com.apollographql.apollo3.api does not exist, you may need to explicitly add the following runtime libraries to your pom.xml

    ---
    <dependency>
          <groupId>com.apollographql.apollo3</groupId>
          <artifactId>apollo-api-jvm</artifactId>
          <version>3.8.2</version>
    </dependency>
     <dependency>
        <groupId>com.apollographql.apollo3</groupId>
        <artifactId>apollo-runtime-jvm</artifactId>
        <version>3.8.2</version>
    </dependency>
    ---

Configuration Options

All plugin configuration properties and their defaults:

<configuration>
    <services>
        <!--Complete default configuration-->
        <lahzouz-complete-api>
            <enabled>true</enabled>
            <addSourceRoot>true</addSourceRoot>
            <addTestSourceRoot>false</addTestSourceRoot>
            <sourceFolder>${project.basedir}/src/main/graphql/lahzouz</sourceFolder>
            <schemaPath>${project.basedir}/src/main/graphql/lahzouz/schema.json</schemaPath>
            <includes>
                <include>**/*.graphql</include>
                <include>**/*.gql</include>
                <include>**/*.json</include>
                <include>**/*.sdl"</include>
            </includes>
            <excludes></excludes>
            <compilationUnit>
                <name>lahzouz</name>
                <outputDirectory>
                    ${project.build.directory}/generated-sources/graphql-client/lahzouz/
                </outputDirectory>
                <testDirectory>
                    ${project.build.directory}/generated-sources/graphql-client/lahzouz/test/
                </testDirectory>
                <debugDirectory>
                    ${project.build.directory}/generated-sources/graphql-client/lahzouz/debug/
                </debugDirectory>
                <generateOperationDescriptors>false</generateOperationDescriptors>
                <compilerParams>
                    <rootFolders>
                        <rootFolder>${project.basedir}/src/main/graphql/lahzouz/</rootFolder>
                    </rootFolders>
                    <scalarsMapping></scalarsMapping>
                    <operationIdGeneratorClass></operationIdGeneratorClass>
                    <operationManifestFormat>persistedQueryManifest</operationManifestFormat>
                    <schemaPackageName>com.lahzouz.apollo.graphql.client</schemaPackageName>
                    <packageName>com.lahzouz.apollo.graphql.client</packageName>
                    <codegenModels>OPERATION</codegenModels>
                    <flattenModels>true</flattenModels>
                    <generateApolloMetadata>false</generateApolloMetadata>
                    <generateAsInternal>false</generateAsInternal>
                    <generateFilterNotNull>false</generateFilterNotNull>
                    <generateFragmentImplementations>false</generateFragmentImplementations>
                    <generateKotlinModels>false</generateKotlinModels>
                    <generateOptionalOperationVariables>false</generateOptionalOperationVariables>
                    <generateQueryDocument>true</generateQueryDocument>
                    <generateResponseFields>false</generateResponseFields>
                    <generateSchema>false</generateSchema>
                    <generateTestBuilders>false</generateTestBuilders>
                    <generateDataBuilders>false</generateDataBuilders>
                    <generateModelBuilders>false</generateModelBuilders>
                    <nullableFieldStyle>NONE</nullableFieldStyle>
                    <useSemanticNaming>true</useSemanticNaming>
                    <targetLanguage>JAVA</targetLanguage>
                    <sealedClassesForEnumsMatching></sealedClassesForEnumsMatching>
                    <alwaysGenerateTypesMatching></alwaysGenerateTypesMatching>
                    <metadataOutputFile>
                        ${project.build.directory}/generated/metadata/apollo/lahzouz/metadata.json
                    </metadataOutputFile>
                </compilerParams>
            </compilationUnit>
            <introspection>
                <enabled>false</enabled>
                <endpointUrl></endpointUrl>
                <headers></headers>
                <schemaFile>${project.basedir}/src/main/graphql/lahzouz/schema.json</schemaFile>
                <connectTimeoutSeconds>10</connectTimeoutSeconds>
                <readTimeoutSeconds>10</readTimeoutSeconds>
                <writeTimeoutSeconds>10</writeTimeoutSeconds>
                <useSelfSignedCertificat>false</useSelfSignedCertificat>
                <useGzip>false</useGzip>
                <prettyPrint>false</prettyPrint>
            </introspection>
        </lahzouz-complete-api>

        <!--Minimal configuration-->
        <lahzouz-min-api>
            <compilationUnit>
                <name>lahzouz</name>
            </compilationUnit>
        </lahzouz-min-api>

        <!--Auto configuration-->
        <lahzouz></lahzouz>
    </services>
</configuration>

Custom Types

To use custom Scalar Types you need to define mapping configuration then register your custom adapter:

<configuration>
    ...
    <scalarsMapping>
        <Long>java.time.LocalDate</Long>
    </scalarsMapping>
    ...
</configuration>

Implementation of a custom adapter for java.time.LocalDate:

import com.apollographql.apollo3.api.Adapter;
import com.apollographql.apollo3.api.CustomScalarAdapters;
import com.apollographql.apollo3.api.json.JsonReader;
import com.apollographql.apollo3.api.json.JsonWriter;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class LocalDateGraphQLAdapter implements Adapter<LocalDate> {
    private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ISO_DATE;

    @Override
    public LocalDate fromJson(@NotNull final JsonReader reader, @NotNull final CustomScalarAdapters customScalarAdapters) throws IOException {
        String dateString = reader.nextString();
        return LocalDate.parse(dateString, dateFormatter);
    }

    @Override
    public void toJson(@NotNull final JsonWriter writer, @NotNull final CustomScalarAdapters customScalarAdapters, final LocalDate value) throws IOException {
        writer.value(value.format(dateFormatter));
    }
}
<configuration>
    ...
    <scalarsMapping>
        <Date>
            <targetName>java.time.LocalDate</targetName>
            <expression>new com.example.LocalDateGraphQLAdapter()</expression>
        </Date>
    </scalarsMapping>
    ...
</configuration>

Test Sources

To generate sources for tests:

<configuration>
    ...
    <addSourceRoot>false</addSourceRoot>
    <addTestSourceRoot>true</addTestSourceRoot>
    <compilationUnit>
        <name>example</name>
        <outputDirectory>${project.basedir}/target/generated-test-sources/apollo/example</outputDirectory>
        <debugDirectory>${project.basedir}/target/generated-test-sources/apollo/example/debug</debugDirectory>
        <testDirectory>${project.basedir}/target/generated-test-sources/apollo/example/debug</testDirectory>
    <compilationUnit/>
    ...
</configuration>

Using Apollo Client

apollo-client-maven-plugin's People

Contributors

aoudiamoncef avatar apottere avatar asashour avatar ddekkers avatar dependabot[bot] avatar jpastoor avatar mgrossmanexp avatar rruizt avatar ryangardner avatar sahilmgandhi avatar spencersteers avatar will-conductor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

apollo-client-maven-plugin's Issues

Error in generated classes while using apollo-runtime version 1.2.2

I am getting the following error in my generated classes

Class 'MyClass' must either be declared abstract or implement abstract method 
'parse(BufferedSource, ScalarTypeAdapters)' in 'Operation'

with the following apollo-runtime, and apollo-client-plugin versions.

<apollo-client-maven-plugin.version>2.2.0</apollo-client-maven-plugin.version>
<apollo-runtime.version>1.2.2</apollo-runtime.version>

Generated code works fine when using apollo-runtime version >=1.2.1
This issue seems to be due to a change in the signature of com.apollographql.apollo.api.Operation class between the two versions.

Add Support For Generating package-private Java

Hi. We're using this library for generating the internal implementation of a hand-crafted client. We'd like to be able to generate all the code into a single package and have all Java classes be package-private visibility. The reason is we are trying to limit what our users see when auto-completing in an IDE when they’ve use our client. We can generate the code into the same package as our hand-crafted classes, and it will be hidden from our users, but not from our hand-crafted implementation. Thanks.

Dynamically Modify Query Fields

Hi. This is not an issue so much as a question. We have an interesting case where we allow our customers to create custom fields on objects. For example, a user object might have "firstName" and "lastName", but for one customer it also has "nickname" and for another customer "phoneNumber". They can add whatever they like. When a customer retrieves metadata we use their customer id to look up their custom fields specific to the customer to populate the metadata with.

As you can imagine this doesn't work so well with generated query code. We can't generate code for every customer - even if we were willing to, the custom fields can be added at any time.

Can you advise if there is any area of the generated client code that would let us get in and modify the query string to inject these custom fields before it is sent over the wire, or perhaps to introduce some kind of decorator or subclass that we can add support for them? Thanks.

Issue with introspection query

You have to add the missing double cotes in introspection file
\"operationName\":introspection ->\"operationName\": \"introspection\"

That's all, please make a PR.

Plugin in execution not covered error with plugin

Planning to adopt this plugin for Java server application, when following the plugin instructions getting the following error. Any advice?

Plugin execution not covered by lifecycle configuration: com.github.sparow199:apollo-client-maven-plugin:3.0.3:generate (execution: default, phase: generate-sources)	pom.xml	/server	line 72	Maven Project Build Lifecycle Mapping Problem

Migration missed Getters and Builder as default builder

Migrating from:

<plugin>
				<groupId>com.github.aoudiamoncef</groupId>
				<artifactId>apollo-client-maven-plugin</artifactId>
				<version>4.0.5</version>
				<executions>
					<execution>
						<id>generate</id>
						<goals>
							<goal>generate</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<services>
						<api>
							<enabled>true</enabled>
							<addSourceRoot>true</addSourceRoot>
							<sourceFolder>${project.basedir}/src/main/resources/graphql</sourceFolder>
							<schemaPath>${project.basedir}/src/main/resources/graphql/schema.json</schemaPath>
							<includes>
								<include>**/*.graphql</include>
							</includes>
							<compilationUnit>
								<name>full-service</name>
								<outputDirectory>
									${project.build.directory}/generated-sources/graphql-client/myService/
								</outputDirectory>
								<compilerParams>
									<rootPackageName>com.myservice</rootPackageName>
									<generateOperationOutput>true</generateOperationOutput>
									<suppressRawTypesWarning>false</suppressRawTypesWarning>
									<useSemanticNaming>true</useSemanticNaming>
									<nullableValueType>JAVA_OPTIONAL</nullableValueType>
									<generateModelBuilder>true</generateModelBuilder>
									<useJavaBeansSemanticNaming>true</useJavaBeansSemanticNaming>
									<generateKotlinModels>false</generateKotlinModels>
									<generateVisitorForPolymorphicDatatypes>
										false
									</generateVisitorForPolymorphicDatatypes>
								</compilerParams>
							</compilationUnit>
						</api>
					</services>
				</configuration>
			</plugin>

to 5.0.0 and apolo 3.x.x Optional was lost, or not sure how to make it work :/

Previously Getter and Builders where generated but not sure how to do it now.

Thanks

Schema introspection query handling null defaults

I have a GraphQL scheme containing following definitions

input SomeType {
  id: String!
  title: String = null
  email: String = null
  reference: String = null
}

The given introspection query returns following for field reference

        {
          "name": "reference",
          "description": "Reference is invoice reference",
          "type": {
            "kind": "SCALAR",
            "name": "String",
            "ofType": null
          },
          "defaultValue": "null"
        },

The "defaultValue": "null" results in a Java object with the String "null". However, I expect he field to be null.

defaultValue should be null and not "null"

NullPointerException when Introspection is enabled

Hi, Im having a bit of trouble getting the client to work on my project. When trying to generate schema.json using introspection enabled I get the following error.

[DEBUG] Configuring mojo 'com.github.aoudiamoncef:apollo-client-maven-plugin:4.0.5:generate' with basic configurator -->
[DEBUG]   (f) project = MavenProject: <REDACTED>
[DEBUG]   (f) name = flatfile
[DEBUG]   (f) compilationUnit = com.github.aoudiamoncef.apollo.plugin.config.CompilationUnit@4ca37d40
[DEBUG]   (f) enabled = true
[WARNING] Map in class com.github.aoudiamoncef.apollo.plugin.GraphQLClientMojo declares value type as: class com.github.aoudiamoncef.apollo.plugin.config.Service but saw: null at runtime
[DEBUG]   (f) services = {test-api=null}
...

[ERROR] Failed to execute goal com.github.aoudiamoncef:apollo-client-maven-plugin:4.0.5:generate (default) on project data-loader-server: Execution default of goal com.github.aoudiamoncef:apollo-client-maven-plugin:4.0.5:generate failed.: NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.aoudiamoncef:apollo-client-maven-plugin:4.0.5:generate (default) on project data-loader-server: Execution default of goal com.github.aoudiamoncef:apollo-client-maven-plugin:4.0.5:generate failed.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default of goal com.github.aoudiamoncef:apollo-client-maven-plugin:4.0.5:generate failed.
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
Caused by: java.lang.NullPointerException
    at com.github.aoudiamoncef.apollo.plugin.GraphQLClientMojo.execute (GraphQLClientMojo.kt:64)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)


Configuration I'm using

<configuration>
    <services>
        <test-api>
            <compilationUnit>
                <name>test</name>
            </compilationUnit>
            <introspection>
                <enabled>true</enabled>
                <endpoint>redacted</endpoint>
            </introspection>
        </test-api>
    </services>
</configuration>

Could you shed some light on this?

Prettify output schema.json

Are there any concern to prettify the output schema.json instead of single long line?

Pros

  • Human readable
  • VCS Diff friendly

Cons

  • Larger in size

Possible to play nice with maven offline-dependencies?

after adding apollo-client-maven-plugin as a dependency on my pom.xml file, i cannot use maven offline dependency pattern.

e.g.

mvn dependency:go-offline
...
mvn --offline install
[INFO] --- apollo-client-maven-plugin:2.2.3:generate (default) @ project ---
[WARNING] The POM for org.apache.maven:maven-plugin-api:jar:3.6.0 is missing, no dependency information available
[WARNING] The POM for org.apache.maven:maven-project:jar:2.2.1 is missing, no dependency information available
[WARNING] The POM for com.apollographql.apollo:apollo-compiler:jar:1.2.3 is missing, no dependency information available
[WARNING] The POM for org.apache.httpcomponents:httpclient:jar:4.5.10 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------ 

I'm just starting to investigate this, but already posting here in case anyone have more insights already.

Error generating sources

the generated query class package is getting a period (.) at the end of the name

example:
// AUTO-GENERATED FILE. DO NOT MODIFY.
//
// This class was automatically generated by Apollo GraphQL plugin from the GraphQL queries it found.
// It should not be modified by hand.
//
package com.example.graphql.client.;

Some type mappings in <customTypeMap /> is ignored

Some of the custom mapping is ignored, for examples, mapping of "Int" is ignored.
Below is my mappings

<customTypeMap>
  <Int>java.lang.Integer</Int>
  <Float>java.math.BigDecimal</Float>
  <Boolean>java.lang.Boolean</Boolean>
  <String>java.lang.String</String>
  <ID>java.lang.String</ID>
  <Decimal>java.math.BigDecimal</Decimal>
  <Money>java.math.BigDecimal</Money>
  <UnsignedInt64>java.math.BigInteger</UnsignedInt64>
  <Date>java.time.ZonedDateTime</Date>
  <DateTime>java.time.ZonedDateTime</DateTime>
  <UtcOffset>java.time.ZoneOffset</UtcOffset>
  <FormattedString>java.lang.String</FormattedString>
  <HTML>java.lang.String</HTML>
  <JSON>java.lang.String</JSON>
  <StorefrontID>java.lang.String</StorefrontID>
  <URL>java.lang.String</URL>
  <ARN>java.lang.String</ARN>
</customTypeMap>

Could you please kindly help?

rootPackageName configuration seems ignored

The code is generated in the com.example.graphql.client, instead of using the configuration option rootPackageName. Am I missing something or is this a bug?

Currently using

        <apollo-client-maven-plugin.version>3.3.1</apollo-client-maven-plugin.version>
        <apollo-runtime.version>2.3.1</apollo-runtime.version>

with the following plugin configuration:

<plugin>
                <groupId>com.github.sparow199</groupId>
                <artifactId>apollo-client-maven-plugin</artifactId>
                <version>${apollo-client-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <rootPackageName>org.mycompany.xxx.graphql.client</rootPackageName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Generated sources have the com.example.graphql.client package. mvn clean and re-generate did not resolve the issue. (I'm pretty rusty when it comes to Java so good chance I'm doing something wrong here :) )

invalid url to introspection gist

there is a link in the docs to the introspection query: https://gist.github.com/Sparow199/a59527016e16a2d56309d62e01ff2348 but this gist does not exist

How to use in Spring Boot?

Hi, can you provide an example of how to use in Spring Boot? The dependencies don't work in that case.

Unable to get code to compile and resolve in kotlin

When the targetLanguage value is set to JAVA, and I run mvn clean verify -U, the introspection works, the code generates, and the tests pass. However, it doesn't compile when I configure the targetLanguage to KOTLIN_1_5. The project fails to compile with "Unresolved reference: graphql" and "Not enough information to infer type variable D" errors during the test-compile phase. Despite this, I'm able to run the tests in Intellij IDEA. The tests compile, run, and pass. After the tests have passed in the IDE, I can then run mvn verify from the command-line and the tests will pass until the next clean build.

  • This is part of a multi-module java + kotlin project, so I don't think the issue is with the maven-kotlin-plugin itself.
  • I've written a sanity test in the project. This is the class which runs into the import issues. I've tried moving this test to a child project, but I experience the same issues downstream.
  • I've tried swapping out the different runtime dependencies: apollo-runtime, apollo-runtime-jvm, and apollo-runtime-kotlin.
  • I've tried setting the kotlin plugin's language level and version to 1.5 in the parent pom.

apollo client maven plugin's pom.xml

    <dependencies>
        <dependency>
            <groupId>com.mycompany.testing</groupId>
            <artifactId>automation-common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.apollographql.apollo3</groupId>
            <artifactId>apollo-api</artifactId>
            <version>3.7.3</version>
        </dependency>
        <dependency>
            <groupId>com.apollographql.apollo3</groupId>
            <artifactId>apollo-runtime-jvm</artifactId>
            <version>3.7.3</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.github.aoudiamoncef</groupId>
                <artifactId>apollo-client-maven-plugin</artifactId>
                <version>5.0.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <services>
                                <myServer>
                                    <sourceFolder>${project.basedir}/src/main/graphql/myServer
                                    </sourceFolder>
                                    <schemaPath>
                                        ${project.basedir}/src/main/graphql/myServer/schema.json
                                    </schemaPath>
                                    <includes>
                                        <include>**/*.graphql</include>
                                        <include>**/*.gql</include>
                                        <include>**/*.json</include>
                                        <include>**/*.sdl</include>
                                    </includes>
                                    <compilationUnit>
                                        <name>myServer</name>

                                        <outputDirectory>
                                            ${project.build.directory}/generated-sources/graphql-client/myServer/
                                        </outputDirectory>
                                        <testDirectory>
                                            ${project.build.directory}/generated-sources/graphql-client/myServer/test/
                                        </testDirectory>
                                        <debugDirectory>
                                            ${project.build.directory}/generated-sources/graphql-client/myServer/debug/
                                        </debugDirectory>
                                        <operationOutputFile>
                                            ${project.build.directory}/generated/operationOutput/apollo/universe/operationOutput.json
                                        </operationOutputFile>
                                        <generateOperationDescriptors>true
                                        </generateOperationDescriptors>
                                        <compilerParams>
                                            <rootFolders>
                                                <rootFolder>
                                                    ${project.basedir}/src/main/graphql/myServer/
                                                </rootFolder>
                                            </rootFolders>
                                            <schemaPackageName>
                                                com.mycompany.automation.graphql.client
                                            </schemaPackageName>
                                            <packageName>com.mycompany.automation.graphql.client
                                            </packageName>
                                            <codegenModels>OPERATION</codegenModels>
                                            <flattenModels>true</flattenModels>
                                            <generateApolloMetadata>true</generateApolloMetadata>
                                            <generateAsInternal>true</generateAsInternal>
                                            <generateFilterNotNull>false</generateFilterNotNull>
                                            <generateFragmentImplementations>true
                                            </generateFragmentImplementations>
                                            <generateKotlinModels>true</generateKotlinModels>
                                            <generateOptionalOperationVariables>false
                                            </generateOptionalOperationVariables>
                                            <generateQueryDocument>true</generateQueryDocument>
                                            <generateResponseFields>false</generateResponseFields>
                                            <generateSchema>false</generateSchema>
                                            <generateTestBuilders>false</generateTestBuilders>
                                            <moduleName>apollographql</moduleName>
                                            <targetLanguage>KOTLIN_1_5</targetLanguage>
                                        </compilerParams>
                                    </compilationUnit>
                                    <introspection>
                                        <enabled>true</enabled>
                                        <endpointUrl>${introspection.endpoint.url}</endpointUrl>
                                        <schemaFile>${introspection.schema.file}</schemaFile>
                                        <prettyPrint>true</prettyPrint>
                                    </introspection>
                                </myServer>
                            </services>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

Parent pom's maven-plugin settings

      <plugin>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-maven-plugin</artifactId>
        <version>1.7.22</version>
        <executions>
          <execution>
            <id>compile</id>
            <goals>
              <goal>compile</goal>
            </goals>
            <configuration>
              <nowarn>true</nowarn>
              <sourceDirs>
                <sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
                <sourceDir>${project.basedir}/src/main/java</sourceDir>
              </sourceDirs>
            </configuration>
          </execution>

          <execution>
            <id>test-compile</id>
            <goals>
              <goal>test-compile</goal>
            </goals>
            <configuration>
              <sourceDirs>
                <sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
                <sourceDir>${project.basedir}/src/test/java</sourceDir>
              </sourceDirs>
            </configuration>
          </execution>
        </executions>
      </plugin>



org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.5.20:test-compile (test-compile) on project automation-graphql-support: Compilation failure
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:375)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:298)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.jetbrains.kotlin.maven.KotlinCompilationFailureException: Compilation failure
    at org.jetbrains.kotlin.maven.MavenPluginLogMessageCollector.throwKotlinCompilerException (MavenPluginLogMessageCollector.java:111)
    at org.jetbrains.kotlin.maven.KotlinCompileMojoBase.execute (KotlinCompileMojoBase.java:212)
    at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execute (K2JVMCompileMojo.java:222)
    at org.jetbrains.kotlin.maven.KotlinTestCompileMojo.execute (KotlinTestCompileMojo.java:84)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:298)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

Failed to fetch artifact apollo-compiler:jar:1.4.4 in central

When remove all the dependency from .m2 then run mvn clean -U install
Get following:
I checked the jcenter and cntral the artificat is no longer there, from the suggestion from apollo GraphQL adding repo (https://dl.bintray.com/apollographql/android/) could solve the problem.

[INFO] --- apollo-client-maven-plugin:2.4.2:generate (default) @ livrosud-platform-common-auth ---
Downloading from central: https://repo.maven.apache.org/maven2/com/apollographql/apollo/apollo-compiler/1.4.4/apollo-compiler-1.4.4.pom
Downloading from jcenter: https://jcenter.bintray.com/com/apollographql/apollo/apollo-compiler/1.4.4/apollo-compiler-1.4.4.pom
[WARNING] The POM for com.apollographql.apollo:apollo-compiler:jar:1.4.4 is missing, no dependency information available
Downloading from central: https://repo.maven.apache.org/maven2/com/apollographql/apollo/apollo-compiler/1.4.4/apollo-compiler-1.4.4.jar
Downloading from jcenter: https://jcenter.bintray.com/com/apollographql/apollo/apollo-compiler/1.4.4/apollo-compiler-1.4.4.jar



[ERROR] Failed to execute goal com.github.sparow199:apollo-client-maven-plugin:2.4.2:generate (default) on project livrosud-platform-common-auth: Execution default of goal com.github.sparow199:apollo-client-maven-plugin:2.4.2:generate failed: Plugin com.github.sparow199:apollo-client-maven-plugin:2.4.2 or one of its dependencies could not be resolved: Could not find artifact com.apollographql.apollo:apollo-compiler:jar:1.4.4 in central (https://repo.maven.apache.org/maven2) -> [Help 1]

Java classes not generated

To generate classes in Java.
I created a query named SampleTest in src/main/graphql/SampleTest.graphql
Then added schema.json in the same directory.
when I'm doing mvn compile or mvn generate-sources. The build is successful but doesnt generate classes.

I have placed the plugin thus:
<build> <pluginManagement> <plugins> <plugin> <groupId>com.github.aoudiamoncef</groupId> <artifactId>apollo-client-maven-plugin</artifactId> <version>4.0.5</version>

Failed to parse GraphQL file

Hello, i followed all the steps in the docs and i had an issue "Failed to parse GraphQL file /home/hany/java/projects-be/src/main/graphql/GetBooks.graphql (2:4)
[ERROR] Can't query books on type Query"
can you help me with it please ?

Disable Hostname verification

Hello,
I get an error with introspection over a secured graphql enpoint (https):

[ERROR] Certificate for <application.A.B.C> doesn't match any of the subject alternative names: [A.B.C, *.A.B.C] javax.net.ssl.SSLPeerUnverifiedException: Certificate for <application.A.B.C> doesn't match any of the subject alternative names: [A.B.C, *.A.B.C] at org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname (SSLConnectionSocketFactory.java:507) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket (SSLConnectionSocketFactory.java:437) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket (SSLConnectionSocketFactory.java:384) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect (DefaultHttpClientConnectionOperator.java:142) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect (PoolingHttpClientConnectionManager.java:376) at org.apache.http.impl.execchain.MainClientExec.establishRoute (MainClientExec.java:393) at org.apache.http.impl.execchain.MainClientExec.execute (MainClientExec.java:236) at org.apache.http.impl.execchain.ProtocolExec.execute (ProtocolExec.java:186) at org.apache.http.impl.execchain.RetryExec.execute (RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute (RedirectExec.java:110) at org.apache.http.impl.client.InternalHttpClient.doExecute (InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:83) at org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:108) at com.lahzouz.java.graphql.client.maven.plugin.Introspection.getIntrospectionSchema (Introspection.kt:30) at com.lahzouz.java.graphql.client.maven.plugin.GraphQLClientMojo.execute (GraphQLClientMojo.kt:121) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289) at org.apache.maven.cli.MavenCli.main (MavenCli.java:193) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:566) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347) at org.codehaus.classworlds.Launcher.main (Launcher.java:47)

Is this a bug?
Nevertherless there should be an option to disable hostname verification in particular, or event SSL verification in general.

Thanks.

apollo-client-maven-plugin:4.0.5:generate failed.: NullPointerException while generating Sources using Plugin

Hello Experts,
I am trying to explore Apollo Android Client for using it in my Java based Application. As a part of the POC, i was able to test different functionality like

  • Query
  • Mutation
  • Subscription
  • Pagination
    etc.

I built a Gradle based project and was generating the Models for different GraphQL files using grade build command.

However since our applications are Maven based, i was exploring a way to use maven to generate the sources.
Through the Apollo Community Forum thread https://community.apollographql.com/t/graphqljava-client-generating-models-on-the-fly-for-graphql-schema/3705/10 , I came to know about this plugin and hence i was trying my hands out to use this so as to generate the model. But i have been facing the following issue while executing mvn compile or mvn clean install

[ERROR] Failed to execute goal com.github.aoudiamoncef:apollo-client-maven-plugin:4.0.5:generate (default) on project graphql-client: Execution default of goal com.github.aoudiamon
cef:apollo-client-maven-plugin:4.0.5:generate failed.: NullPointerException -> [Help 1]
[ERROR]

I am trying to use the 4.0.5 version of the Plugin as suggested by Martin on the Forum, since we are using version 2.5.11 of Apollo Runtime.

Can you please let me know why i am getting this error. A sample snapshot of the project is located at https://github.com/ashudeep-sharma/graphql-client

Thanks in Advance!!

Exception handling an array of errors in call response

Hi, I am writing a simple mutation which generates service code that works fine when everything succeeds.

mutation CreateEntry($entries: [EntryInput!]!) {
  createEntry(input: $entries) {
    id
    // ... some fields
    start
    end
  }
}

The service returns errors as an array, which I thought was expected according to the specification. Unfortunately my response handling chokes on this. Is this a PBKAC? Am I able to configure something that allows Apollo to also expect error arrays in the response? (Present in version 3.3.1, apollo-runtime tested @2.3.1 & 2.4.1.) Thanks a bunch!

Caused by: com.apollographql.apollo.api.internal.json.JsonDataException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $.errors[59]
	at com.apollographql.apollo.api.internal.json.BufferedSourceJsonReader.beginObject(BufferedSourceJsonReader.kt:93)
	at com.apollographql.apollo.api.internal.json.ResponseJsonStreamReader.nextObject(ResponseJsonStreamReader.kt:58)
	at com.apollographql.apollo.response.OperationResponseParser$3.read(OperationResponseParser.java:129)
	at com.apollographql.apollo.response.OperationResponseParser$3.read(OperationResponseParser.java:127)
	at com.apollographql.apollo.api.internal.json.ResponseJsonStreamReader.nextList(ResponseJsonStreamReader.kt:74)
	at com.apollographql.apollo.response.OperationResponseParser.readResponseErrors(OperationResponseParser.java:127)
	at com.apollographql.apollo.response.OperationResponseParser.parse(OperationResponseParser.java:101)
	at com.apollographql.apollo.internal.interceptor.ApolloParseInterceptor.parse(ApolloParseInterceptor.java:87)
	... 6 more

Automatically run introspection query and build schema.json

I wonder if it would be possible to automatically run the introspection query against a given graphql endpoint prior to building the java apollo client. I believe the apollo cli can download the schema with something like apollo schema:download OUTPUT.

Is there anything limiting the ability to do this? Re-downloading the results of an introspection query and checking it in frequently as a manual process would be a nice workflow to automate.

Hi, is there an easy way to map GraphQL Int to Java Long type

Let's say the schema defines:
create_item("The new item's name." item_name: String, "The unique identifier." board_id: Int!, "The column values of the new item." column_values: JSON): Item

and the mutation is like:
mutation CreateItem ($boardId: Int!, $itemName: String!, $columnValues: JSON!) {create_item (board_id: $boardId, item_name: $itemName, column_values: $columnValues) {id}}

the Java bean (POJO) generated by the plugin is like:
public CreateItemMutation(Integer boardId, String itemName, Object columnValues) { this.boardId = boardId; this.itemName = itemName; this.columnValues = columnValues; }

So my question is how I can have the generated POJO which maps the boardId as Long type instead of integer type?

public CreateItemMutation(Long boardId, String itemName, Object columnValues) { this.boardId = boardId; this.itemName = itemName; this.columnValues = columnValues; }

I see the Gradle plugin has a configuration: mapScalar("Int", "Long"), does the Maven plugin has an equivalent one?

Update:
I tried:
<customScalarsMapping> <Int>java.lang.Long</Int> </customScalarsMapping>

but get error:

Execution default of goal com.github.aoudiamoncef:apollo-client-maven-plugin:5.0.0:generate failed: Apollo: unknown custom scalar(s) in customScalarsMapping: Int -> [Help 1]

Thank you!

Introspection schema downloading with graphql-java-servlet not work

hi!

i set up my graphql endpoint as:
<schemaUrl>http://localhost:9091/graphql</schemaUrl>
then i get:

Caused by: org.apache.maven.plugin.MojoExecutionException: Error, can't generate introspection schema file from: http://localhost:9091/graphql
    at com.lahzouz.java.graphql.client.maven.plugin.GraphQLClientMojo.execute (GraphQLClientMojo.kt:123)

the log on my console says:

graphql.execution.UnknownOperationException: Unknown operation named 'introspection'.

can you heal this, please?
(i'm using graphql-java-kickstart/graphql-java-servlet, so, if you simply send a GET request to "/graphql/schema.json", would be far enough, i think.)
(en fact, i implemented the same endpoint, which accepts POST requests (because graphql-java-servlet's works only with GET, damn! and you are sending POST with an introspeciton query), and it worked perfectly.)
(maybe the new methodology should be set up/activated with new configuration value(s)?)

thx, Ders

Cannot find the generated classes

To use the generated classes in Java.
I created a query named Info in src/main/graphql/Info.graphql
Then added schema.json in the same directory.
when I'm doing mvn compile or mvn generate-sources. The build is successful but I can't find the classes to import in my java code. where are they stored and are they actually being generated for me

How is <schemaUrlHeaders/> working ?

Hi, I want to genereate the schema.json file with introspection, i have my request in the right folder, working fine for a route without a needed header.

but when i want to set up the <schemaUrlHeaders> node i dont know how to use it. Is there a specific syntax?

Can you please guide me?

<plugin>
	<groupId>com.github.sparow199</groupId>
	<artifactId>apollo-client-maven-plugin</artifactId>
	<version>3.3.1</version>
	<executions>
		<execution>
			<goals>
				<goal>generate</goal>
			</goals>
			<configuration>
				<rootPackageName>api.graphql</rootPackageName>
				<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
				<generateIntrospectionFile>true</generateIntrospectionFile>
				<schemaUrl>http://remote.server:8080/graphql</schemaUrl>
				<schemaUrlHeaders></schemaUrlHeaders>
			</configuration>
		</execution>
	</executions>
</plugin>

here is my pom.xml plugin node

Query filter representing "match all"?

Hi, we're using the plugin to generate Java classes from our query specs, and it's very useful, thank you. However, I've got a question regarding (empty) query filters.

If I generate a query class Q with corresponding filter input class F, such that Q's ctor takes an F instance, then I can filter on field foo for some value f like so:

F.Builder filter = F.builder().foo(...builder().eq(f).build());
new Q(filter.build());

This is nice. However, if I'm trying to build my filter from a list of optional things over which I have no control, then I may have an empty filter, as if I had done:

F.Builder filter = F.builder();
new Q(filter.build());

This un-intuitively matches nothing on the server, whereas I would expect it to match everything.

The only way I can see to make this work is by making the filter be optional, such that Q's ctor takes an Input<F> instance, and using Input.absent() when there is nothing to filter on. However, this means I have to keep track of whether I have any actual things to use in a filter, which is messy. For example, if I have 4 things I can filter on in F, I have to use an Input.absent() if all of the things are null, and build an actual Input<F> otherwise.

Ideally, I would like an empty filter to match everything, but I don't know if that's a bug or a feature.

Or is there a better way?

Malformed POM Error with `services` tag

I tried to set up the plugin, but got this error when trying to run it:

Malformed POM D:\...\pom.xml: Unrecognised tag: 'services' (position: START_TAG seen ...</goals>\r\n<services>... @225:35)

What can I do here?

Can't parse `Int` value when set nullable int field to null

Failed to execute goal com.github.sparow199:apollo-client-maven-plugin:3.3.1:generate (default-cli) on project graphql-shared: Execution default-cli of goal com.github.sparow199:apollo-client-maven-plugin:3.3.1:generate failed: 
Failed to parse GraphQL file src\main\graphql\AbandonAccountConfUser.graphql (2:80)
Can't parse `Int` value
----------------------------------------------------
[1]:mutation AbandonAccountConfUser($accountId: Int) {
[2]:    update_conf_user(where: {account_id: {_eq: $accountId}}, _set: {account_id: null, state: abandoned}) {
[3]:        affected_rows
----------------------------------------------------

The above message is very clear, the account_id can't be null, but it's actually a valid graphql.

Java 19

I have been unable to generate any Java code that will compile or is usable (type safe) on Java 19 - I haven't tried any earlier version, so really this is just a question to ask if type safe Java 19 is supported at all?

Examples are scarce and I have exhausted the docs, which is why I've resorted to asking here.

Generated objects/fields on Interfaces/Implementations

Consider the following schema

type Test {
   items: [Item!]!
}

interface Item {
    id: String!
}

type ItemA implements Item {
    id: String!
    a: String!
}

type ItemB implements Item {
    id: String!
    b: String!
}

type Query {
    getTest: Test
}

Case 1
If we don't specify the concrete types on the query

getTest {
     items {
        id
     }
}

The java code for the items field is

List<Item>

Case 2
Once we specify the the concrete types on the query

getTest {
     items {
        id
       ... on ItemA {
          a
       }
       ... on ItemB {
          b
       }
     }
}

The java code for the items field is

Optional<List<Item>>

Actual: a field (non null) is optional, once concrete types are specified
Expected: a field (non null) is not optional, once concrete types are specified

Unable to generate classes for recursive tree structures

Hi,

I am having issues generating classes with below error. Would like to label this as a question.

Can't query Info on type Info
Sample

Info.graphqls
extend type Query {
listSomeInfo(userId: String!): [Info!]
}

type Info {
id: ID!
name: String!
desription: String!
children: [Info!]
parent: Info
}

Info.graphql
query (
$userId: String!
) {
listSomeInfo(
userId: $userId
) {
id
name
desription
children: Info {
id
name
children: Info {
id,
name
}
parent: Info {
id,
name
}
}
}
}

Failed to locate schema root node `__schema`

Hi, I'm running into this error "[ERROR] Failed to execute goal com.github.sparow199:apollo-client-maven-plugin:3.2.2:generate (default) on project xxx: Execution default of goal com.github.sparow199:apollo-client-maven-plugin:3.2.2:generate failed: Failed to parse GraphQL schema introspection query from /Users/rmeruva/xxx/src/main/graphql/schema.json: Failed to locate schema root node __schema -> [Help 1]"...Attaching the schema.json and query file (in txt format)
schema.txt
launchList.txt

I don't see this error when I use the schema provided in one of your examples(https://github.com/aoudiamoncef/spring-boot-mvc-apollo-graphql/tree/master/src/main/graphql).

Thanks

Originally posted by @rmeruva29 in #28 (comment)

lateinit property services has not been initialized

did tried to clone repository, open apollo-client-maven-plugin-tests in idea, comment some unnecessary parts from pox.xml and define plugin version to 4.0.4 as suggested in readme

after trying to perform apollo-client:generate maven task retrieving lateinit property services has not been initialized

full log
C:\Users\mac\.jdks\adopt-openjdk-14.0.2\bin\java.exe -Dmaven.multiModuleProjectDirectory=C:\Users\mac\Downloads\apollo-client-maven-plugin -Dmaven.home=C:\Users\mac\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\212.4746.92\plugins\maven\lib\maven3 -Dclassworlds.conf=C:\Users\mac\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\212.4746.92\plugins\maven\lib\maven3\bin\m2.conf -Dmaven.ext.class.path=C:\Users\mac\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\212.4746.92\plugins\maven\lib\maven-event-listener.jar -javaagent:C:\Users\mac\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\212.4746.92\lib\idea_rt.jar=61317:C:\Users\mac\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\212.4746.92\bin -Dfile.encoding=UTF-8 -classpath C:\Users\mac\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\212.4746.92\plugins\maven\lib\maven3\boot\plexus-classworlds-2.6.0.jar;C:\Users\mac\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\212.4746.92\plugins\maven\lib\maven3\boot\plexus-classworlds.license org.codehaus.classworlds.Launcher -Didea.version=2021.2 apollo-client:generate -e
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] 
[INFO] ------< com.github.aoudiamoncef:apollo-client-maven-plugin-tests >------
[INFO] Building apollo-client-maven-plugin-tests 4.0.4
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- apollo-client-maven-plugin:4.0.4:generate (default-cli) @ apollo-client-maven-plugin-tests ---
[INFO] Apollo GraphQL Client code generation task started
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.680 s
[INFO] Finished at: 2021-08-19T14:13:15+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.aoudiamoncef:apollo-client-maven-plugin:4.0.4:generate (default-cli) on project apollo-client-maven-plugin-tests: Execution default-cli of goal com.github.aoudiamoncef:apollo-client-maven-plugin:4.0.4:generate failed: lateinit property services has not been initialized -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.aoudiamoncef:apollo-client-maven-plugin:4.0.4:generate (default-cli) on project apollo-client-maven-plugin-tests: Execution default-cli of goal com.github.aoudiamoncef:apollo-client-maven-plugin:4.0.4:generate failed: lateinit property services has not been initialized
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:564)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal com.github.aoudiamoncef:apollo-client-maven-plugin:4.0.4:generate failed: lateinit property services has not been initialized
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:564)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property services has not been initialized
    at com.github.aoudiamoncef.apollo.plugin.GraphQLClientMojo.execute (GraphQLClientMojo.kt:63)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:564)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

Process finished with exit code 1

initially got the same on selenide project but decided to test everything in your test example

feel free to ask for any additional details will be happy to provide everything needed

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.