This is an example application template that can be used to create Federated GraphQL subgraph using Spring GraphQL. You can use this template from Rover with rover template use --template subgraph-java-spring-graphql.
This example application implements following GraphQL schema:
directive @contact(
"Contact title of the subgraph owner"
name: String!
"URL where the subgraph's owner can be reached"
url: String
"Other relevant notes can be included here; supports markdown links"
description: String
) on SCHEMA
schema
@contact(
name: "FooBar Server Team"
url: "https://myteam.slack.com/archives/teams-chat-room-url"
description: "send urgent issues to [#oncall](https://yourteam.slack.com/archives/oncall)."
)
@link(
url: "https://specs.apollo.dev/federation/v2.0",
import: ["@key"]
) {
query: Query
}
type Query {
foo(id: ID!): Foo
}
type Foo @key(fields: "id") {
id: ID!
name: String
}This project uses Maven and requires Java 17+ runtime. In order to build the project locally (which
will also execute all the tests), simply run the clean install goals.
./mvnw clean installNOTE: in order to ensure you use the right version of Maven we highly recommend to use the provided wrapper script
Build is configured with JaCoCo plugin that measures the code coverage. It is configured
to run as part of the build lifecycle and will generate its report under target/site.
Example integration test is provided. It starts up the SpringBoot server and executes example queries against it. Run
verify goal to execute tests and calculate the coverage.
./mvnw clean verifyThis project comes with some example build actions that will trigger on PR requests and commits to the main branch.
To start the GraphQL server:
- Run
Application.javadirectly from your IDE - Alternatively you can also run the Spring Boot plugin directly from the command line
./mvnw spring-boot:runOnce the app has started you can explore the example schema by opening the GraphQL Playground endpoint at http://localhost:8080/playground and begin developing your supergraph with rover dev --url http://localhost:8080/graphql --name my-sugraph.
- Set these secrets in GitHub Actions:
- APOLLO_KEY: An Apollo Studio API key for the supergraph to enable schema checks and publishing of the subgraph.
- APOLLO_GRAPH_REF: The name of the supergraph in Apollo Studio.
- PRODUCTION_URL: The URL of the deployed subgraph that the supergraph gateway will route to.
- Set
SUBGRAPH_NAMEin .github/workflows/checks.yaml and .github/workflows/deploy.yaml - Remove the
if: falselines from.github/workflows/checks.yamland.github/workflows/deploy.yamlto enable schema checks and publishing. - Write your custom deploy logic in
.github/workflows/deploy.yaml. - Send the
Router-Authorizationheader from your Cloud router and set theROUTER_SECRETenvironment variable wherever you deploy this to.