78 lines
1.5 KiB
TypeScript
78 lines
1.5 KiB
TypeScript
import 'server-only';
|
|
import { ApolloError, gql } from "apollo-server-micro";
|
|
import { pageTypeDefs } from "./page";
|
|
import { GAME_SYSTEMS } from "@/lib/game";
|
|
|
|
export const gameTypeDefs = gql`
|
|
${pageTypeDefs}
|
|
|
|
enum GameSystem {
|
|
${GAME_SYSTEMS.join('\n')}
|
|
}
|
|
|
|
type Game {
|
|
id: ID!
|
|
name: String!
|
|
system: GameSystem!
|
|
}
|
|
|
|
input GameFilter {
|
|
system: GameSystem
|
|
}
|
|
|
|
enum GameOrderBy {
|
|
NAME_ASC
|
|
NAME_DESC
|
|
}
|
|
|
|
type GameEdge {
|
|
node: Game
|
|
cursor: String
|
|
}
|
|
|
|
type GameConnection {
|
|
edges: [GameEdge]
|
|
pageInfo: PageInfo
|
|
}
|
|
|
|
type Query {
|
|
game(id: ID!): Game
|
|
games(first: Int!, after: String, orderBy: GameOrderBy, filter: GameFilter): GameConnection
|
|
}
|
|
`;
|
|
|
|
const GAME = {
|
|
id: '0',
|
|
name: 'Pokemon Crystal Version',
|
|
system: 'gbc'
|
|
};
|
|
|
|
export const gameResolvers = {
|
|
Query: {
|
|
game: (_:any, { id }:{ id:string }) => {
|
|
if(!id) throw new ApolloError('Invalid ID');
|
|
|
|
switch(id) {
|
|
case '0':
|
|
return GAME;
|
|
|
|
default:
|
|
return null;
|
|
}
|
|
},
|
|
|
|
games: (_: any, { first, after, orderBy, filter }: { first: number, after?: string, orderBy?: string, filter?: { system?: string } }) => {
|
|
if(first > 100) throw new ApolloError('first cannot be greater than 100');
|
|
return {
|
|
edges: [
|
|
{ node: GAME }
|
|
],
|
|
pageInfo: {
|
|
hasNextPage: false,
|
|
hasPreviousPage: false,
|
|
startCursor: '0'
|
|
},
|
|
};
|
|
},
|
|
},
|
|
}; |