Skip to content

Commit ddce469

Browse files
committed
fix(pocket): update request types in future pocket
1 parent f499031 commit ddce469

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

common/state/page-home/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const getHomeQuery = gql`
6666
export async function getHomeSlates(locale: string): Promise<HomeQueryResponse | ResponseError> {
6767
try {
6868
const localeToUse = SUPPORTED_LOCALES.includes(locale) ? locale : 'en'
69-
const response = await pocketRequest<{ homeSlateLineup: CorpusSlateLineup }>({
69+
const response = await pocketRequest<{ homeSlateLineup: CorpusSlateLineup }, null>({
7070
query: getHomeQuery,
7171
variables: { locale: localeToUse }
7272
})

common/state/page-saves/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export async function getUserSaves(
8888

8989
if (!isAuthenticated) throw new PageSavesError('User not authenticated')
9090

91-
const response = await pocketRequest<{ user: Pick<User, 'savedItems'> }>(
91+
const response = await pocketRequest<{ user: Pick<User, 'savedItems'> }, UserSavesArguments>(
9292
{
9393
query: getUserSavesQuery,
9494
variables

common/state/user-info/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export async function getUser(): Promise<UserDisplayData | ResponseError> {
4040
const { token, isAuthenticated } = await verifySession()
4141
if (!isAuthenticated) throw new UserRequestError('User not authenticated')
4242

43-
const response = await pocketRequest<{ user: User }>({ query: getUserQuery }, token)
43+
const response = await pocketRequest<{ user: User }, null>({ query: getUserQuery }, token)
4444
const user: User = response?.user
4545

4646
if (!user) throw new UserRequestError('User response was not valid')

common/utilities/request/index.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Define the structure of a GraphQL request body
55
* `variables` are optional and can be any shape you need.
66
*/
7-
interface GraphQLRequestBody {
7+
interface GraphQLRequestBody<RequestData> {
88
query: string
9-
variables?: Record<string, unknown>
9+
variables?: RequestData | Record<string, unknown>
1010
}
1111

1212
/**
@@ -42,9 +42,9 @@ export const gql = String.raw
4242
* It accepts a request body, an optional auth token, and extra headers.
4343
* The function then returns the typed data (T).
4444
*/
45-
export async function gqlRequest<T>(
45+
export async function gqlRequest<T, RequestData>(
4646
client: string,
47-
data: GraphQLRequestBody,
47+
data: GraphQLRequestBody<RequestData>,
4848
token?: string
4949
): Promise<T> {
5050
// Build headers. If an auth token is provided, set the Authorization header.
@@ -87,15 +87,21 @@ export async function gqlRequest<T>(
8787
/**
8888
* Convenience function that sets web-client as the client,
8989
*/
90-
export async function pocketRequest<T>(body: GraphQLRequestBody, token?: string): Promise<T> {
91-
return gqlRequest<T>('web-client', body, token)
90+
export async function pocketRequest<T, RequestData>(
91+
body: GraphQLRequestBody<RequestData>,
92+
token?: string
93+
): Promise<T> {
94+
return gqlRequest<T, RequestData>('web-client', body, token)
9295
}
9396

9497
/**
9598
* Convenience function that sets web-client as the client,
9699
*/
97-
export async function extensionRequest<T>(body: GraphQLRequestBody, token?: string): Promise<T> {
98-
return gqlRequest<T>('web-extension', body, token)
100+
export async function extensionRequest<T, RequestData>(
101+
body: GraphQLRequestBody<RequestData>,
102+
token?: string
103+
): Promise<T> {
104+
return gqlRequest<T, RequestData>('web-extension', body, token)
99105
}
100106

101107
class GraphQLRequestError extends Error {

0 commit comments

Comments
 (0)