initial commit

This commit is contained in:
2021-02-19 18:30:02 -07:00
parent e13b4d737b
commit 7f9cffbfdd
16 changed files with 2865 additions and 0 deletions

6
src/graphql/index.ts Normal file
View 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
View 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);
},
},
};