diff --git a/api/resolvers/item.js b/api/resolvers/item.js index 54673d7c..a34fc822 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -1,5 +1,5 @@ import { ensureProtocol, removeTracking, stripTrailingSlash } from '@/lib/url' -import { decodeCursor, LIMIT, nextCursorEncoded } from '@/lib/cursor' +import { decodeCursor, nextCursorEncoded } from '@/lib/cursor' import { getMetadata, metadataRuleSets } from 'page-metadata-parser' import { ruleSet as publicationDateRuleSet } from '@/lib/timedate-scraper' import domino from 'domino' @@ -362,7 +362,7 @@ export default { return count }, - items: async (parent, { sub, sort, type, cursor, name, when, from, to, by, limit = LIMIT }, { me, models }) => { + items: async (parent, { sub, sort, type, cursor, name, when, from, to, by, limit }, { me, models }) => { const decodedCursor = decodeCursor(cursor) let items, user, pins, subFull, table, ad diff --git a/api/resolvers/search.js b/api/resolvers/search.js index a042a9f6..99dcd07f 100644 --- a/api/resolvers/search.js +++ b/api/resolvers/search.js @@ -24,7 +24,7 @@ function queryParts (q) { export default { Query: { - related: async (parent, { title, id, cursor, limit = LIMIT, minMatch }, { me, models, search }) => { + related: async (parent, { title, id, cursor, limit, minMatch }, { me, models, search }) => { const decodedCursor = decodeCursor(cursor) if (!id && (!title || title.trim().split(/\s+/).length < 1)) { diff --git a/api/resolvers/sub.js b/api/resolvers/sub.js index 25aede5a..0f0e38d6 100644 --- a/api/resolvers/sub.js +++ b/api/resolvers/sub.js @@ -37,7 +37,7 @@ export async function getSub (parent, { name }, { models, me }) { export default { Query: { sub: getSub, - subSuggestions: async (parent, { q, limit = 5 }, { models }) => { + subSuggestions: async (parent, { q, limit }, { models }) => { let subs = [] subs = await models.$queryRaw` SELECT name @@ -88,7 +88,7 @@ export default { return latest?.createdAt }, - topSubs: async (parent, { cursor, when, by, from, to, limit = LIMIT }, { models, me }) => { + topSubs: async (parent, { cursor, when, by, from, to, limit }, { models, me }) => { const decodedCursor = decodeCursor(cursor) const range = whenRange(when, from, to || decodeCursor.time) @@ -120,7 +120,7 @@ export default { subs } }, - userSubs: async (_parent, { name, cursor, when, by, from, to, limit = LIMIT }, { models, me }) => { + userSubs: async (_parent, { name, cursor, when, by, from, to, limit }, { models, me }) => { if (!name) { throw new GqlInputError('must supply user name') } diff --git a/api/resolvers/user.js b/api/resolvers/user.js index 9c5bb75b..25e6a113 100644 --- a/api/resolvers/user.js +++ b/api/resolvers/user.js @@ -55,7 +55,7 @@ async function authMethods (user, args, { models, me }) { } } -export async function topUsers (parent, { cursor, when, by, from, to, limit = LIMIT }, { models, me }) { +export async function topUsers (parent, { cursor, when, by, from, to, limit }, { models, me }) { const decodedCursor = decodeCursor(cursor) const range = whenRange(when, from, to || decodeCursor.time) @@ -213,7 +213,7 @@ export default { users } }, - userSuggestions: async (parent, { q, limit = 5 }, { models }) => { + userSuggestions: async (parent, { q, limit }, { models }) => { let users = [] if (q) { users = await models.$queryRaw` @@ -605,7 +605,7 @@ export default { SELECT * FROM users WHERE (id > ${RESERVED_MAX_USER_ID} OR id IN (${USER_ID.anon}, ${USER_ID.delete})) - AND SIMILARITY(name, ${q}) > ${Number(similarity) || 0.1} ORDER BY SIMILARITY(name, ${q}) DESC LIMIT ${Number(limit) || 5}` + AND SIMILARITY(name, ${q}) > ${Number(similarity) || 0.1} ORDER BY SIMILARITY(name, ${q}) DESC LIMIT ${Number(limit)}` }, userStatsActions: async (parent, { when, from, to }, { me, models }) => { const range = whenRange(when, from, to) diff --git a/api/typeDefs/item.js b/api/typeDefs/item.js index 9fde3fa3..a4e0a988 100644 --- a/api/typeDefs/item.js +++ b/api/typeDefs/item.js @@ -1,12 +1,13 @@ import { gql } from 'graphql-tag' +import { LIMIT } from '@/lib/cursor' export default gql` extend type Query { - items(sub: String, sort: String, type: String, cursor: String, name: String, when: String, from: String, to: String, by: String, limit: Limit): Items + items(sub: String, sort: String, type: String, cursor: String, name: String, when: String, from: String, to: String, by: String, limit: Limit! = ${LIMIT}): Items item(id: ID!): Item pageTitleAndUnshorted(url: String!): TitleUnshorted dupes(url: String!): [Item!] - related(cursor: String, title: String, id: ID, minMatch: String, limit: Limit): Items + related(cursor: String, title: String, id: ID, minMatch: String, limit: Limit! = ${LIMIT}): Items search(q: String, sub: String, cursor: String, what: String, sort: String, when: String, from: String, to: String): Items auctionPosition(sub: String, id: ID, boost: Int): Int! boostPosition(sub: String, id: ID, boost: Int): BoostPositions! diff --git a/api/typeDefs/sub.js b/api/typeDefs/sub.js index 679db42e..8bf8bd2a 100644 --- a/api/typeDefs/sub.js +++ b/api/typeDefs/sub.js @@ -1,14 +1,15 @@ import { gql } from 'graphql-tag' +import { LIMIT } from '@/lib/cursor' export default gql` extend type Query { sub(name: String): Sub subLatestPost(name: String!): String subs: [Sub!]! - topSubs(cursor: String, when: String, from: String, to: String, by: String, limit: Limit): Subs - userSubs(name: String!, cursor: String, when: String, from: String, to: String, by: String, limit: Limit): Subs + topSubs(cursor: String, when: String, from: String, to: String, by: String, limit: Limit! = ${LIMIT}): Subs + userSubs(name: String!, cursor: String, when: String, from: String, to: String, by: String, limit: Limit! = ${LIMIT}): Subs mySubscribedSubs(cursor: String): Subs - subSuggestions(q: String!, limit: Limit): [Sub!]! + subSuggestions(q: String!, limit: Limit! = 5): [Sub!]! } type Subs { diff --git a/api/typeDefs/user.js b/api/typeDefs/user.js index f4a8c4d8..c41bb267 100644 --- a/api/typeDefs/user.js +++ b/api/typeDefs/user.js @@ -1,4 +1,5 @@ import { gql } from 'graphql-tag' +import { LIMIT } from '@/lib/cursor' export default gql` extend type Query { @@ -7,10 +8,10 @@ export default gql` user(id: ID, name: String): User users: [User!] nameAvailable(name: String!): Boolean! - topUsers(cursor: String, when: String, from: String, to: String, by: String, limit: Limit): UsersNullable! + topUsers(cursor: String, when: String, from: String, to: String, by: String, limit: Limit! = ${LIMIT}): UsersNullable! topCowboys(cursor: String): UsersNullable! - searchUsers(q: String!, limit: Limit, similarity: Float): [User!]! - userSuggestions(q: String, limit: Limit): [User!]! + searchUsers(q: String!, limit: Limit! = 5, similarity: Float): [User!]! + userSuggestions(q: String, limit: Limit! = 5): [User!]! hasNewNotes: Boolean! mySubscribedUsers(cursor: String): Users! myMutedUsers(cursor: String): Users!