Example project using Spring Data Neo4j and Spring GraphQL
== Spring GraphQL with Spring Data Neo4j
This example project shows how to combine https://docs.spring.io/spring-graphql/docs/1.2.0/reference/html/[Spring GraphQL 1.2.0] with https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#reference[Spring Data Neo4j 7.1.0]. The project itself is based on Spring Boot 3.1 to make use of some very nice improvements.
=== Planned features / tasks for this example
=== Some features and libraries used in this example
==== New Testcontainers support features
@ServiceConnection
: https://docs.spring.io/spring-boot/docs/3.1.x/reference/htmlsingle/#features.testing.testcontainers.service-connections
@ImportTestcontainers
: https://docs.spring.io/spring-boot/docs/3.1.x/reference/htmlsingle/#features.testing.testcontainers.at-development-time.importing-container-declarations
==== Neo4j-Migrations for test data creation
Starting the application from the tests or running integration tests, the project will use https://github.com/michael-simons/neo4j-migrations[Neo4j-Migrations] to create the initial dataset.
==== Neo4j Java driver metrics / health
===== Micrometer metrics
Although the current version of the Neo4j Java driver is 5.7.,
the Spring Boot autoconfiguration is backwards compatible to the whole 4.x versions.
As a consequence, it cannot configure the metrics provider automatically and we need to provide a ConfigBuilderCustomizer
to set Micrometer
as the adapter.
This will provide following metrics to consume. Accessible via http://localhost:8080/actuator/metrics/<neo4j.driver.metric>
===== Health
The health endpoint is enriched with the information about the connection to the running Neo4j instance and can be queried at http://localhost:8080/actuator/health/neo4j.
Please be aware that both, metrics and health endpoints, are configured without any security mechanisms in this project's configuration. Always check the information you are exposing before deploying an application to the public.
=== Try it out
==== With a temporary test database
The project provides a Neo4j testcontainer instance if it gets started from the tests. (Docker needed)
==== With a "production" database
If you want to connect to a running instance, you have to start the application with the matching environment variables
Please keep in mind that the application is focused on using the movie dataset.
If not happen yet, please run the :play movies
guide and the Cypher query to populate the database.
==== Compile native
This requires you to have GraalVM (Java 17 based) installed and included your $PATH on your machine. There is a pre-configured profile (native) that will invoke the GraalVM's native maven plugin.
After it has successfully compiled, you can invoke the executable similar to the command above.
=== What to explore
The current schema looks like this:
type Query { movies : [Movie] movie(title : String!) : Movie }
type Movie { id: ID! title: String! description : String! "Random number 0 - 100 as an example for aggregation of data" rating: Int actors: [Person] directors: [Person] }
Example queries as you can see above are:
will return:
will return:
==== Multiple sources
It is possible to aggregate the data from different sources.
For example the rating
field of the Movie
will be a random generated number between 0 and 100.
returns