Skip to content

Commit

Permalink
feat: improve PersistedQueryProvider types (#1121)
Browse files Browse the repository at this point in the history
* feat: improve PersistedQueryProvider types

* feat: add tests
  • Loading branch information
marcoreni authored Dec 12, 2024
1 parent b5cfac8 commit 8d6c319
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ declare namespace mercurius {
/**
* Return the query for a given hash.
*/
getQueryFromHash: (hash: string) => Promise<string>;
getQueryFromHash: (hash: string) => Promise<string | undefined>;
/**
* Return the hash for a given query string. Do not provide if you want to skip saving new queries.
*/
Expand Down
33 changes: 33 additions & 0 deletions test/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,3 +654,36 @@ expectType<typeof mercurius.ErrorWithProps>(ErrorWithProps)
expectType<typeof mercurius.defaultErrorFormatter>(defaultErrorFormatter)
expectType<typeof mercurius.persistedQueryDefaults>(persistedQueryDefaults)
expectType<typeof mercurius.withFilter>(withFilter)

app.register(mercurius, {
schema,
resolvers,
persistedQueryProvider: {
...persistedQueryDefaults.automatic(),
getQueryFromHash: () => {
return Promise.resolve('foo')
},
}
})

app.register(mercurius, {
schema,
resolvers,
persistedQueryProvider: {
...persistedQueryDefaults.automatic(),
getQueryFromHash: () => {
return Promise.resolve(undefined)
},
}
})

expectError(app.register(mercurius, {
schema,
resolvers,
persistedQueryProvider: {
...persistedQueryDefaults.automatic(),
getQueryFromHash: () => {
return Promise.resolve(false)
},
}
}))

0 comments on commit 8d6c319

Please sign in to comment.