Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions graphql-jpa-query-example-merge/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3.2"
services:
gpaphql-jpa-query-example-merge:
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
ports:
- 8080:8080
image: introproventures/graphql-jpa-query-example-merge:latest
networks:
- application
networks:
application:
driver: overlay
135 changes: 135 additions & 0 deletions graphql-jpa-query-example-merge/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>graphql-jpa-query-example-merge</artifactId>
<name>graphql-jpa-query-example-merge</name>

<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-build</artifactId>
<version>0.3.14-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-build</relativePath>
</parent>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>

<dependency>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-web</artifactId>
</dependency>

<dependency>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-schema</artifactId>
</dependency>

<dependency>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-autoconfigure</artifactId>
</dependency>

<dependency>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-autoconfigure</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

</dependencies>

<build>

<finalName>${project.artifactId}</finalName>

<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.6.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.14</version>
<dependencies>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>push-image</id>
<phase>deploy</phase>
<goals>
<goal>push</goal>
</goals>
<configuration>
<pushImage>true</pushImage>
</configuration>
</execution>
</executions>
<configuration>
<serverId>docker-hub</serverId>
<registryUrl>https://index.docker.io/v1/</registryUrl>
<imageName>introproventures/${project.artifactId}</imageName>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>

<!-- optionally overwrite tags every time image is built with docker:build -->
<forceTags>true</forceTags>
<imageTags>
<imageTag>${project.version}</imageTag>
<imageTag>latest</imageTag>
</imageTags>

</configuration>

</plugin>

</plugins>
</build>
</project>
12 changes: 12 additions & 0 deletions graphql-jpa-query-example-merge/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM openjdk:8-jdk-alpine

VOLUME /var/log/
VOLUME /tmp

EXPOSE 8080

ADD graphql-jpa-query-example-merge.jar app.jar

ENV JAVA_OPTS=""

ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2017 IntroPro Ventures, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.introproventures.graphql.jpa.query.example;

import com.introproventures.graphql.jpa.query.schema.GraphQLExecutor;
import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor;
import graphql.schema.GraphQLSchema;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
* GraphQL JPA Query Example with Spring Boot Autoconfiguration
*
* You can configure GraphQL JPA Query properties in application.yml
*
* @author Igor Dianov
*
*/
@SpringBootApplication
@EnableTransactionManagement
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

@Bean
public GraphQLExecutor graphQLExecutor(GraphQLSchema graphQLSchema) {
return new GraphQLJpaExecutor(graphQLSchema);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2017 IntroPro Ventures Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.introproventures.graphql.jpa.query.example.books;

import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import lombok.Data;

@Data
@Entity
public class Author {
@Id
Long id;

String name;

@OneToMany(mappedBy="author")
Collection<Book> books;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2017 IntroPro Ventures Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.introproventures.graphql.jpa.query.example.books;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import lombok.Data;

@Data
@Entity
public class Book {
@Id
Long id;

String title;

@ManyToOne
Author author;

@Enumerated(EnumType.STRING)
Genre genre;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.introproventures.graphql.jpa.query.example.books;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import com.introproventures.graphql.jpa.query.autoconfigure.GraphQLSchemaConfigurer;
import com.introproventures.graphql.jpa.query.autoconfigure.GraphQLShemaRegistration;
import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaSchemaBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.H2Dialect;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;

@Configuration
public class BooksSchemaConfiguration {

@Bean
@ConfigurationProperties(prefix = "books")
@Qualifier("bookDataSource")
public DataSource bookDataSource() {
return DataSourceBuilder.create()
.build();
}

@Bean
@Qualifier("bookEntityManager")
public LocalContainerEntityManagerFactoryBean bookEntityManagerFactory(
EntityManagerFactoryBuilder builder) {
Map<String, Object> properties = new HashMap<>();
properties.put(AvailableSettings.HBM2DDL_AUTO, "create-drop");
properties.put(AvailableSettings.HBM2DLL_CREATE_SCHEMAS, "true");
properties.put(AvailableSettings.DIALECT, H2Dialect.class.getName());
properties.put(AvailableSettings.SHOW_SQL, "true");
properties.put(AvailableSettings.FORMAT_SQL, "true");

return builder
.dataSource(bookDataSource())
.packages(Book.class)
.persistenceUnit("books")
.properties(properties)
.build();
}

@Bean
public DataSourceInitializer booksDataSourceInitializer(@Qualifier("bookDataSource") DataSource bookDataSource) {
DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
ResourceLoader resourceLoader = new DefaultResourceLoader();

ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
databasePopulator.addScript(resourceLoader.getResource("books.sql"));

dataSourceInitializer.setDataSource(bookDataSource);
dataSourceInitializer.setDatabasePopulator(databasePopulator);

return dataSourceInitializer;
}


@Configuration
public static class GraphQLJpaQuerySchemaConfigurer implements GraphQLSchemaConfigurer {

private final EntityManager entityManager;

public GraphQLJpaQuerySchemaConfigurer(@Qualifier("bookEntityManager") EntityManagerFactory entityManager) {
this.entityManager = entityManager.createEntityManager();
}

@Override
public void configure(GraphQLShemaRegistration registry) {

registry.register(new GraphQLJpaSchemaBuilder(entityManager).name("GraphQLBooks").build());
}
}

}
Loading