-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsignatureRequestResolver.ts
More file actions
53 lines (48 loc) · 1.98 KB
/
Copy pathsignatureRequestResolver.ts
File metadata and controls
53 lines (48 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Args, FieldResolver, Query, Resolver, Root } from "type-graphql";
import { GetSignatureRequestsArgs } from "../../../graphql/schemas/args/signatureRequestArgs.js";
import {
GetSignatureRequestResponse,
SignatureRequest,
} from "../../../graphql/schemas/typeDefs/signatureRequestTypeDefs.js";
import { inject, injectable } from "tsyringe";
import { SignatureRequestsService } from "../../database/entities/SignatureRequestsEntityService.js";
/**
* GraphQL resolver for signature requests.
* Handles queries for retrieving signature requests and resolves specific fields.
*
* A signature request represents a message that needs to be signed by a Safe wallet,
* typically used for user data updates or other authenticated operations.
*/
@injectable()
@Resolver(() => SignatureRequest)
export class SignatureRequestResolver {
constructor(
@inject(SignatureRequestsService)
private signatureRequestsService: SignatureRequestsService,
) {}
/**
* Query resolver for fetching signature requests.
* Can be filtered by safe address and status.
*
* @param args - Query arguments including optional safe_address and status filters
* @returns A paginated response containing signature requests and total count
*/
@Query(() => GetSignatureRequestResponse)
async signatureRequests(@Args() args: GetSignatureRequestsArgs) {
return await this.signatureRequestsService.getSignatureRequests(args);
}
/**
* Field resolver for the message field.
* Ensures consistent string representation of messages, whether they're
* stored as objects or strings.
*
* @param signatureRequest - The signature request containing the message
* @returns The message as a string, stringified if it's an object
*/
@FieldResolver(() => String)
message(@Root() signatureRequest: SignatureRequest): string {
return typeof signatureRequest.message === "object"
? JSON.stringify(signatureRequest.message)
: signatureRequest.message || "could not parse message";
}
}