Loading save files done.
This commit is contained in:
77
src/graphql/game.ts
Normal file
77
src/graphql/game.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { GAME_SYSTEMS } from "@/lib/game";
|
||||
import { ApolloError, gql } from "apollo-server-micro";
|
||||
import { pageTypeDefs } from "./page";
|
||||
|
||||
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'
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user