Skip to content

Flamingo GraphQL

This module allows the usage of GraphQL services in your Flamingo project.


The module contains a working example that you can try out yourself. See

Use Graphql in your Flaming project

Create a new Module and bind a graphql.Service.

The service has both the Schema and Model-Mapping information.

It also makes sense to declare graphql.Module as a direct dependency from your model:

package todo

import (

// Service for the todo graphql service
type service struct{}

// Schema getter for graphql
func (*service) Schema() []byte {
    // language=graphql
    return []byte(`
type Todo {
    id: ID!
    task: String!
    done: Boolean!
extend type User {
    todos: [Todo]
extend type Mutation {
    TodoAdd(user: ID!, task: String!): Todo
    TodoDone(todo: ID!, done: Boolean!): Todo

// Types mapping between graphql and go
func (*service) Types(types *graphql.Types) {
    types.Map("Todo", domain.Todo{})
    config.Resolve("User", "todos", UserResolver{}, "Todos")
    config.Resolve("Mutation", "TodoAdd", MutationResolver{}, "TodoAdd")
    config.Resolve("Mutation", "TodoDone", MutationResolver{}, "TodoDone")

// Module struct for the todo module
type Module struct{}

// Configure registers the service graphql service
func (Module) Configure(injector *dingo.Injector) {

// Depends marks dependency to the graphql Module
func (*Module) Depends() []dingo.Module {
    return []dingo.Module{

Setup Graphql in your Flamingo project

Add the graphql.Module to your projects modules.

Generate the local code by running go run main.go graphql. Better is to add the following lines to your project main file:

//go:generate rm -f graphql/generated.go
//go:generate go run -tags graphql main.go graphql

Then you can run go generate . instead of go run main.go graphql

After this the project specific graphql code is generated inside the folder graphql

You then also need to add the generated local Module to your main project file:

import (
    projectGraphql "yourpoject-namespace/graphql"


Now when you start your application you are able to use the graphql API and the graphql console. See the example folder for a complete example on how to use

The next thing you need to do is to add Resolver to the file resolver.go:

Resolver and Modifier

Everything needs to be resolved, unless gqlgen can figure something out on its own.

Best practice here is to provide default resolvers in your code, which can be used via embedding. See example/user for an example UserQuery resolver.

Suggested Naming Conventions

We recommend to namespace your Types and Type extensions with the Project name. For Flamingo Core Framework GraphQL Schema we use the prefix Core_ and for Flamingo Commerce we use Commerce_


You can enable LimitOperationAmountMiddleware to prevent batching attack by setting to true. option can be used to set a limit for the same operations called in a single request. option can be used to set a limit for all the operations called in a single request.


Learn GraphQL:

GraphQL Specification: