Skip to content

Commit

Permalink
feat(init): ༼ つ ◕_◕ ༽つ Woovi Playground
Browse files Browse the repository at this point in the history
  • Loading branch information
Eckzzo committed Apr 17, 2023
1 parent 69a66dc commit 54f7f0a
Show file tree
Hide file tree
Showing 59 changed files with 2,735 additions and 265 deletions.
16 changes: 8 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = {
root: true,
// This tells ESLint to load the config from the package `eslint-config-custom`
extends: ["custom"],
settings: {
next: {
rootDir: ["apps/*/"],
},
},
root: true,
// This tells ESLint to load the config from the package `eslint-config-custom`
extends: ['@woovi-playground/custom'],
settings: {
next: {
rootDir: ['apps/*/'],
},
},
};
4 changes: 0 additions & 4 deletions apps/docs/.eslintrc.js

This file was deleted.

34 changes: 0 additions & 34 deletions apps/docs/.gitignore

This file was deleted.

30 changes: 0 additions & 30 deletions apps/docs/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions apps/docs/next-env.d.ts

This file was deleted.

4 changes: 0 additions & 4 deletions apps/docs/next.config.js

This file was deleted.

25 changes: 0 additions & 25 deletions apps/docs/package.json

This file was deleted.

10 changes: 0 additions & 10 deletions apps/docs/pages/index.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions apps/docs/tsconfig.json

This file was deleted.

3 changes: 3 additions & 0 deletions apps/server/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PORT=4000
MONGO_URI=mongodb://localhost/woovi-playground
REDIS_HOST=redis://localhost
33 changes: 33 additions & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@woovi-playground/server",
"version": "1.0.0",
"private": true,
"scripts": {
"schema": "tsx scripts/updateSchema.ts",
"dev": "tsx --watch src/index.ts"
},
"dependencies": {
"@entria/graphql-mongo-helpers": "^1.1.2",
"dataloader": "^2.2.2",
"dotenv-safe": "^8.2.0",
"graphql": "^16.6.0",
"graphql-redis-subscriptions": "^2.6.0",
"graphql-relay": "^0.10.0",
"graphql-relay-subscription": "^1.0.0",
"graphql-subscriptions": "^2.0.0",
"graphql-ws": "^5.12.1",
"koa": "^2.14.2",
"koa-bodyparser": "^4.4.0",
"koa-graphql": "^0.12.0",
"koa-logger": "^3.2.1",
"koa-router": "^12.0.0",
"mongoose": "^7.0.3"
},
"devDependencies": {
"@types/koa": "^2.13.5",
"@types/koa-bodyparser": "^4.3.10",
"@types/koa-router": "^7.4.4",
"@types/node": "^17.0.12",
"tsx": "^3.12.6"
}
}
76 changes: 76 additions & 0 deletions apps/server/schema/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
type Query {
messages: MessageConnection
}

"""A connection to a list of items."""
type MessageConnection {
"""Information to aid in pagination."""
pageInfo: PageInfo!

"""A list of edges."""
edges: [MessageEdge]
}

"""Information about pagination in a connection."""
type PageInfo {
"""When paginating forwards, are there more items?"""
hasNextPage: Boolean!

"""When paginating backwards, are there more items?"""
hasPreviousPage: Boolean!

"""When paginating backwards, the cursor to continue."""
startCursor: String

"""When paginating forwards, the cursor to continue."""
endCursor: String
}

"""An edge in a connection."""
type MessageEdge {
"""The item at the end of the edge"""
node: Message

"""A cursor for use in pagination"""
cursor: String!
}

"""Represents a message"""
type Message implements Node {
"""The ID of an object"""
id: ID!
content: String
}

"""An object with an ID"""
interface Node {
"""The id of the object."""
id: ID!
}

type Mutation {
MessageAdd(input: MessageAddInput!): MessageAddPayload
}

type MessageAddPayload {
message: Message
clientMutationId: String
}

input MessageAddInput {
content: String!
clientMutationId: String
}

type Subscription {
MessageAdded(input: MessageAddedInput!): MessageAddedPayload
}

type MessageAddedPayload {
message: Message
clientSubscriptionId: String
}

input MessageAddedInput {
clientSubscriptionId: String
}
15 changes: 15 additions & 0 deletions apps/server/scripts/updateSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fs from 'fs/promises';
import { printSchema } from 'graphql/utilities';
import path from 'path';
import { promisify } from 'util';

import { schema } from '../src/schema/schema';

(async () => {
await fs.writeFile(
path.join(__dirname, '../schema/schema.graphql'),
printSchema(schema)
);

process.exit(0);
})();
21 changes: 21 additions & 0 deletions apps/server/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import path from 'path';

import dotenvSafe from 'dotenv-safe';

const cwd = process.cwd();

const root = path.join.bind(cwd);

dotenvSafe.config({
path: root('.env'),
sample: root('.env.example'),
});

const ENV = process.env;

const config = {
PORT: ENV.PORT ?? 4000,
MONGO_URI: ENV.MONGO_URI ?? '',
};

export { config };
14 changes: 14 additions & 0 deletions apps/server/src/database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import mongoose from 'mongoose';

import { config } from './config';

async function connectDatabase() {
// eslint-disable-next-line
mongoose.connection.on('close', () =>
console.log('Database connection closed.')
);

await mongoose.connect(config.MONGO_URI);
}

export { connectDatabase };
16 changes: 16 additions & 0 deletions apps/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import http from 'http';

import { app } from './server/app';
import { config } from './config';
import { connectDatabase } from './database';

(async () => {
await connectDatabase();

const server = http.createServer(app.callback());

server.listen(config.PORT, () => {
// eslint-disable-next-line
console.log(`Server running on port:${config.PORT}`);
});
})();
8 changes: 8 additions & 0 deletions apps/server/src/modules/error/errorFields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { GraphQLString } from 'graphql';

export const errorField = (key: string) => ({
[key]: {
type: GraphQLString,
resolve: async (obj: Record<string, unknown>) => obj.error,
},
});
16 changes: 16 additions & 0 deletions apps/server/src/modules/loader/loaderRegister.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const loaders: Record<string, () => unknown> = {};

const registerLoader = (key: string, getLoader: () => unknown) => {
loaders[key] = getLoader;
};

const getDataloaders = (): Record<string, () => unknown> =>
Object.keys(loaders).reduce(
(prev, loaderKey) => ({
...prev,
[loaderKey]: loaders[loaderKey](),
}),
{}
);

export { registerLoader, getDataloaders };
20 changes: 20 additions & 0 deletions apps/server/src/modules/message/MessageLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createLoader } from '@entria/graphql-mongo-helpers';

import { registerLoader } from '../loader/loaderRegister';

import { Message } from './MessageModel';

const { Wrapper, getLoader, clearCache, load, loadAll } = createLoader({
model: Message,
loaderName: 'MessageLoader',
});

registerLoader('MessageLoader', getLoader);

export const MessageLoader = {
Message: Wrapper,
getLoader,
clearCache,
load,
loadAll,
};
21 changes: 21 additions & 0 deletions apps/server/src/modules/message/MessageModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Document, Model } from 'mongoose';
import mongoose from 'mongoose';

const Schema = new mongoose.Schema<IMessage>(
{
content: {
type: String,
description: 'The content of the message',
},
},
{
collection: 'Message',
timestamps: true,
}
);

export type IMessage = {
content: string;
} & Document;

export const Message: Model<IMessage> = mongoose.model('Message', Schema);
Loading

0 comments on commit 54f7f0a

Please sign in to comment.