dictyBase GraphQL server. This uses glqgen to generate code to match our gRPC models.
NAME:
graphql-server - cli for graphql-server backend
USAGE:
graphql-server [global options] command [command options] [arguments...]
VERSION:
1.0.0
COMMANDS:
start-server starts the graphql-server backend
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--log-format value format of the logging out, either of json or text. (default: "json")
--log-level value log level for the application (default: "error")
--help, -h show help
--version, -v print the version
NAME:
graphql-server start-server - starts the graphql-server backend
USAGE:
graphql-server start-server [command options] [arguments...]
OPTIONS:
--user-grpc-host value, --uh value user grpc host [$USER_API_SERVICE_HOST]
--user-grpc-port value, --up value user grpc port [$USER_API_SERVICE_PORT]
--role-grpc-host value, --rh value role grpc host [$ROLE_API_SERVICE_HOST]
--role-grpc-port value, --rp value role grpc port [$ROLE_API_SERVICE_PORT]
--permission-grpc-host value, --ph value permission grpc host [$PERMISSION_API_SERVICE_HOST]
--permission-grpc-port value, --pp value permission grpc port [$PERMISSION_API_SERVICE_PORT]
--publication-api value, --pub value publication api endpoint (default: "https://betafunc.dictybase.org/publications") [$PUBLICATION_API_ENDPOINT]
--stock-grpc-host value, --sh value stock grpc host [$STOCK_API_SERVICE_HOST]
--stock-grpc-port value, --sp value stock grpc port [$STOCK_API_SERVICE_PORT]
--order-grpc-host value, --oh value order grpc host [$ORDER_API_SERVICE_HOST]
--order-grpc-port value, --op value order grpc port [$ORDER_API_SERVICE_PORT]
gqlgen relies on GraphQL schema to generate its code. We are storing our schema files in the dictyBase/graphql-schema repository. There are three files that will be used for each type of schema introduced:
Any unique types and inputs for a particular category (i.e. user) should be placed in their own schema files in the same folder.
In order to generate the actual code, you need to update the gqlgen.yml file. Here are the steps to do so:
schema: field.Now run the generator script with go generate ./.... This may take a few minutes, but it will then rebuild the generated files to incorporate your new changes.
Couple of quirks to beware of:
generated as the package name, you are going to have to go in and manually include it like so:func (r *Resolver) User() generated.UserResolver {
return &userResolver{r}
}
After adding your new schema and running the generator script, you will need to do a bit of additional refactoring.
ServiceMap in the same file. If adding an API endpoint, you need to update RunGraphQLServer to manually add this to the registry. See how this was done with Publication for an example. Also be sure to test the endpoint during server initialization.GetUserClient).Permission()) in the resolver.go file and update it to match the format of the other functions.(q *QueryResolver) and for mutations (m *MutationResolver).resolver. These resolvers are generally tied to the individual fields for that model, and they are unique to that particular client. You can look at the user folder for examples. Also update the package name if necessary.To improve error handling in our front end web applications, we are adding custom error messages when applicable on the server side. The errorutils function in the package of the same name is used to add new errors with custom extensions. See any of the shared resolvers for an example in how to use this.
.
├── README.md
├── build
│ └── Dockerfile
├── cmd
│ └── graphql-server
│ └── main.go
├── deployments
│ └── charts
│ └── graphql-server
│ ├── Chart.yaml
│ ├── templates
│ │ ├── NOTES.txt
│ │ ├── _helpers.tpl
│ │ ├── deployment.yaml
│ │ └── service.yaml
│ └── values.yaml
├── go.mod
├── go.sum
├── gqlgen.yml
├── graphql-server
├── internal
│ ├── app
│ │ ├── server
│ │ │ └── server.go
│ │ └── validate
│ │ └── validate.go
│ ├── graphql
│ │ ├── generated
│ │ │ └── generated.go
│ │ ├── models
│ │ │ ├── models_gen.go
│ │ │ └── timestamp.go
│ │ └── resolver
│ │ ├── permission.go
│ │ ├── resolver.go
│ │ ├── role.go
│ │ ├── user
│ │ │ ├── permission.go
│ │ │ ├── role.go
│ │ │ └── user.go
│ │ └── user.go
│ └── registry
│ └── registry.go
└── scripts
└── gqlgen.go
Content type
Image
Digest
sha256:1285c7ba6…
Size
9 MB
Last updated
15 days ago
docker pull dictybase/graphql-server:develop-af90c3f