Skip to content
Docs

Database to GraphQL API in Five Minutes

BifrostQL turns a database into a GraphQL API in about five minutes. You install two packages, put a connection string in appsettings.json, and wire four lines of Program.cs. There is no schema file to write and no code to generate — the database is the contract.

This page uses SQL Server. For the other three engines, see connect a database.

From a SQLite file to a nested GraphQL query — The blog sample database served through the generated API: a paged query, then one request that joins posts to authors, categories, and comments.

Create a new ASP.NET Core project and add the BifrostQL packages:

Terminal window
dotnet new web -n MyBifrostApi
cd MyBifrostApi
dotnet add package BifrostQL.Server
dotnet add package BifrostQL.SqlServer # or BifrostQL.Ngsql, BifrostQL.MySql

Add your connection string and BifrostQL settings to appsettings.json:

{
"ConnectionStrings": {
"bifrost": "Server=localhost;Database=mydb;User Id=sa;Password=xxx"
},
"BifrostQL": {
"Path": "/graphql",
"Playground": "/graphiql",
"DisableAuth": true,
"Provider": "sqlserver"
}
}

Replace sqlserver with postgres, mysql, or sqlite if you’re using a different database. Provider is optional; BifrostQL infers the engine from the connection string when it is absent, and fails fast when it cannot.

Replace the contents of Program.cs:

using BifrostQL.Core.Model;
using BifrostQL.Server;
using BifrostQL.SqlServer;
// Dialect packages do not self-register. Register the provider you installed.
DbConnFactoryResolver.Register(BifrostDbProvider.SqlServer, cs => new SqlServerDbConnFactory(cs));
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddBifrostQL(o => o.BindStandardConfig(builder.Configuration));
builder.Services.AddCors();
var app = builder.Build();
app.UseCors(x => x.AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin());
app.UseBifrostQL();
await app.RunAsync();

That’s the entire application. BifrostQL reads your database schema at startup and generates the complete GraphQL API.

The DbConnFactoryResolver.Register call is required. Without it, startup fails with No factory registered for provider …. Each engine has its own factory type — see connect a database.

Terminal window
dotnet run

Open http://localhost:5000/graphiql for the GraphQL playground. The API endpoint is at http://localhost:5000/graphql.

If your database has a users table, you can query it immediately:

{
users(limit: 10, sort: [name_asc]) {
data {
userId
name
email
}
}
}

Every query uses the paged format: the table name takes limit, offset, sort, and filter arguments, and results are nested inside a data field.

BifrostQL also ships as a standalone CLI tool for quick schema inspection and local serving:

Terminal window
dotnet tool install -g BifrostQL.Tool
bifrost serve --connection "Server=localhost;Database=mydb;..."
bifrost schema --connection "..."
bifrost config-generate --connection "..."

bifrost serve starts a local GraphQL server without writing any project files. Useful for exploring a database schema before committing to a project structure.