aoudiamoncef / apollo-client-maven-plugin

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use in Spring Boot?

SledgeHammer01 opened this issue · comments

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

Hi @SledgeHammer01,
I tried the latest version with Spring Boot 2.2.2 and it works without any issue.
Try to remove com.sparow199 jars from your Maven local repository and re-sync.

Hi @SledgeHammer01,
I tried the latest version with Spring Boot 2.2.2 and it works without any issue.
Try to remove com.sparow199 jars from your Maven local repository and re-sync.

Hi,

I am pretty new to Spring. This is a new Spring project. I was trying to follow the pom in the test app, but in that case I am using the spring-boot-starter-parent as the parent. I wasn't able to save my pom successfully as the specified jars were not found.

Can you possibly share your pom and/or perhaps even the sample project you just tried?

Thanks!

I will did it tomorrow, I haven't the source now, I'll try to add a simple spring boot example.

On Mon, Jan 6, 2020, 23:49 SledgeHammer01 @.***> wrote: Hi @SledgeHammer01 https://github.com/SledgeHammer01, I tried the latest version with Spring Boot 2.2.2 and it works without any issue. Try to remove com.sparow199 jars from your Maven local repository and re-sync. Hi, I am pretty new to Spring. This is a new Spring project. I was trying to follow the pom in the test app, but in that case I am using the spring-boot-starter-parent as the parent. I wasn't able to save my pom successfully as the specified jars were not found. Can you possibly share your pom and/or perhaps even the sample project you just tried? Thanks! — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#18?email_source=notifications&email_token=AFJ7ZUQMMUKX43F2CB25GD3Q4OYPHA5CNFSM4KDK3522YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIHBZ3Q#issuecomment-571350254>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJ7ZUSQQU4AD67RHNC5S23Q4OYPHANCNFSM4KDK352Q .

Awesome, that would be great! Thanks!

I will did it tomorrow, I haven't the source now, I'll try to add a simple spring boot example.

On Mon, Jan 6, 2020, 23:49 SledgeHammer01 @.***> wrote: Hi @SledgeHammer01 https://github.com/SledgeHammer01, I tried the latest version with Spring Boot 2.2.2 and it works without any issue. Try to remove com.sparow199 jars from your Maven local repository and re-sync. Hi, I am pretty new to Spring. This is a new Spring project. I was trying to follow the pom in the test app, but in that case I am using the spring-boot-starter-parent as the parent. I wasn't able to save my pom successfully as the specified jars were not found. Can you possibly share your pom and/or perhaps even the sample project you just tried? Thanks! — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#18?email_source=notifications&email_token=AFJ7ZUQMMUKX43F2CB25GD3Q4OYPHA5CNFSM4KDK3522YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIHBZ3Q#issuecomment-571350254>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJ7ZUSQQU4AD67RHNC5S23Q4OYPHANCNFSM4KDK352Q .

