https://github.com/ujjwalguptaofficial/fortjs-graphql
GraphQl module for fortjs
https://github.com/ujjwalguptaofficial/fortjs-graphql
es6 fortjs graphql graphql-server nodejs typescript
Last synced: 4 months ago
JSON representation
GraphQl module for fortjs
- Host: GitHub
- URL: https://github.com/ujjwalguptaofficial/fortjs-graphql
- Owner: ujjwalguptaofficial
- License: apache-2.0
- Created: 2019-02-18T16:41:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-01T16:53:59.000Z (about 5 years ago)
- Last Synced: 2025-02-05T13:37:46.909Z (8 months ago)
- Topics: es6, fortjs, graphql, graphql-server, nodejs, typescript
- Language: TypeScript
- Size: 1.31 MB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://badge.fury.io/js/fortjs-graphql)
# fortjs-graphql
GraphQl module for fortjs# Uses
1. `npm i fortjs-graphql` or `yarn add fortjs-graphql`
2. Create a controller and inherit `GraphQlHelper`
* Create a default worker and call `processGraphQl` inside it.
* For graphiql , create another worker and call `getGraphiqlUi` inside it.
```
import { HTTP_METHOD, DefaultWorker, Worker } from "fortjs";
import { GraphQlHelper } from "fort-graphql";export class GraphQlController extends GraphQlHelper {
/**
* This method will be used to process graphql query
*
* @returns
* @memberof GraphQlController
*/
@DefaultWorker([HTTP_METHOD.Get, HTTP_METHOD.Post])
async default() {
return this.processGraphQl();
}/**
* This method will return graphiql
*
* @returns
* @memberof GraphQlController
*/
@Worker()
async graphiql() {
return this.getGraphiqlUi();
}}
```
3. Add the controller into routes
4. Initiate the graphql, where you have bootstrapped your app. By default file is app.ts/app.js -```
import { Fort } from 'fortjs';
import { routes } from './routes';
import { FortViewEngine } from 'eshtml';
import * as path from "path";
import { FortGraphQl } from 'fortjs-graphql';
import { GraphQLError, buildSchema } from 'graphql';export class App extends Fort {
constructor() {
super();
this.routes = routes;
this.viewEngine = FortViewEngine;
}
}new App().create({
defaultPath: "default"
}).then(() => {
console.log("Your fort is located at address - localhost:4000");
// setup graphqlnew FortGraphQl().initiate({
schema: buildSchema(`
type Query {
hello: String
}
` ),
resolver: { hello: () => 'Hello world!' }
})
}).catch(err => {
console.error(err);
})
```# Options
### Errors can be formatted by using `errorFormatter` property.
```
new FortGraphQl().initiate({
errorFormatter: function (error: GraphQLError) {
// format the error and return it
return error;
},
schema: buildSchema(`
type Query {
hello: String
}
` ),
resolver: { hello: () => 'Hello world!' }
})
```