Skip to content

Instantly share code, notes, and snippets.

@rodrwan
Last active August 26, 2018 22:56
Show Gist options
  • Save rodrwan/4f53ca02a62985948821d45a949a7fcb to your computer and use it in GitHub Desktop.
Save rodrwan/4f53ca02a62985948821d45a949a7fcb to your computer and use it in GitHub Desktop.
package types
import (
"github.com/rodrwan/gateway"
"github.com/graphql-go/graphql"
)
var User = graphql.NewObject(graphql.ObjectConfig{
Name: "User",
Fields: graphql.Fields{
"first_name": &graphql.Field{
Type: graphql.String,
},
"last_name": &graphql.Field{
Type: graphql.String,
},
"email": &graphql.Field{
Type: graphql.String,
},
"phone": &graphql.Field{
Type: graphql.String,
},
"birthdate": &graphql.Field{
Type: graphql.DateTime,
},
"dni": &graphql.Field{
Type: graphql.String,
},
"dni_type": &graphql.Field{
Type: graphql.String,
},
"family_status": &graphql.Field{
Type: graphql.String,
},
"gender": &graphql.Field{
Type: graphql.String,
},
"title": &graphql.Field{
Type: graphql.String,
},
"address": &graphql.Field{
Type: Address,
},
},
})
var Address = graphql.NewObject(graphql.ObjectConfig{
Name: "Address",
Fields: graphql.Fields{
"address_line": &graphql.Field{
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
a := p.Source.(*gateway.Address)
return a.AddressLine, nil
},
},
"city": &graphql.Field{
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
a := p.Source.(*gateway.Address)
return a.City, nil
},
},
"locality": &graphql.Field{
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
a := p.Source.(*gateway.Address)
return a.Locality, nil
},
},
"administrative_area_level_1": &graphql.Field{
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
a := p.Source.(*gateway.Address)
return a.AdministrativeAreaLevel1, nil
},
},
"country": &graphql.Field{
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
a := p.Source.(*gateway.Address)
return a.Country, nil
},
},
"place": &graphql.Field{
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
a := p.Source.(*gateway.Address)
return a.Place, nil
},
},
"postal_code": &graphql.Field{
Type: graphql.Int,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
a := p.Source.(*gateway.Address)
return a.PostalCode, nil
},
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment