Giter Site home page Giter Site logo

a1's Introduction

โ€ƒREADME

A1 is a GraphQL framework written in Go. It is designed to remove boilerplate code by defining only the models returned by the API and their relationships. This makes setting up an entire API a piece of cake.

Installation and Usage

You can either start from scratch by installing the library directly using go get, or you can clone a boilerplate project to get up and running faster.

# Install the library directly
go get github.com/aklinker1/a1

# Clone a boilerplate project
git clone https://github.com/aklinker1/a1-boilerplate.git

Then to use the framework, simply create a new a1.ServerConfig and then call a1.Start(ServerConfig) to start the server.

import (
    a1 "github.com/aklinker1/a1/pkg"
)

func main() {
    server := a1.ServerConfig{
        DataLoaders:         a1.DataLoaderMap{ /* define data loaders */ },
        Models:              a1.ModelMap{ /* define models */ },
        EnableIntrospection: true
    }
    a1.Start(server)
}

Basic Example

A simple todo application with users and todos. This example includes all three types of fields: Field, VirtualField, and LinkedField.

package example

import (
    a1 "github.com/aklinker1/a1/pkg"
    a1Types "github.com/aklinker1/a1/pkg/types"
    postgres "github.com/aklinker1/a1-postgresql/pkg"
)

var dataLoaders  = a1.DataLoaderMap{
    "PostgreSQL": postgres.CreateDataLoader("postgresql://postgres:password@localhost:5432/todos_db")
}

var models = a1.ModelMap{
    "User": a1.Model{
        DataLoader: a1.DataLoaderConfig{
            Source: "PostgreSQL",
            Group:  "users",
        }
        Fields: a1.FieldMap{
            "id": a1.Field{
                PrimaryKey: true,
                Type:       a1Types.ID,
            },
            "firstName": a1Types.String,
            "lastName":  a1Types.String,
            "fullName": a1.VirtualField{
                Type:           a1Types.String,
                RequiredFields: []string{"firstName", "lastName"},
                Computed: func (data: a1.DataMap) interface{} {
                    return fmt.Sprintf("%s %s", data["firstName"], data["lastName"])
                },
            },
            "todos": a1.LinkedField{
                Model:       "Todo",
                Type:        a1.OneToMany,
                Field:       "id",
                LinkedField: "_userId",
            },
        },
    },
    "Todo": a1.Model{
        DataLoader: a1.DataLoaderConfig{
            Source: "PostgreSQL",
            Group:  "todos",
        },
        Fields: a1.FieldMap{
            "id": a1.Field{
                PrimaryKey: true,
                Type:       "ID",
            },
            "value":      a1Types.String,
            "isChecked":  a1Types.Boolean,
            "userId":     a1Types.ID,
            "user": a1.LinkedField{
                Model:       "User",
                Type:        a1.ManyToOne,
                Field:       "userId",
                LinkedField: "id",
            },
        },
    }
}

func main() {
    server := a1.ServerConfig{
        DataLoaders: dataLoaders,
        Models:      models,
        Port:        8000,
        Endpoint:    "/graphql",
    }
}

And there you go! A fully functioning basic todo application GraphQL backend.

For a bit larger and more complex version, checkout the example here.

Documentation

To checkout the full documentation and examples for getting started, checkout the docs/ folder.

a1's People

Contributors

aklinker1 avatar

Watchers

 avatar

a1's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.