Setup
GraphQL
You've defined your GraphQL Controllers, operation types, their input and output DTOs. Now you just need to provide this information to the GraphQL Server when you initialize it.
The GraphQL server constructor requires to provide a port and your set of graphQL controllers. Your schema will be generated by the associated controllers.
setup.bl
GraphQLServer({
port: env.APOLLO_SERVER || 5002,
}) {
[Demo][Hello World]HelloWorldGQLController();
}
You are familiar with the [Demo][Hello World]
syntax by now which indicates the bounded context and module where your controller resides.
Package
You've defined your PackagePort and your concrete PackageAdapter and now you want to instantiate it in the setup. So, when you use the package in your application it will use the adapter that you have specified in the setup.
Example
setup.bl
[Demo][Hello World]BitloopsGherkinPackageAdapter concretes GherkinPackagePort;
You can use the above package in your application like this:
const bytes = GherkinPackage.encode(value);
UseCase
You've defined your UseCase and now you want to instantiate it in the setup. Bounded Context and Module must be placed in front [Todo][Todo]
and the dependencies passed as arguments todoWriteRepo
, as it seems below:
For multiple dependencies separate them by comma
Example
setup.bl
const updateTodoUseCase = [Todo][Todo]UpdateTodoUseCase(todoWriteRepo);
RESTController
You've defined your RESTController and now you want to use it in the setup. You need to create a Rest Router that will link the REST API method and path with your controller. You then need to create a Rest Server that will use this Rest Router, in order to be able to run your server and make requests.
Example
setup.bl
The Rest Router requires the web framework and inside to declare the REST API method and path with the controller.
const todoRESTRouter = RESTRouter(REST.Fastify) {
Patch('/:id'): [Todo][Todo]UpdateTodoRESTController(updateTodoUseCase);
}
The Rest Server requires the web framework, the port, the api prefix and inside to declare the route paths with the routers.
RESTServer({
server: REST.Fastify,
port: Env(FASTIFY_PORT, 5001),
apiPrefix: '/api',
}) {
'/todo': todoRESTRouter;
}