npm.io
1.9.0 • Published 4 years ago

@vdtn359/sequelize-graphql

Licence
MIT
Version
1.9.0
Deps
12
Size
302 kB
Vulns
1
Weekly
0

README.md

A package that automatically generates a readonly graphql server from a Sequelize instance.

Examples

import * as path from 'path';
import { sequelize } from '../sequelize';
import { bootstrap } from '../../src';

bootstrap(sequelize, {
	emitSchemaFile: path.resolve(__dirname, 'schema.gql'),
}).then((apolloServer) => {
	return apolloServer.listen(8080).then(() => {
		console.info('Apollo server is listening on port 8080');
	});
});
Customization:

You can customize the server to have additional resolvers. See examples/advanced:

import * as path from 'path';
import { sequelize } from '../sequelize';
import { bootstrap } from '../../src';

bootstrap(sequelize, {
	emitSchemaFile: path.resolve(__dirname, 'schema.gql'),
	extraResolvers: [TestResolver],
	models: {
		user: UserModel,
	},
	resolvers: {
		user: UserResolver,
	},
	filters: {
		user: UserFilter,
	},
}).then((apolloServer) => {
	return apolloServer.listen(8080).then(() => {
		console.info('Apollo server is listening on port 8080');
	});
});
Tests
npm run test-integration

This run 2 different test suites against sqlite and mysql database

Demo

Run seed database

npm run seed

Basic example: ./examples/basic

npm run start:basic

Advanced example: ./examples/advanced

npm run start:advanced
TODO:
  • Aggregations
  • Mutations