Hi, I have made some progress after many hours... here is my current pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>org.mycompany</groupId>
	<artifactId>xxx-Test</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>xxx-Test</name>
	<description>xxx Tester</description>
	<properties>
		<java.version>13</java.version>
	</properties>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.2.2.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	<repositories>
		<repository>
			<id>jcenter</id>
			<url>https://jcenter.bintray.com/</url>
		</repository>
	</repositories>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-webflux</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.security</groupId>
			<artifactId>spring-security-oauth2-client</artifactId>
		</dependency>
		<dependency>
			<groupId>com.google.guava</groupId>
			<artifactId>guava</artifactId>
			<version>28.1-jre</version>
		</dependency>
		<dependency>
			<groupId>com.apollographql.apollo</groupId>
			<artifactId>apollo-runtime</artifactId>
			<version>1.2.2</version>
		</dependency>
	</dependencies>
	<build>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-maven-plugin</artifactId>
				</plugin>
				<plugin>
					<groupId>com.github.sparow199</groupId>
					<artifactId>apollo-client-maven-plugin</artifactId>
					<version>2.2.3-SNAPSHOT</version>
					<executions>
						<execution>
							<goals>
								<goal>generate</goal>
							</goals>
							<configuration>
								<skip>false</skip>
								<addSourceRoot>true</addSourceRoot>
								<generateIntrospectionFile>false</generateIntrospectionFile>
								<sourceDirName>${project.basedir}/src/main/resources/graphql</sourceDirName>
								<introspectionFile>${project.basedir}/src/main/resources/graphql/schema.json</introspectionFile>
								<generateTransformedQueries>false</generateTransformedQueries>
								<transformedQueriesOutputDir>${project.build.directory}/generated-sources/graphql-client/transformed</transformedQueriesOutputDir>
								<rootPackageName>org.mycompany.xxx.graphql.client</rootPackageName>
								<outputDirectory>${project.build.directory}/generated-sources/graphql-client</outputDirectory>
								<generateModelBuilder>true</generateModelBuilder>
								<useJavaBeansSemanticNaming>true</useJavaBeansSemanticNaming>
								<useSemanticNaming>true</useSemanticNaming>
								<nullableValueType>JAVA_OPTIONAL</nullableValueType>
								<suppressRawTypesWarning>false</suppressRawTypesWarning>
								<generateKotlinModels>false</generateKotlinModels>
								<generateAsInternal>false</generateAsInternal>
								<generateVisitorForPolymorphicDatatypes>false</generateVisitorForPolymorphicDatatypes>
								<customTypeMap>
									<Long>java.lang.Long</Long>
								</customTypeMap>
							</configuration>
						</execution>
					</executions>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>
</project>

src/main/resources/graphql:

schema.json
getAllCustomers.graphql

I'm using STS4 on Windows 10, I right click on the project and run a maven build with the goals: clean generate-sources

Output is:

[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< org.xxx:xxx-Test >---------------------
[INFO] Building xxx-Test 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ xxx-Test ---
[INFO] Deleting C:\Users\xxx\Workspaces\xxx\xxx-Test\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.327 s
[INFO] Finished at: 2020-01-06T21:00:55-08:00
[INFO] ------------------------------------------------------------------------

Doesn't seem to be generating any classes. Any ideas?

Thanks again for the help!

Hi @SledgeHammer01,
I started a Spring Boot project, it compiles and generate the queries without any issues.

Hi @SledgeHammer01,
I started a Spring Boot project, it compiles and generate the queries without any issues.

I tried switching my project to Gradle and had the same issue. I think setting the schema and query locations to anything other then /src/main/graphql is broken on their end :(. I tried moving them to stock location and it still didn't work with the Maven plugin, so I ended up switching to the Gradle one due to time constraints. The other thing I noticed under the Gradle plugin was that it was complaining it about Anonymous queries. Not sure if that was the Maven problem too, but the Maven plugin didn't report any errors, so not sure what happened.

Thanks again for the help and the sample! :)

Hi @SledgeHammer01,
I started a Spring Boot project, it compiles and generate the queries without any issues.

As I mentioned above, the Apollo Client in Gradle had the same issues with the non standard paths, so if you ported that one, the functionality doesn't work there either :(.

I then tried the new incubating plugin since they are deprecating the gradle one, and that one, all the functionality for different paths and specifying namespaces, etc. seems to be working. They re-wrote it from scratch in Kt.

Thanks again for the assistance!

@aoudiamoncef

Is it safe to use this maven plugin in production spring boot applications?

Hi @priyankaa-patil,
I'm using it in production, it's used only at compile time.

@aoudiamoncef
Thanks for quick reply.
I will give it a try using maven plugin

I'm working on a complete rewriting based on Gradle official plugin with the latest versions of all dependencies. stay tuned

Have you used this maven plugin in production or gradle plugin ?
Just want to make sure if there are any major issues to be considered with maven plugin before using it.

I don't use Gradle in production, so I use this projet to generate my client.

Hi @SledgeHammer01,
I started a Spring Boot project, it compiles and generate the queries without any issues.

@aoudiamoncef

I tried using maven plugin as mentioned in above project.
But its not clear how to call Graphql API to get response.

Can you explain me that?

@priyankaa-patil

take a look at Apollo Android documentation.