123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- const jwtSecret = 'AjnjLhjxM'
- const express = require('express');
- const express_graphql = require('express-graphql');
- const { buildSchema, printSchema } = require('graphql');
- const expand = require('mm-graphql/expand')
- ;(async () => {
- const {Savable, slice, getModels} = await require('./models.js')()
- const jwtGQL = require('mm-graphql/jwt')
- const {anonSchema, anonResolvers} = require('./anon')({Savable, secret: jwtSecret})
- let schema = buildSchema(`
- type User {
- _id: String
- createdAt: String
- login: String
- nick : String
- avatar: Image
- likes: [Like]
- likesCount: Int
- }
- input UserInput {
- _id: String
- login: String
- nick : String
- avatar: ImageInput
- }
- type Like {
- _id: ID,
- post: Post,
- comment: Comment,
- direct: Direct,
- user: User,
- }
- input LikeInput {
- _id: ID,
- post: Post,
- comment: CommentInput,
- direct: DirectInput,
- user: UserInput,
- }
- type Post {
- _id: ID,
- createdAt: String
- text: String,
- images: [Image],
- comments: [Comment],
- directs: [Direct],
- collections: [Collection]
- likes: [Like]
- likesCount: Int
- }
- input PostInput {
- _id: ID,
- text: String,
- images: [ImageInput],
- comments: [CommentInput],
- directs: [DirectInput],
- collections: [CollectionInput]
- }
- type Image {
- _id: ID,
- text: String,
- url: String,
- originalFileName: String,
- userAvatar: User,
- posts: [Post],
- directs: [Direct]
- }
- input ImageInput {
- _id: ID,
- userAvatar: User,
- posts: [Post],
- directs: [Direct]
- }
- type Comment {
- _id: ID,
- createdAt: String,
- text: String,
- post: Post,
- answers: [Comment],
- answerTo: Comment
- likes: [Like]
- likesCount: Int
- }
- input CommentInput {
- _id: ID,
- text: String,
- post: PostInput,
- answers: [CommentInput],
- answerTo: CommentInput
- }
- type Direct {
- _id: ID,
- createdAt: String,
- text: String,
- post: Post,
- image: Image,
- likes: [Like]
- likesCount: Int
- }
- input DirectInput {
- _id: ID,
- text: String,
- post: PostInput,
- image: ImageInput,
- likes: [LikeInput]
- }
- type Collection {
- _id: ID,
- text: String,
- posts: [Post]
- }
- input CollectionInput {
- _id: ID,
- text: String,
- posts: [Post]
- }
- `);
- schema = expand(schema)
- console.log(printSchema(schema))
- const app = express();
- app.use(express.static('public'));
- app.use('/graphql', express_graphql(jwtGQL({anonSchema, anonResolvers, schema, createContext: getModels, graphiql: true, secret: jwtSecret})))
- app.listen(4000, () => console.log('Express GraphQL Server Now Running On localhost:4000/graphql'));
- })()
|