activegraph

package module
v0.0.8-b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2022 License: MIT Imports: 3 Imported by: 1

README

ActiveGraph · Tests Documentation

GraphQL-powered server framework for Go.

Installation

You can install the latest version of the ActiveGraph module using go mod:

go get github.com/activegraph/activegraph

Documentation

The ActiveGraph Documentation contains additional details on how to get started with GraphQL and ActiveGraph.

Usage

Implementation of the ActiveGraph, comparing to other Go frameworks does not require GraphQL schema declaration. Instead, it is highly anticipated to work with business models of the service as API entities for GraphQL server.

Active Records

You can provision database and create ActiveRecord from the database schema using the activerecord package:

activerecord.EstablishConnection(
    activerecord.DatabaseConfig{Adapter: "sqlite3", Database: "main.db"},
)

activerecord.Migrate("001_create_tables", func(m *activerecord.M) {
    m.CreateTable("authors", func(t *activerecord.Table) {
        t.String("name")
        t.DateTime("born_at")
    })

    m.CreateTable("books", func(t *activerecord.Table) {
        t.Int64("publisher_id")
        t.Int64("year")
        t.String("title")
        t.References("authors")
        t.ForeignKey("authors")
    })
})

// Declare records that reference created tables.
Book := activerecord.New("book", func(r *activerecord.R) {
    r.BelongsTo("author")
})

Author := activerecord.New("author", func(r *activerecord.R) {
    r.HasMany("books")
})
Action Controller

You can create a GraphQL controller using actioncontroller package:

AuthorControler := actioncontroller.New(func(c *actioncontroller.C) {
    // Generates "author(id: Int!)" query.
    c.Show(func(ctx *actioncontroller.Context) actioncontroller.Result {
        author := Author.Find(ctx.Params["id"])
        return actionview.NestedView(ctx, author)
    })

    // Generates "createAuthor(author: CreateAuthorInput!)" mutation.
    c.Create(func(ctx *actioncontroller.Context) actioncontroller.Result {
        author := Author.Create(ctx.Params.Get("author"))
        return actionview.NestedView(ctx, author)
    })

    // Generates "deleteAuthor(id: Int!)" mutation.
    c.Destroy(func(ctx *actioncontroller.Context) actioncontroller.Result {
        author := Author.Find(ctx.Params["id"])
        author = author.Delete()
        return actionview.NestedView(ctx, author)
    })
})

License

ActiveGraph is MIT licensed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type A

type A struct {
	actioncontroller.Mapper
}

type Application

type Application struct {
	// contains filtered or unexported fields
}

func Initialize

func Initialize(init func(*A)) (*Application, error)

func New

func New(init func(*A)) *Application

func (*Application) ListenAndServe

func (a *Application) ListenAndServe() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL