Skip to content

Instantly share code, notes, and snippets.

View rodrwan's full-sized avatar
🇨🇱
cooking amazing code

Rod Fuenzalida rodrwan

🇨🇱
cooking amazing code
View GitHub Profile
type User struct {
ID string `json:"id" db:"id"`
FirstName string `json:"first_name" db:"first_name"`
LastName string `json:"last_name" db:"last_name"`
Email string `json:"email" db:"email"`
Birthdate time.Time `json:"birthdate" db:"birthdate"`
DNI string `json:"dni" db:"dni"`
DNIType string `json:"dni_type" db:"dni_type"`
FamilyStatus string `json:"family_status" db:"family_status"`
Gender string `json:"gender" db:"gender"`
package types
import (
"github.com/rodrwan/gateway"
"github.com/graphql-go/graphql"
)
var User = graphql.NewObject(graphql.ObjectConfig{
Name: "User",
Fields: graphql.Fields{
package queries
import (
"errors"
"github.com/rodrwan/gateway"
"github.com/rodrwan/gateway/graph"
"github.com/rodrwan/gateway/graph/types"
"github.com/graphql-go/graphql"
)
// User hold user information returned by UserService
type User struct {
ID string `json:"id,omitempty" db:"id"`
Email string `json:"email,omitempty" db:"email"`
FirstName string `json:"first_name,omitempty" db:"first_name"`
LastName string `json:"last_name,omitempty" db:"last_name"`
Phone string `json:"phone,omitempty" db:"phone"`
Birthdate time.Time `json:"birthdate,omitempty" db:"birthdate"`
// Address hold adderss information returned by AddressStore
type Address struct {
UserID string `json:"user_id,omitempty" db:"user_id"`
AddressLine string `json:"address_line,omitempty" db:"address_line"`
City string `json:"city,omitempty" db:"city"`
Locality string `json:"locality,omitempty" db:"locality"`
AdministrativeAreaLevel1 string `json:"administrative_area_level_1,omitempty" db:"administrative_area_level_1"`
Country string `json:"country,omitempty" db:"country"`
PostalCode int `json:"postal_code,omitempty" db:"postal_code"`
}
@rodrwan
rodrwan / main.go
Last active October 5, 2018 13:17
func main() {
postgresDSN := flag.String(
"postgres-dsn", "postgres://localhost:5432/graph_test?sslmode=disable", "Postgres DSN")
flag.Parse()
db, err := postgres.New(*postgresDSN)
check(err)
us := &postgres.UserService{
Store: db,
package postgres
import (
"unicode"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
"github.com/jmoiron/sqlx"
"github.com/lib/pq"
package postgres
import (
"crypto/rand"
"database/sql"
"encoding/base64"
"fmt"
"strings"
"time"
type User {
id: ID!
email: String!
first_name: String!
last_name: String!
phone: String!
birthdate: Time!
address: Address!
}
schema:
- schema.graphql
exec:
filename: graphql/generated.go
resolver:
filename: graphql/resolver.go
type: Resolver
models:
User:
model: github.com/rodrwan/medium-example.User