This is an example application template that can be used to create Federated GraphQL subgraph using gqlgen. You can use this template from Rover with rover template use --template subgraph-go-gqlgen
.
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
}
In order to build the project locally run the following go command
go build
gqlgen auto generates the code for you based on your schema. If you update schema, regenerate your code by running
# download and install gqlgen locally, only need to run it once
go get -d github.com/99designs/gqlgen
# regenerate code
go run github.com/99designs/gqlgen generate
Example integration test is provided. It starts up the example server and executes foo
query against it. Run test
command to execute provided tests.
go test
This 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 following go command.
go run server.go
Once the app has started you can explore the example schema with Apollo Studio Sandbox and begin developing your supergraph with rover dev --url http://localhost:8080 --name my-subgraph
.
- 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_NAME in .github/workflows/checks.yaml and .github/workflows/deploy.yaml
- Remove the if: false lines from .github/workflows/checks.yaml and .github/workflows/deploy.yaml to enable schema checks and publishing.
- Write your custom deploy logic in .github/workflows/deploy.yaml.
- To secure your subgraph, send the
Router-Authorization
header from your Cloud router and set theROUTER_SECRET
environment variable wherever you deploy this to.