mirror of
https://github.com/Unkn0wnCat/calapi.git
synced 2025-06-07 18:51:38 +02:00
Add authentication and metrics
This commit is contained in:
parent
7667ea7b90
commit
6abea91d7c
16 changed files with 894 additions and 31 deletions
|
@ -79,6 +79,7 @@ type ComplexityRoot struct {
|
|||
DeleteEvent func(childComplexity int, input string) int
|
||||
EditCalendar func(childComplexity int, input model.EditCalendar) int
|
||||
EditEvent func(childComplexity int, input model.EditEvent) int
|
||||
Login func(childComplexity int, input model.Login) int
|
||||
}
|
||||
|
||||
Query struct {
|
||||
|
@ -107,6 +108,7 @@ type MutationResolver interface {
|
|||
CreateCalendar(ctx context.Context, input model.NewCalendar) (*model.Calendar, error)
|
||||
EditCalendar(ctx context.Context, input model.EditCalendar) (*model.Calendar, error)
|
||||
DeleteCalendar(ctx context.Context, input string) (bool, error)
|
||||
Login(ctx context.Context, input model.Login) (string, error)
|
||||
}
|
||||
type QueryResolver interface {
|
||||
Events(ctx context.Context, after *time.Time, before *time.Time, calendar *string) ([]*model.Event, error)
|
||||
|
@ -312,6 +314,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
|||
|
||||
return e.complexity.Mutation.EditEvent(childComplexity, args["input"].(model.EditEvent)), true
|
||||
|
||||
case "Mutation.login":
|
||||
if e.complexity.Mutation.Login == nil {
|
||||
break
|
||||
}
|
||||
|
||||
args, err := ec.field_Mutation_login_args(context.TODO(), rawArgs)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return e.complexity.Mutation.Login(childComplexity, args["input"].(model.Login)), true
|
||||
|
||||
case "Query.calendar":
|
||||
if e.complexity.Query.Calendar == nil {
|
||||
break
|
||||
|
@ -379,6 +393,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
|
|||
inputUnmarshalMap := graphql.BuildUnmarshalerMap(
|
||||
ec.unmarshalInputEditCalendar,
|
||||
ec.unmarshalInputEditEvent,
|
||||
ec.unmarshalInputLogin,
|
||||
ec.unmarshalInputNewCalendar,
|
||||
ec.unmarshalInputNewEvent,
|
||||
ec.unmarshalInputSetLocation,
|
||||
|
@ -575,6 +590,21 @@ func (ec *executionContext) field_Mutation_editEvent_args(ctx context.Context, r
|
|||
return args, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Mutation_login_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
|
||||
var err error
|
||||
args := map[string]interface{}{}
|
||||
var arg0 model.Login
|
||||
if tmp, ok := rawArgs["input"]; ok {
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("input"))
|
||||
arg0, err = ec.unmarshalNLogin2githubᚗcomᚋUnkn0wnCatᚋcalapiᚋgraphᚋmodelᚐLogin(ctx, tmp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
args["input"] = arg0
|
||||
return args, 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{}{}
|
||||
|
@ -1759,6 +1789,60 @@ func (ec *executionContext) fieldContext_Mutation_deleteCalendar(ctx context.Con
|
|||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Mutation_login(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
fc, err := ec.fieldContext_Mutation_login(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().Login(rctx, fc.Args["input"].(model.Login))
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalNString2string(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) {
|
||||
return nil, errors.New("field of type String 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_login_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Query_events(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
fc, err := ec.fieldContext_Query_events(ctx, field)
|
||||
if err != nil {
|
||||
|
@ -4118,6 +4202,42 @@ func (ec *executionContext) unmarshalInputEditEvent(ctx context.Context, obj int
|
|||
return it, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalInputLogin(ctx context.Context, obj interface{}) (model.Login, error) {
|
||||
var it model.Login
|
||||
asMap := map[string]interface{}{}
|
||||
for k, v := range obj.(map[string]interface{}) {
|
||||
asMap[k] = v
|
||||
}
|
||||
|
||||
fieldsInOrder := [...]string{"username", "password"}
|
||||
for _, k := range fieldsInOrder {
|
||||
v, ok := asMap[k]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
switch k {
|
||||
case "username":
|
||||
var err error
|
||||
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("username"))
|
||||
it.Username, err = ec.unmarshalNString2string(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
case "password":
|
||||
var err error
|
||||
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("password"))
|
||||
it.Password, err = ec.unmarshalNString2string(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return it, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalInputNewCalendar(ctx context.Context, obj interface{}) (model.NewCalendar, error) {
|
||||
var it model.NewCalendar
|
||||
asMap := map[string]interface{}{}
|
||||
|
@ -4515,6 +4635,12 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet)
|
|||
return ec._Mutation_deleteCalendar(ctx, field)
|
||||
})
|
||||
|
||||
case "login":
|
||||
|
||||
out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) {
|
||||
return ec._Mutation_login(ctx, field)
|
||||
})
|
||||
|
||||
default:
|
||||
panic("unknown field " + strconv.Quote(field.Name))
|
||||
}
|
||||
|
@ -5150,6 +5276,11 @@ func (ec *executionContext) marshalNID2string(ctx context.Context, sel ast.Selec
|
|||
return res
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalNLogin2githubᚗcomᚋUnkn0wnCatᚋcalapiᚋgraphᚋmodelᚐLogin(ctx context.Context, v interface{}) (model.Login, error) {
|
||||
res, err := ec.unmarshalInputLogin(ctx, v)
|
||||
return res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalNNewCalendar2githubᚗcomᚋUnkn0wnCatᚋcalapiᚋgraphᚋmodelᚐNewCalendar(ctx context.Context, v interface{}) (model.NewCalendar, error) {
|
||||
res, err := ec.unmarshalInputNewCalendar(ctx, v)
|
||||
return res, graphql.ErrorOnPath(ctx, err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue