Browse Source

basic relations

Ivan Asmer 5 years ago
parent
commit
49fc2d0f19
3 changed files with 148 additions and 2 deletions
  1. 21 2
      README.md
  2. 104 0
      index.js
  3. 23 0
      package.json

+ 21 - 2
README.md

@@ -1,3 +1,22 @@
-# hipstagram
+hipstagram
+===
 
- Mock Back for instagram-like service
+Mock Back for instagram-like service
+
+Basic relations
+----
+
+
+User: Owner, Following, Followers
+Post: Images, Like
+Images: Avatar, Posts, Direct
+Comments: Post, Comment (tree), Like
+Like: Post, Comment, User, Direct
+Direct: User, Owner, Post?, Image?, Like
+Collection: Posts
+Storis: видосики
+
+
+Пермишены:
+User: public, private (Follow Approve by user)
+Post: public, private

+ 104 - 0
index.js

@@ -0,0 +1,104 @@
+const jwtSecret   = 'CbymrfGfnB'
+
+const express = require('express');
+const express_graphql = require('express-graphql');
+
+const { buildSchema, printSchema } = require('graphql');
+const expand = require('./expand')
+
+;(async () => {
+
+    const {Savable, slice, getModels} = await require('./models.js')()
+    const jwtGQL = require('./jwt')
+
+    const {anonSchema, anonResolvers} = require('./anon')({Savable, secret: jwtSecret})
+
+    let schema = buildSchema(`
+        type User {
+             _id: String
+             createdAt: String
+             login: String
+             nick : String
+             orders: [Order]
+        }
+
+        input UserInput {
+             _id: String
+             login: String
+             nick : String
+        }
+
+        type Category {
+            _id: ID,
+            createdAt: String
+            name: String!,
+            goods: [Good]
+        }
+        input CategoryInput {
+            _id: ID,
+            name: String,
+            goods: [GoodInput]
+        }
+
+        type Good {
+            _id: ID,
+            createdAt: String
+            name: String!,
+            description: String
+            price: Float
+            imgUrls: [String]
+            orderGoods: [OrderGood]
+            categories: [Category]
+        }
+
+        input GoodInput {
+            _id: ID,
+            name: String,
+            description: String
+            imgUrls: [String]
+            price: Float
+            categories: [CategoryInput]
+        }
+
+
+        type OrderGood {
+            _id: ID,
+            createdAt: String
+            price: Float,
+            count: Float,
+            good: Good,
+            order: Order
+            total: Float
+        }
+
+        input OrderGoodInput {
+            _id: ID,
+            count: Int,
+            good: GoodInput,
+            order: OrderInput
+        }
+
+
+        type Order {
+            _id: ID
+            createdAt: String
+            orderGoods: [OrderGood]
+            total: Float
+        }
+
+        input OrderInput {
+            _id: ID
+            orderGoods: [OrderGoodInput]
+        }
+
+    `);
+
+    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'));
+})()
+

+ 23 - 0
package.json

@@ -0,0 +1,23 @@
+{
+  "name": "hipstagram",
+  "version": "1.0.0",
+  "description": "Mock Back for instagram-like service",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "repository": {
+    "type": "git",
+    "url": "git@gitlab.a-level.com.ua:gitgod/hipstagram.git"
+  },
+  "keywords": [
+    "node",
+    "memmongo",
+    "mongo",
+    "graphql",
+    "jwt",
+    "instagram"
+  ],
+  "author": "Ivan Grynkin",
+  "license": "MIT"
+}