auto-graphql-server is a 🐋docker image that automaticly generates a backend from a 📈GraphQL schema.
If you ever are too lazy to implement a simple CRUD backend, go ahead and use this!
- Only requires a graphql.schema and a config.json to function
- Supports Sqlite, MySQL and PostgreDB
- Contains many examples to learn from!
auto-graphql-server requires graphql.schema and config.json files to function
- Create a volume for graphql.schema and config.json files
- Add a graphql.schema, this should have 📈GraphQL type definitions (see examples)
- Add a config.json file
- Optionally add a resolvers.js file
- Run with
docker run -p 3001:3001 -v your_volume:/app/data
type Config = {
port?: number;
printSql?: boolean; //default false
skipDbCreationIfExists?: boolean; //default true
deleteDbCreationIfExists?: boolean; //default false
graphqlHTTP?: Omit<graphqlHTTP.Options, 'schema'>;
database?: Knex.Config;
};
port
for local development, will be overriden by enviroment PORT if providedprintSql
whether or not print all Knex generated SQL commandsskipDbCreationIfExists
whether or not skip table generations for db if they already existdeleteDbCreationIfExists
sqlite only, will deletegraphqlHTTP
field takes any koa-graphql options options but most of the time you just want GraphiQL interface with:{ "graphiql": true }
database
field is a Knex.js configuration- Supported db clients - sqlite, mysql2 and pg
If you need custom functionallity add a resolvers.js file. It looks exatly like graphql-tools resolver map, except it contains functions that return resolvers, for example:
module.exports = {
Type_Name_Here: {
Field_of_that_type_name: function (knex) {
const resolver = async (root, args, context, info) {
return await knex('Type_Name_Here').select().where(args);
};
}
}
}
More examples in exmaples folder
- This project only works with default GraphQL scalar types
- Generates tables from
type
fields - Not null
!
is not supported - Intefaces, Unions, Enums are not supported
- Directives not verified if they work
- create a data folder with graphql.schema and config.json files
- use
yarn
to install dependencies - start the project using
yarn dev
- Run with
yarn test
- Run with
yarn lint