not found on empty search
This commit is contained in:
parent
afed19430c
commit
f1fd1f3c9c
@ -31,12 +31,20 @@ export default async function getSSRApolloClient (req, me = null) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getGetServerSideProps (query, variables = null, foundField) {
|
export function getGetServerSideProps (query, variables = null, foundField, requireVar) {
|
||||||
return async function ({ req, query: params }) {
|
return async function ({ req, query: params }) {
|
||||||
const client = await getSSRApolloClient(req)
|
const client = await getSSRApolloClient(req)
|
||||||
|
const vars = { ...params, ...variables }
|
||||||
|
|
||||||
|
if (requireVar && !vars[requireVar]) {
|
||||||
|
return {
|
||||||
|
notFound: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const { error, data } = await client.query({
|
const { error, data } = await client.query({
|
||||||
query,
|
query,
|
||||||
variables: { ...params, ...variables }
|
variables: vars
|
||||||
})
|
})
|
||||||
|
|
||||||
if (error || !data || (foundField && !data[foundField])) {
|
if (error || !data || (foundField && !data[foundField])) {
|
||||||
|
@ -4,7 +4,7 @@ import { ITEM_SEARCH } from '../fragments/items'
|
|||||||
import SearchItems from '../components/search-items'
|
import SearchItems from '../components/search-items'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
|
|
||||||
export const getServerSideProps = getGetServerSideProps(ITEM_SEARCH)
|
export const getServerSideProps = getGetServerSideProps(ITEM_SEARCH, null, null, 'q')
|
||||||
|
|
||||||
export default function Index ({ data: { search: { items, cursor } } }) {
|
export default function Index ({ data: { search: { items, cursor } } }) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user