This commit is contained in:
2021-02-04 15:31:07 -05:00
parent 082f923482
commit a5692babb8
20 changed files with 319 additions and 348 deletions

View File

@@ -43,6 +43,7 @@ type ResolverRoot interface {
type DirectiveRoot struct {
HasMinRole func(ctx context.Context, obj interface{}, next graphql.Resolver, role model.Role) (res interface{}, err error)
IsPrivate func(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error)
Meta func(ctx context.Context, obj interface{}, next graphql.Resolver, gorm *string) (res interface{}, err error)
}
@@ -243,21 +244,21 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.AlbumResponse.PageInfo(childComplexity), true
case "AuthResponse.Device":
case "AuthResponse.device":
if e.complexity.AuthResponse.Device == nil {
break
}
return e.complexity.AuthResponse.Device(childComplexity), true
case "AuthResponse.Error":
case "AuthResponse.error":
if e.complexity.AuthResponse.Error == nil {
break
}
return e.complexity.AuthResponse.Error(childComplexity), true
case "AuthResponse.Result":
case "AuthResponse.result":
if e.complexity.AuthResponse.Result == nil {
break
}
@@ -863,6 +864,7 @@ scalar Upload
# https://gqlgen.com/reference/directives/
directive @hasMinRole(role: Role!) on FIELD_DEFINITION
directive @isPrivate on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
directive @meta(
gorm: String,
@@ -899,9 +901,9 @@ enum AuthResult {
}
type AuthResponse {
Result: AuthResult!
Device: Device
Error: String
result: AuthResult!
device: Device
error: String
}
# ------------------------------------------------------------
@@ -1004,7 +1006,7 @@ type Device {
type: DeviceType! @meta(gorm: "default:Unknown;not null")
userID: ID! @meta(gorm: "not null")
user: User! @meta(gorm: "foreignKey:ID;references:UserID;not null")
refreshKey: String
refreshKey: String @deprecated(reason: "Private Field") # @isPrivate
}
type User {
@@ -1017,7 +1019,7 @@ type User {
lastName: String
role: Role! @meta(gorm: "default:User;not null")
authType: AuthType! @meta(gorm: "default:Local;not null")
password: String
password: String @deprecated(reason: "Private Field") #@isPrivate
}
type MediaItem {
@@ -1927,7 +1929,7 @@ func (ec *executionContext) _AlbumResponse_pageInfo(ctx context.Context, field g
return ec.marshalNPageInfo2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐPageInfo(ctx, field.Selections, res)
}
func (ec *executionContext) _AuthResponse_Result(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
func (ec *executionContext) _AuthResponse_result(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
@@ -1962,7 +1964,7 @@ func (ec *executionContext) _AuthResponse_Result(ctx context.Context, field grap
return ec.marshalNAuthResult2reichardᚗioᚋimaginiᚋgraphᚋmodelᚐAuthResult(ctx, field.Selections, res)
}
func (ec *executionContext) _AuthResponse_Device(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
func (ec *executionContext) _AuthResponse_device(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
@@ -1994,7 +1996,7 @@ func (ec *executionContext) _AuthResponse_Device(ctx context.Context, field grap
return ec.marshalODevice2ᚖreichardᚗioᚋimaginiᚋgraphᚋmodelᚐDevice(ctx, field.Selections, res)
}
func (ec *executionContext) _AuthResponse_Error(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
func (ec *executionContext) _AuthResponse_error(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
@@ -7553,15 +7555,15 @@ func (ec *executionContext) _AuthResponse(ctx context.Context, sel ast.Selection
switch field.Name {
case "__typename":
out.Values[i] = graphql.MarshalString("AuthResponse")
case "Result":
out.Values[i] = ec._AuthResponse_Result(ctx, field, obj)
case "result":
out.Values[i] = ec._AuthResponse_result(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
case "Device":
out.Values[i] = ec._AuthResponse_Device(ctx, field, obj)
case "Error":
out.Values[i] = ec._AuthResponse_Error(ctx, field, obj)
case "device":
out.Values[i] = ec._AuthResponse_device(ctx, field, obj)
case "error":
out.Values[i] = ec._AuthResponse_error(ctx, field, obj)
default:
panic("unknown field " + strconv.Quote(field.Name))
}

View File

@@ -33,9 +33,9 @@ type AlbumResponse struct {
}
type AuthResponse struct {
Result AuthResult `json:"Result" `
Device *Device `json:"Device" `
Error *string `json:"Error" `
Result AuthResult `json:"result" `
Device *Device `json:"device" `
Error *string `json:"error" `
}
type AuthTypeFilter struct {

View File

@@ -5,6 +5,7 @@ scalar Upload
# https://gqlgen.com/reference/directives/
directive @hasMinRole(role: Role!) on FIELD_DEFINITION
directive @isPrivate on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
directive @meta(
gorm: String,
@@ -41,9 +42,9 @@ enum AuthResult {
}
type AuthResponse {
Result: AuthResult!
Device: Device
Error: String
result: AuthResult!
device: Device
error: String
}
# ------------------------------------------------------------
@@ -146,7 +147,7 @@ type Device {
type: DeviceType! @meta(gorm: "default:Unknown;not null")
userID: ID! @meta(gorm: "not null")
user: User! @meta(gorm: "foreignKey:ID;references:UserID;not null")
refreshKey: String
refreshKey: String @isPrivate
}
type User {
@@ -159,7 +160,7 @@ type User {
lastName: String
role: Role! @meta(gorm: "default:User;not null")
authType: AuthType! @meta(gorm: "default:Local;not null")
password: String
password: String @isPrivate
}
type MediaItem {

View File

@@ -75,6 +75,8 @@ func (r *queryResolver) Login(ctx context.Context, user string, password string,
}
} else {
foundDevice.Type = deriveDeviceType(req)
foundDevice.UserID = foundUser.ID
// TODO: foundDevice.User = &foundUser
err := r.DB.CreateDevice(&foundDevice)
if err != nil {
return &model.AuthResponse{Result: model.AuthResultFailure}, nil
@@ -97,6 +99,8 @@ func (r *queryResolver) Login(ctx context.Context, user string, password string,
http.SetCookie(*resp, &accessCookie)
http.SetCookie(*resp, &refreshCookie)
// TODO: Prob bandaid
foundDevice.User = &foundUser
return &model.AuthResponse{Result: model.AuthResultSuccess, Device: &foundDevice}, nil
}