graphql-go / graphql

An implementation of GraphQL for Go / Golang
MIT License
9.88k stars 840 forks source link

someone can create todo example with database(postgres)? #158

Open aligos opened 8 years ago

aligos commented 8 years ago

i hope this repo will be todo example with database like postgres

kmulvey commented 7 years ago

if you use https://github.com/jinzhu/gorm (which you should) then your resolver would look like:

"organization": &graphql.Field{
    Type: organizationType,
    Resolve: func(p graphql.ResolveParams) (interface{}, error) {
        db := models.GetAdamaDB()
        organization := models.Organization{}
        db.Where(&models.Organization{ID: p.Source.(models.User).OrganizationID}).Find(&organization)
        return organization, nil
    },
},