Cleanup game stuff before I redo pagination.
This commit is contained in:
@ -21,7 +21,9 @@ builder.queryField('games', (t) => (
|
|||||||
builder.queryField('game', (t) => (
|
builder.queryField('game', (t) => (
|
||||||
t.prismaField({
|
t.prismaField({
|
||||||
type: 'Game',
|
type: 'Game',
|
||||||
args: { id: t.arg.string() },
|
args: {
|
||||||
|
id: t.arg.id()
|
||||||
|
},
|
||||||
resolve: (q, _p, { id }) => {
|
resolve: (q, _p, { id }) => {
|
||||||
if(!id) return null;
|
if(!id) return null;
|
||||||
return database.game.findUnique({ where: { uuid: id } })
|
return database.game.findUnique({ where: { uuid: id } })
|
||||||
|
@ -8,31 +8,32 @@ import { extendFragment, includeFragment } from '@/lib/fragment';
|
|||||||
import { Paginated, paginationQuery } from '@/lib/page';
|
import { Paginated, paginationQuery } from '@/lib/page';
|
||||||
|
|
||||||
type PageProps = {
|
type PageProps = {
|
||||||
games:Paginated<GameLight>|null;
|
games:GameLight[];
|
||||||
} | Error500Props;
|
} | Error500Props;
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps<PageProps> = async () => {
|
export const getServerSideProps:GetServerSideProps<PageProps> = async () => {
|
||||||
try {
|
try {
|
||||||
const client = await apiClientGet();
|
const client = await apiClientGet();
|
||||||
const res = await client.query<{ games:Paginated<GameLight> }>({
|
const res = await client.query<{ games:GameLight[] }>({
|
||||||
variables: {
|
variables: {
|
||||||
after: null,
|
after: null,
|
||||||
},
|
},
|
||||||
query: gql`
|
query: gql`
|
||||||
${includeFragment(GameLightFragment)}
|
${includeFragment(GameLightFragment)}
|
||||||
|
|
||||||
query getGames {
|
query getGames {
|
||||||
games(first: 100) {
|
games {
|
||||||
${paginationQuery(extendFragment(GameLightFragment))}
|
${extendFragment(GameLightFragment)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
});
|
});
|
||||||
|
|
||||||
if(!res || !res.data || !res.data.games) {
|
if(!res || !res.data || !res.data.games) {
|
||||||
return { props: { games:null } };
|
return { props: { games:[] } };
|
||||||
}
|
}
|
||||||
|
|
||||||
return { props: { games: res.data.games } };
|
return { props: { games: res.data.games } };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error', e);
|
console.error('Error', e);
|
||||||
return { props: { code: 500 } };
|
return { props: { code: 500 } };
|
||||||
@ -54,11 +55,11 @@ export const Page: React.FC<PageProps> = props => {
|
|||||||
<div>
|
<div>
|
||||||
<h1>Games</h1>
|
<h1>Games</h1>
|
||||||
<ul>
|
<ul>
|
||||||
{games.edges.map(({ node }) => {
|
{games.map(node => {
|
||||||
return (
|
return (
|
||||||
<li key={node.id}>
|
<li key={node.id}>
|
||||||
<Link href={`/games/${node.id}`}>
|
<Link href={`/games/${node.id}`}>
|
||||||
{node.name} ({node.system})
|
{node.title} ({node.system})
|
||||||
</Link>
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user