Add last used at to personal api key

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-01-05 16:46:13 +01:00
parent cf72beaba4
commit 71263367f6
11 changed files with 108 additions and 20 deletions

View File

@@ -312,6 +312,7 @@ type PersonalAPIKey implements Node {
id: ID!
name: String!
expiresAt: Datetime!
lastUsedAt: Datetime
createdAt: Datetime!
token: String @goField(forceResolver: true)

View File

@@ -276,6 +276,7 @@ type ComplexityRoot struct {
CreatedAt func(childComplexity int) int
ExpiresAt func(childComplexity int) int
ID func(childComplexity int) int
LastUsedAt func(childComplexity int) int
Name func(childComplexity int) int
Permission func(childComplexity int, action string) int
Token func(childComplexity int) int
@@ -1530,6 +1531,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
}
return e.complexity.PersonalAPIKey.ID(childComplexity), true
case "PersonalAPIKey.lastUsedAt":
if e.complexity.PersonalAPIKey.LastUsedAt == nil {
break
}
return e.complexity.PersonalAPIKey.LastUsedAt(childComplexity), true
case "PersonalAPIKey.name":
if e.complexity.PersonalAPIKey.Name == nil {
break
@@ -2598,6 +2605,7 @@ type PersonalAPIKey implements Node {
id: ID!
name: String!
expiresAt: Datetime!
lastUsedAt: Datetime
createdAt: Datetime!
token: String @goField(forceResolver: true)
@@ -9070,6 +9078,35 @@ func (ec *executionContext) fieldContext_PersonalAPIKey_expiresAt(_ context.Cont
return fc, nil
}
func (ec *executionContext) _PersonalAPIKey_lastUsedAt(ctx context.Context, field graphql.CollectedField, obj *types.PersonalAPIKey) (ret graphql.Marshaler) {
return graphql.ResolveField(
ctx,
ec.OperationContext,
field,
ec.fieldContext_PersonalAPIKey_lastUsedAt,
func(ctx context.Context) (any, error) {
return obj.LastUsedAt, nil
},
nil,
ec.marshalODatetime2ᚖtimeᚐTime,
true,
false,
)
}
func (ec *executionContext) fieldContext_PersonalAPIKey_lastUsedAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "PersonalAPIKey",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type Datetime does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _PersonalAPIKey_createdAt(ctx context.Context, field graphql.CollectedField, obj *types.PersonalAPIKey) (ret graphql.Marshaler) {
return graphql.ResolveField(
ctx,
@@ -9320,6 +9357,8 @@ func (ec *executionContext) fieldContext_PersonalAPIKeyEdge_node(_ context.Conte
return ec.fieldContext_PersonalAPIKey_name(ctx, field)
case "expiresAt":
return ec.fieldContext_PersonalAPIKey_expiresAt(ctx, field)
case "lastUsedAt":
return ec.fieldContext_PersonalAPIKey_lastUsedAt(ctx, field)
case "createdAt":
return ec.fieldContext_PersonalAPIKey_createdAt(ctx, field)
case "token":
@@ -17483,6 +17522,8 @@ func (ec *executionContext) _PersonalAPIKey(ctx context.Context, sel ast.Selecti
if out.Values[i] == graphql.Null {
atomic.AddUint32(&out.Invalids, 1)
}
case "lastUsedAt":
out.Values[i] = ec._PersonalAPIKey_lastUsedAt(ctx, field, obj)
case "createdAt":
out.Values[i] = ec._PersonalAPIKey_createdAt(ctx, field, obj)
if out.Values[i] == graphql.Null {

View File

@@ -61,9 +61,10 @@ func NewPersonalAPIKeyEdge(personalAPIKey *coredata.PersonalAPIKey, orderField c
func NewPersonalAPIKey(personalAPIKey *coredata.PersonalAPIKey) *PersonalAPIKey {
return &PersonalAPIKey{
ID: personalAPIKey.ID,
Name: personalAPIKey.Name,
ExpiresAt: personalAPIKey.ExpiresAt,
CreatedAt: personalAPIKey.CreatedAt,
ID: personalAPIKey.ID,
Name: personalAPIKey.Name,
ExpiresAt: personalAPIKey.ExpiresAt,
LastUsedAt: personalAPIKey.LastUsedAt,
CreatedAt: personalAPIKey.CreatedAt,
}
}

View File

@@ -281,12 +281,13 @@ type PasswordRequired struct {
func (PasswordRequired) IsAssumeOrganizationSessionResult() {}
type PersonalAPIKey struct {
ID gid.GID `json:"id"`
Name string `json:"name"`
ExpiresAt time.Time `json:"expiresAt"`
CreatedAt time.Time `json:"createdAt"`
Token *string `json:"token,omitempty"`
Permission bool `json:"permission"`
ID gid.GID `json:"id"`
Name string `json:"name"`
ExpiresAt time.Time `json:"expiresAt"`
LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
CreatedAt time.Time `json:"createdAt"`
Token *string `json:"token,omitempty"`
Permission bool `json:"permission"`
}
func (PersonalAPIKey) IsNode() {}