This is an example application template that can be used to create a Federated GraphQL subgraph using HotChocolate. You can use this template from Rover with rover template use --template subgraph-csharp-hotchocolate-annotation
.
This example application implements the following GraphQL schema:
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.5", import: ["@key"])
type Query {
thing(id: ID!): Thing
}
type Mutation {
createThing(thing: CreateThing!): Thing
}
type Thing @key(fields: "id") {
id: ID!
name: String
}
input CreateThing {
id: ID!
name: String
}
This project uses .NET CLI and requires .NET 7.0+ runtime. In order to build the project locally, run:
dotnet build
To test the project, run:
dotnet 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:
# from root directory
dotnet run --project Server
# from Server directory
dotnet run
Once the app has started, you can explore the example schema by opening the Banana Cake Pop IDE at http://localhost:4001/ or http://localhost:4001/graphql and begin developing your supergraph with rover dev --url http://localhost:4001/graphql --name my-subgraph
.
There is a launch configuration for both the Server project and the Tests project that you can debug with VS Code. Open up the debug panel in VS Code and press the play button.
- 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. Check the Apollo documentation for how to obtain this API key.APOLLO_GRAPH_REF
: A string with the following format:graph_id@variant_name
. You can find your graph's ID in that graph's Settings page in Studio.PRODUCTION_URL
: The URL of the deployed subgraph.
- 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
. - Send the
Router-Authorization
header from your Cloud router and set theROUTER_SECRET
environment variable wherever you deploy this to.