forked from woovibr/woovi-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(init): ༼ つ ◕_◕ ༽つ Woovi Playground
- Loading branch information
Showing
59 changed files
with
2,735 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/*/'], | ||
}, | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.