This repository is a gqlgen with ent backend starter template. Initial configuration is time-consuming and complicated. This is here to make things easier and help people get started with GraphQL and ent.
- You use Keycloak as the OIDC IDP. It can be used with any IDP, but a custom viewer would need to be constructed. You will have to add the audience in Keycloak to the token, because Keycloak is dumb like that.
- xid is used for globally unique IDs
- The
Profileschema is the root of your related entities. - Schema introspection is enabled
- PostgreSQL is used as the database. Optionally SQLite in-memory mode can be used or development purposes.
- The Schema is automigrated on each graphql run.
- Relay is used to provide filtering, ordering and pagination
go run main.go graphql --sqlite=true --debug=truego run main.go graphql \
--debug=true \
--db_uri="postgres://root:password@localhost:port/?sslmode=disable"
#or
go run main.go graphql \
--debug=true \
--db_user="username" \
--db_password="password" \
--db_name="database name" \
--db_host="localhost" \
--db_port="5432"Let's assume your project is at github.com/user/repo
mkdir -p ~/go/src/github.com/user
cd ~/go/src/github.com/user
git clone https://github.com/dlukt/graphql-backend-starter.git repo
cd repochmod +x ./update-repo.sh
./update-repo.sh github.com/user/repo# remember, repo is your repo name
rm graph/generated/starter.generated.go
mv starter.graphql repo.graphql
mv graph/starter.resolvers.go graph/repo.resolvers.goedit gqlgen.yml and replace the - starter.graphql with your - repo.graphql
schema:
- ent.graphql
- repo.graphqlRegenerate
go generate ./...Change the project name in cmd/root.go, line 22.
rm -rf .git
git init
git add .
git remote add origin github.com/user/repo
git commit -m 'initial'
git push -u origin masteralias ent='go run -mod=mod entgo.io/ent/cmd/ent'cd into your project root.
ent new Entity # capitalization mattersadd the new entity to gqlgen.yml
autobind:
- github.com/user/repo/ent
- github.com/user/repo/ent/profile
- github.com/user/repo/ent/entityand edit the ent/schema/entity.go file.
Afterwards, regenerate all the things.
go generate ./...Uses OIDC Middleware Guard and its viewer with helper functions.
It assumes a Keycloak claims structure.
If you need the claims viewer.RawClaims which returns a map[string]any.