first issue
This commit is contained in:
20
types/role.go
Normal file
20
types/role.go
Normal file
@ -0,0 +1,20 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/graphql-go/graphql"
|
||||
)
|
||||
|
||||
// Role type definition.
|
||||
type Role struct {
|
||||
ID int `db:"id" json:"id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
}
|
||||
|
||||
// RoleType is the GraphQL schema for the user type.
|
||||
var RoleType = graphql.NewObject(graphql.ObjectConfig{
|
||||
Name: "Role",
|
||||
Fields: graphql.Fields{
|
||||
"id": &graphql.Field{Type: graphql.Int},
|
||||
"name": &graphql.Field{Type: graphql.String},
|
||||
},
|
||||
})
|
33
types/user.go
Normal file
33
types/user.go
Normal file
@ -0,0 +1,33 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/graphql-go/graphql"
|
||||
)
|
||||
|
||||
// User type definition.
|
||||
type User struct {
|
||||
ID int `db:"id" json:"id"`
|
||||
Firstname string `db:"firstname" json:"firstname"`
|
||||
Lastname string `db:"lastname" json:"lastname"`
|
||||
}
|
||||
|
||||
// UserType is the GraphQL schema for the user type.
|
||||
var UserType = graphql.NewObject(graphql.ObjectConfig{
|
||||
Name: "User",
|
||||
Fields: graphql.Fields{
|
||||
"id": &graphql.Field{Type: graphql.Int},
|
||||
"firstname": &graphql.Field{Type: graphql.String},
|
||||
"lastname": &graphql.Field{Type: graphql.String},
|
||||
"roles": &graphql.Field{
|
||||
Type: graphql.NewList(RoleType),
|
||||
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
|
||||
var roles []Role
|
||||
|
||||
// userID := params.Source.(User).ID
|
||||
// Implement logic to retrieve user associated roles from user id here.
|
||||
|
||||
return roles, nil
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
Reference in New Issue
Block a user