feature: verify tokens
This commit is contained in:
@@ -1,6 +1,18 @@
|
||||
extend type Mutation {
|
||||
login(email: String!, pwd: String!): AuthUser!
|
||||
logout: Boolean!
|
||||
"""
|
||||
Verify email token
|
||||
"""
|
||||
accountVerifyEmail(token: String): Boolean!
|
||||
|
||||
"""
|
||||
User account login
|
||||
"""
|
||||
accountLogin(email: String!, pwd: String!): AuthUser!
|
||||
|
||||
"""
|
||||
User account logout
|
||||
"""
|
||||
accountLogout: Boolean!
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
@@ -8,8 +20,8 @@ extend type Query {
|
||||
}
|
||||
|
||||
type AuthUser {
|
||||
id: ID!
|
||||
id: UID!
|
||||
email: String!
|
||||
displayName: String!
|
||||
name: String!
|
||||
roleID: Int!
|
||||
}
|
||||
|
@@ -11,14 +11,19 @@ import (
|
||||
"gitserver.in/patialtech/rano/graph/model"
|
||||
)
|
||||
|
||||
// Login is the resolver for the login field.
|
||||
func (r *mutationResolver) Login(ctx context.Context, email string, pwd string) (*model.AuthUser, error) {
|
||||
panic(fmt.Errorf("not implemented: Login - login"))
|
||||
// AccountVerifyEmail is the resolver for the accountVerifyEmail field.
|
||||
func (r *mutationResolver) AccountVerifyEmail(ctx context.Context, token *string) (bool, error) {
|
||||
panic(fmt.Errorf("not implemented: AccountVerifyEmail - accountVerifyEmail"))
|
||||
}
|
||||
|
||||
// Logout is the resolver for the logout field.
|
||||
func (r *mutationResolver) Logout(ctx context.Context) (bool, error) {
|
||||
panic(fmt.Errorf("not implemented: Logout - logout"))
|
||||
// AccountLogin is the resolver for the accountLogin field.
|
||||
func (r *mutationResolver) AccountLogin(ctx context.Context, email string, pwd string) (*model.AuthUser, error) {
|
||||
panic(fmt.Errorf("not implemented: AccountLogin - accountLogin"))
|
||||
}
|
||||
|
||||
// AccountLogout is the resolver for the accountLogout field.
|
||||
func (r *mutationResolver) AccountLogout(ctx context.Context) (bool, error) {
|
||||
panic(fmt.Errorf("not implemented: AccountLogout - accountLogout"))
|
||||
}
|
||||
|
||||
// Me is the resolver for the me field.
|
||||
|
@@ -55,7 +55,7 @@ func (ec *executionContext) _AuthUser_id(ctx context.Context, field graphql.Coll
|
||||
}
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalNID2string(ctx, field.Selections, res)
|
||||
return ec.marshalNUID2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) fieldContext_AuthUser_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
@@ -65,7 +65,7 @@ func (ec *executionContext) fieldContext_AuthUser_id(_ context.Context, field gr
|
||||
IsMethod: false,
|
||||
IsResolver: false,
|
||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||
return nil, errors.New("field of type ID does not have child fields")
|
||||
return nil, errors.New("field of type UID does not have child fields")
|
||||
},
|
||||
}
|
||||
return fc, nil
|
||||
@@ -115,8 +115,8 @@ func (ec *executionContext) fieldContext_AuthUser_email(_ context.Context, field
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _AuthUser_displayName(ctx context.Context, field graphql.CollectedField, obj *model.AuthUser) (ret graphql.Marshaler) {
|
||||
fc, err := ec.fieldContext_AuthUser_displayName(ctx, field)
|
||||
func (ec *executionContext) _AuthUser_name(ctx context.Context, field graphql.CollectedField, obj *model.AuthUser) (ret graphql.Marshaler) {
|
||||
fc, err := ec.fieldContext_AuthUser_name(ctx, field)
|
||||
if err != nil {
|
||||
return graphql.Null
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func (ec *executionContext) _AuthUser_displayName(ctx context.Context, field gra
|
||||
}()
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.DisplayName, nil
|
||||
return obj.Name, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
@@ -146,7 +146,7 @@ func (ec *executionContext) _AuthUser_displayName(ctx context.Context, field gra
|
||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) fieldContext_AuthUser_displayName(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
func (ec *executionContext) fieldContext_AuthUser_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
fc = &graphql.FieldContext{
|
||||
Object: "AuthUser",
|
||||
Field: field,
|
||||
@@ -236,8 +236,8 @@ func (ec *executionContext) _AuthUser(ctx context.Context, sel ast.SelectionSet,
|
||||
if out.Values[i] == graphql.Null {
|
||||
out.Invalids++
|
||||
}
|
||||
case "displayName":
|
||||
out.Values[i] = ec._AuthUser_displayName(ctx, field, obj)
|
||||
case "name":
|
||||
out.Values[i] = ec._AuthUser_name(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
out.Invalids++
|
||||
}
|
||||
|
@@ -2256,21 +2256,6 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se
|
||||
return res
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalNID2string(ctx context.Context, v interface{}) (string, error) {
|
||||
res, err := graphql.UnmarshalID(v)
|
||||
return res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalNID2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler {
|
||||
res := graphql.MarshalID(v)
|
||||
if res == graphql.Null {
|
||||
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
||||
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalNInt2int(ctx context.Context, v interface{}) (int, error) {
|
||||
res, err := graphql.UnmarshalInt(v)
|
||||
return res, graphql.ErrorOnPath(ctx, err)
|
||||
|
@@ -18,8 +18,9 @@ import (
|
||||
// region ************************** generated!.gotpl **************************
|
||||
|
||||
type MutationResolver interface {
|
||||
Login(ctx context.Context, email string, pwd string) (*model.AuthUser, error)
|
||||
Logout(ctx context.Context) (bool, error)
|
||||
AccountVerifyEmail(ctx context.Context, token *string) (bool, error)
|
||||
AccountLogin(ctx context.Context, email string, pwd string) (*model.AuthUser, error)
|
||||
AccountLogout(ctx context.Context) (bool, error)
|
||||
}
|
||||
type QueryResolver interface {
|
||||
Me(ctx context.Context) (*model.AuthUser, error)
|
||||
@@ -29,22 +30,22 @@ type QueryResolver interface {
|
||||
|
||||
// region ***************************** args.gotpl *****************************
|
||||
|
||||
func (ec *executionContext) field_Mutation_login_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
|
||||
func (ec *executionContext) field_Mutation_accountLogin_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
|
||||
var err error
|
||||
args := map[string]interface{}{}
|
||||
arg0, err := ec.field_Mutation_login_argsEmail(ctx, rawArgs)
|
||||
arg0, err := ec.field_Mutation_accountLogin_argsEmail(ctx, rawArgs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args["email"] = arg0
|
||||
arg1, err := ec.field_Mutation_login_argsPwd(ctx, rawArgs)
|
||||
arg1, err := ec.field_Mutation_accountLogin_argsPwd(ctx, rawArgs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args["pwd"] = arg1
|
||||
return args, nil
|
||||
}
|
||||
func (ec *executionContext) field_Mutation_login_argsEmail(
|
||||
func (ec *executionContext) field_Mutation_accountLogin_argsEmail(
|
||||
ctx context.Context,
|
||||
rawArgs map[string]interface{},
|
||||
) (string, error) {
|
||||
@@ -57,7 +58,7 @@ func (ec *executionContext) field_Mutation_login_argsEmail(
|
||||
return zeroVal, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Mutation_login_argsPwd(
|
||||
func (ec *executionContext) field_Mutation_accountLogin_argsPwd(
|
||||
ctx context.Context,
|
||||
rawArgs map[string]interface{},
|
||||
) (string, error) {
|
||||
@@ -70,6 +71,29 @@ func (ec *executionContext) field_Mutation_login_argsPwd(
|
||||
return zeroVal, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Mutation_accountVerifyEmail_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
|
||||
var err error
|
||||
args := map[string]interface{}{}
|
||||
arg0, err := ec.field_Mutation_accountVerifyEmail_argsToken(ctx, rawArgs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args["token"] = arg0
|
||||
return args, nil
|
||||
}
|
||||
func (ec *executionContext) field_Mutation_accountVerifyEmail_argsToken(
|
||||
ctx context.Context,
|
||||
rawArgs map[string]interface{},
|
||||
) (*string, error) {
|
||||
ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("token"))
|
||||
if tmp, ok := rawArgs["token"]; ok {
|
||||
return ec.unmarshalOString2ᚖstring(ctx, tmp)
|
||||
}
|
||||
|
||||
var zeroVal *string
|
||||
return zeroVal, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
|
||||
var err error
|
||||
args := map[string]interface{}{}
|
||||
@@ -101,8 +125,8 @@ func (ec *executionContext) field_Query___type_argsName(
|
||||
|
||||
// region **************************** field.gotpl *****************************
|
||||
|
||||
func (ec *executionContext) _Mutation_login(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
fc, err := ec.fieldContext_Mutation_login(ctx, field)
|
||||
func (ec *executionContext) _Mutation_accountVerifyEmail(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
fc, err := ec.fieldContext_Mutation_accountVerifyEmail(ctx, field)
|
||||
if err != nil {
|
||||
return graphql.Null
|
||||
}
|
||||
@@ -115,72 +139,7 @@ func (ec *executionContext) _Mutation_login(ctx context.Context, field graphql.C
|
||||
}()
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.Mutation().Login(rctx, fc.Args["email"].(string), fc.Args["pwd"].(string))
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(*model.AuthUser)
|
||||
fc.Result = res
|
||||
return ec.marshalNAuthUser2ᚖgitserverᚗinᚋpatialtechᚋranoᚋgraphᚋmodelᚐAuthUser(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) fieldContext_Mutation_login(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
fc = &graphql.FieldContext{
|
||||
Object: "Mutation",
|
||||
Field: field,
|
||||
IsMethod: true,
|
||||
IsResolver: true,
|
||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||
switch field.Name {
|
||||
case "id":
|
||||
return ec.fieldContext_AuthUser_id(ctx, field)
|
||||
case "email":
|
||||
return ec.fieldContext_AuthUser_email(ctx, field)
|
||||
case "displayName":
|
||||
return ec.fieldContext_AuthUser_displayName(ctx, field)
|
||||
case "roleID":
|
||||
return ec.fieldContext_AuthUser_roleID(ctx, field)
|
||||
}
|
||||
return nil, fmt.Errorf("no field named %q was found under type AuthUser", field.Name)
|
||||
},
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = ec.Recover(ctx, r)
|
||||
ec.Error(ctx, err)
|
||||
}
|
||||
}()
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
if fc.Args, err = ec.field_Mutation_login_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return fc, err
|
||||
}
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Mutation_logout(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
fc, err := ec.fieldContext_Mutation_logout(ctx, field)
|
||||
if err != nil {
|
||||
return graphql.Null
|
||||
}
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.Mutation().Logout(rctx)
|
||||
return ec.resolvers.Mutation().AccountVerifyEmail(rctx, fc.Args["token"].(*string))
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
@@ -197,7 +156,127 @@ func (ec *executionContext) _Mutation_logout(ctx context.Context, field graphql.
|
||||
return ec.marshalNBoolean2bool(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) fieldContext_Mutation_logout(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
func (ec *executionContext) fieldContext_Mutation_accountVerifyEmail(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
fc = &graphql.FieldContext{
|
||||
Object: "Mutation",
|
||||
Field: field,
|
||||
IsMethod: true,
|
||||
IsResolver: true,
|
||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||
return nil, errors.New("field of type Boolean does not have child fields")
|
||||
},
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = ec.Recover(ctx, r)
|
||||
ec.Error(ctx, err)
|
||||
}
|
||||
}()
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
if fc.Args, err = ec.field_Mutation_accountVerifyEmail_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return fc, err
|
||||
}
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Mutation_accountLogin(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
fc, err := ec.fieldContext_Mutation_accountLogin(ctx, field)
|
||||
if err != nil {
|
||||
return graphql.Null
|
||||
}
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.Mutation().AccountLogin(rctx, fc.Args["email"].(string), fc.Args["pwd"].(string))
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(*model.AuthUser)
|
||||
fc.Result = res
|
||||
return ec.marshalNAuthUser2ᚖgitserverᚗinᚋpatialtechᚋranoᚋgraphᚋmodelᚐAuthUser(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) fieldContext_Mutation_accountLogin(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
fc = &graphql.FieldContext{
|
||||
Object: "Mutation",
|
||||
Field: field,
|
||||
IsMethod: true,
|
||||
IsResolver: true,
|
||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||
switch field.Name {
|
||||
case "id":
|
||||
return ec.fieldContext_AuthUser_id(ctx, field)
|
||||
case "email":
|
||||
return ec.fieldContext_AuthUser_email(ctx, field)
|
||||
case "name":
|
||||
return ec.fieldContext_AuthUser_name(ctx, field)
|
||||
case "roleID":
|
||||
return ec.fieldContext_AuthUser_roleID(ctx, field)
|
||||
}
|
||||
return nil, fmt.Errorf("no field named %q was found under type AuthUser", field.Name)
|
||||
},
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = ec.Recover(ctx, r)
|
||||
ec.Error(ctx, err)
|
||||
}
|
||||
}()
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
if fc.Args, err = ec.field_Mutation_accountLogin_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return fc, err
|
||||
}
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Mutation_accountLogout(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
fc, err := ec.fieldContext_Mutation_accountLogout(ctx, field)
|
||||
if err != nil {
|
||||
return graphql.Null
|
||||
}
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.Mutation().AccountLogout(rctx)
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(bool)
|
||||
fc.Result = res
|
||||
return ec.marshalNBoolean2bool(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) fieldContext_Mutation_accountLogout(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
fc = &graphql.FieldContext{
|
||||
Object: "Mutation",
|
||||
Field: field,
|
||||
@@ -250,8 +329,8 @@ func (ec *executionContext) fieldContext_Query_me(_ context.Context, field graph
|
||||
return ec.fieldContext_AuthUser_id(ctx, field)
|
||||
case "email":
|
||||
return ec.fieldContext_AuthUser_email(ctx, field)
|
||||
case "displayName":
|
||||
return ec.fieldContext_AuthUser_displayName(ctx, field)
|
||||
case "name":
|
||||
return ec.fieldContext_AuthUser_name(ctx, field)
|
||||
case "roleID":
|
||||
return ec.fieldContext_AuthUser_roleID(ctx, field)
|
||||
}
|
||||
@@ -421,16 +500,23 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet)
|
||||
switch field.Name {
|
||||
case "__typename":
|
||||
out.Values[i] = graphql.MarshalString("Mutation")
|
||||
case "login":
|
||||
case "accountVerifyEmail":
|
||||
out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) {
|
||||
return ec._Mutation_login(ctx, field)
|
||||
return ec._Mutation_accountVerifyEmail(ctx, field)
|
||||
})
|
||||
if out.Values[i] == graphql.Null {
|
||||
out.Invalids++
|
||||
}
|
||||
case "logout":
|
||||
case "accountLogin":
|
||||
out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) {
|
||||
return ec._Mutation_logout(ctx, field)
|
||||
return ec._Mutation_accountLogin(ctx, field)
|
||||
})
|
||||
if out.Values[i] == graphql.Null {
|
||||
out.Invalids++
|
||||
}
|
||||
case "accountLogout":
|
||||
out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) {
|
||||
return ec._Mutation_accountLogout(ctx, field)
|
||||
})
|
||||
if out.Values[i] == graphql.Null {
|
||||
out.Invalids++
|
||||
@@ -531,4 +617,19 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr
|
||||
|
||||
// region ***************************** type.gotpl *****************************
|
||||
|
||||
func (ec *executionContext) unmarshalNUID2string(ctx context.Context, v interface{}) (string, error) {
|
||||
res, err := graphql.UnmarshalString(v)
|
||||
return res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalNUID2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler {
|
||||
res := graphql.MarshalString(v)
|
||||
if res == graphql.Null {
|
||||
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
||||
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// endregion ***************************** type.gotpl *****************************
|
||||
|
@@ -41,15 +41,16 @@ type DirectiveRoot struct {
|
||||
|
||||
type ComplexityRoot struct {
|
||||
AuthUser struct {
|
||||
DisplayName func(childComplexity int) int
|
||||
Email func(childComplexity int) int
|
||||
ID func(childComplexity int) int
|
||||
RoleID func(childComplexity int) int
|
||||
Email func(childComplexity int) int
|
||||
ID func(childComplexity int) int
|
||||
Name func(childComplexity int) int
|
||||
RoleID func(childComplexity int) int
|
||||
}
|
||||
|
||||
Mutation struct {
|
||||
Login func(childComplexity int, email string, pwd string) int
|
||||
Logout func(childComplexity int) int
|
||||
AccountLogin func(childComplexity int, email string, pwd string) int
|
||||
AccountLogout func(childComplexity int) int
|
||||
AccountVerifyEmail func(childComplexity int, token *string) int
|
||||
}
|
||||
|
||||
Query struct {
|
||||
@@ -76,13 +77,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||
_ = ec
|
||||
switch typeName + "." + field {
|
||||
|
||||
case "AuthUser.displayName":
|
||||
if e.complexity.AuthUser.DisplayName == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.AuthUser.DisplayName(childComplexity), true
|
||||
|
||||
case "AuthUser.email":
|
||||
if e.complexity.AuthUser.Email == nil {
|
||||
break
|
||||
@@ -97,6 +91,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||
|
||||
return e.complexity.AuthUser.ID(childComplexity), true
|
||||
|
||||
case "AuthUser.name":
|
||||
if e.complexity.AuthUser.Name == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.AuthUser.Name(childComplexity), true
|
||||
|
||||
case "AuthUser.roleID":
|
||||
if e.complexity.AuthUser.RoleID == nil {
|
||||
break
|
||||
@@ -104,24 +105,36 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||
|
||||
return e.complexity.AuthUser.RoleID(childComplexity), true
|
||||
|
||||
case "Mutation.login":
|
||||
if e.complexity.Mutation.Login == nil {
|
||||
case "Mutation.accountLogin":
|
||||
if e.complexity.Mutation.AccountLogin == nil {
|
||||
break
|
||||
}
|
||||
|
||||
args, err := ec.field_Mutation_login_args(context.TODO(), rawArgs)
|
||||
args, err := ec.field_Mutation_accountLogin_args(context.TODO(), rawArgs)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return e.complexity.Mutation.Login(childComplexity, args["email"].(string), args["pwd"].(string)), true
|
||||
return e.complexity.Mutation.AccountLogin(childComplexity, args["email"].(string), args["pwd"].(string)), true
|
||||
|
||||
case "Mutation.logout":
|
||||
if e.complexity.Mutation.Logout == nil {
|
||||
case "Mutation.accountLogout":
|
||||
if e.complexity.Mutation.AccountLogout == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.Mutation.Logout(childComplexity), true
|
||||
return e.complexity.Mutation.AccountLogout(childComplexity), true
|
||||
|
||||
case "Mutation.accountVerifyEmail":
|
||||
if e.complexity.Mutation.AccountVerifyEmail == nil {
|
||||
break
|
||||
}
|
||||
|
||||
args, err := ec.field_Mutation_accountVerifyEmail_args(context.TODO(), rawArgs)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return e.complexity.Mutation.AccountVerifyEmail(childComplexity, args["token"].(*string)), true
|
||||
|
||||
case "Query.me":
|
||||
if e.complexity.Query.Me == nil {
|
||||
@@ -235,8 +248,20 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er
|
||||
|
||||
var sources = []*ast.Source{
|
||||
{Name: "../account.graphql", Input: `extend type Mutation {
|
||||
login(email: String!, pwd: String!): AuthUser!
|
||||
logout: Boolean!
|
||||
"""
|
||||
Verify email token
|
||||
"""
|
||||
accountVerifyEmail(token: String): Boolean!
|
||||
|
||||
"""
|
||||
User account login
|
||||
"""
|
||||
accountLogin(email: String!, pwd: String!): AuthUser!
|
||||
|
||||
"""
|
||||
User account logout
|
||||
"""
|
||||
accountLogout: Boolean!
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
@@ -244,9 +269,9 @@ extend type Query {
|
||||
}
|
||||
|
||||
type AuthUser {
|
||||
id: ID!
|
||||
id: UID!
|
||||
email: String!
|
||||
displayName: String!
|
||||
name: String!
|
||||
roleID: Int!
|
||||
}
|
||||
`, BuiltIn: false},
|
||||
@@ -258,6 +283,10 @@ type Mutation
|
||||
|
||||
type Query
|
||||
|
||||
scalar UID
|
||||
|
||||
scalar Int64
|
||||
|
||||
"""
|
||||
Maps a Time GraphQL scalar to a Go time.Time struct.
|
||||
"""
|
||||
@@ -272,6 +301,7 @@ scalar Map
|
||||
Go type interface{}
|
||||
"""
|
||||
scalar Any
|
||||
|
||||
scalar Void
|
||||
|
||||
"""
|
||||
|
@@ -3,10 +3,10 @@
|
||||
package model
|
||||
|
||||
type AuthUser struct {
|
||||
ID string `json:"id"`
|
||||
Email string `json:"email"`
|
||||
DisplayName string `json:"displayName"`
|
||||
RoleID int `json:"roleID"`
|
||||
ID string `json:"id"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
RoleID int `json:"roleID"`
|
||||
}
|
||||
|
||||
type Mutation struct {
|
||||
|
@@ -6,6 +6,10 @@ type Mutation
|
||||
|
||||
type Query
|
||||
|
||||
scalar UID
|
||||
|
||||
scalar Int64
|
||||
|
||||
"""
|
||||
Maps a Time GraphQL scalar to a Go time.Time struct.
|
||||
"""
|
||||
@@ -20,6 +24,7 @@ scalar Map
|
||||
Go type interface{}
|
||||
"""
|
||||
scalar Any
|
||||
|
||||
scalar Void
|
||||
|
||||
"""
|
||||
|
@@ -1,43 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"gitserver.in/patialtech/mux"
|
||||
"gitserver.in/patialtech/mux/middleware"
|
||||
"gitserver.in/patialtech/rano/config"
|
||||
"gitserver.in/patialtech/rano/graph"
|
||||
"gitserver.in/patialtech/rano/util/logger"
|
||||
)
|
||||
|
||||
func main() {
|
||||
r := mux.NewRouter()
|
||||
// CORS
|
||||
r.Use(middleware.CORS(middleware.CORSOption{
|
||||
AllowedHeaders: []string{"Content-Type"},
|
||||
MaxAge: 60,
|
||||
}))
|
||||
// Secure Headers
|
||||
r.Use(middleware.Helmet(middleware.HelmetOption{
|
||||
ContentSecurityPolicy: middleware.CSP{
|
||||
ScriptSrc: []string{"self", "https://cdn.jsdelivr.net", "unsafe-inline"},
|
||||
},
|
||||
}))
|
||||
|
||||
// graphiql
|
||||
r.GET("/graphiql", graph.GraphiQL("/query"))
|
||||
// graph query
|
||||
r.POST("/query", graph.Query)
|
||||
|
||||
// catch all
|
||||
r.GET("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("hello there"))
|
||||
})
|
||||
|
||||
r.Serve(func(srv *http.Server) error {
|
||||
srv.Addr = fmt.Sprintf(":%d", config.Read().GraphPort)
|
||||
logger.Info("graph server listening on %s", srv.Addr)
|
||||
return srv.ListenAndServe()
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user