Graphql
@kult/graphql is a graphql plugin for @kult/core
Installation
yarn:
bash
yarn add @kult/graphql
NPM:
bash
npm i @kult/graphql
Usage
Create a schema.graphql
in your src
directory:
src/config/plugins.ts
type Query {
hello: String
}
type Mutation {
sayHello: String
}
Register the plugin in src/config/plugins.ts
src/config/plugins.ts
import KultGraphqlPlugin from '@kult/graphql';
export default {
plugins: [KultGraphqlPlugin],
};
Define your queries and mutations using the @Query
and @Mutation
decorators:
src/app/controllers/user.controller.ts
import { Application, ControllerBase, KultController } from '@kult/core';
import { Mutation, Query } from '@kult/graphql';
@KultController('/users')
class UserController extends ControllerBase {
constructor(app: Application) {
super(app);
}
@Query()
hello() {
return 'hello world';
}
@Mutation()
sayHello() {
return 'hello world';
}
}
export default UserController;
Environment Variables
Ensure this port is different than your server's port
.env
GRAPHQL_PORT=3001