initial commit
This commit is contained in:
6
src/graphql/index.ts
Normal file
6
src/graphql/index.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { mergeTypeDefs, mergeResolvers } from "../mods";
|
||||
|
||||
const modules = [require("./sudoku")];
|
||||
|
||||
export const typeDefs = mergeTypeDefs(modules.map((mod) => mod.typeDefs));
|
||||
export const resolvers = mergeResolvers(modules.map((mod) => mod.resolvers));
|
55
src/graphql/sudoku.ts
Normal file
55
src/graphql/sudoku.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import { gql } from "../mods";
|
||||
import { generate } from "../sudoku/index";
|
||||
|
||||
export const typeDefs = gql`
|
||||
type Cell {
|
||||
value: Int
|
||||
}
|
||||
"""
|
||||
A sudoku
|
||||
"""
|
||||
type Sudoku {
|
||||
"The width of each region."
|
||||
regionWidth: Int!
|
||||
|
||||
"The height of each region."
|
||||
regionHeight: Int!
|
||||
|
||||
"The total number of cells in the board."
|
||||
cells: Int!
|
||||
|
||||
"The 'raw' board, an array of cells in region-first order."
|
||||
raw: [Cell!]!
|
||||
|
||||
"The rows of the board, from top to bottom."
|
||||
rows: [[Cell!]!]!
|
||||
|
||||
"The columns of the board, from left to right."
|
||||
columns: [[Cell!]!]!
|
||||
|
||||
"The regions of the board, book-ordered."
|
||||
regions: [[Cell!]!]!
|
||||
}
|
||||
|
||||
type Query {
|
||||
"Generates a new sudoku."
|
||||
generate(regionWidth: Int = 3, regionHeight: Int = 3, clues: Int!): Sudoku!
|
||||
}
|
||||
`;
|
||||
|
||||
type GenerateArguments = {
|
||||
regionWidth: number;
|
||||
regionHeight: number;
|
||||
clues: number;
|
||||
};
|
||||
|
||||
export const resolvers = {
|
||||
Query: {
|
||||
generate: (
|
||||
obj: any,
|
||||
{ regionWidth, regionHeight, clues }: GenerateArguments
|
||||
) => {
|
||||
return generate(regionWidth, regionHeight, clues);
|
||||
},
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user