mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
simplyfied schema and modulized seeding process
This commit is contained in:
parent
96da90a255
commit
c6420b5351
@ -7,7 +7,7 @@
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "./node_modules/.bin/nodemon --exec babel-node src/index.js",
|
||||
"start:debug": "./node_modules/.bin/nodemon --exec babel-node --inspect=0.0.0.0:9229 src/index.js",
|
||||
"seedDb": "cross-env IS_SEEDING='true' ./node_modules/.bin/babel-node src/seed/seed-db.js && cross-env IS_SEEDING=false"
|
||||
"db:seed": "./node_modules/.bin/babel-node src/seed/seed-db.js"
|
||||
},
|
||||
"author": "Grzegorz Leoniec",
|
||||
"license": "MIT",
|
||||
|
||||
20
src/bootstrap/neo4j.js
Normal file
20
src/bootstrap/neo4j.js
Normal file
@ -0,0 +1,20 @@
|
||||
import { v1 as neo4j } from 'neo4j-driver'
|
||||
|
||||
let driver
|
||||
|
||||
export default function () {
|
||||
return {
|
||||
getDriver() {
|
||||
if (!driver) {
|
||||
driver = neo4j.driver(
|
||||
process.env.NEO4J_URI || 'bolt://localhost:7687',
|
||||
neo4j.auth.basic(
|
||||
process.env.NEO4J_USER || 'neo4j',
|
||||
process.env.NEO4J_PASSWORD || 'neo4j'
|
||||
)
|
||||
)
|
||||
}
|
||||
return driver
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/index.js
10
src/index.js
@ -2,12 +2,12 @@ import { GraphQLServer } from 'graphql-yoga'
|
||||
import { makeExecutableSchema } from 'apollo-server'
|
||||
import { augmentSchema } from 'neo4j-graphql-js'
|
||||
import { typeDefs, resolvers } from './graphql-schema'
|
||||
import { v1 as neo4j } from 'neo4j-driver'
|
||||
import dotenv from 'dotenv'
|
||||
import mocks from './mocks'
|
||||
import middleware from './middleware'
|
||||
import applyDirectives from './bootstrap/directives'
|
||||
import applyScalars from './bootstrap/scalars'
|
||||
import neo4j from './bootstrap/neo4j'
|
||||
|
||||
import passport from 'passport'
|
||||
import jwtStrategy from './jwt/strategy'
|
||||
@ -20,13 +20,7 @@ let schema = makeExecutableSchema({
|
||||
resolvers
|
||||
})
|
||||
|
||||
const driver = neo4j.driver(
|
||||
process.env.NEO4J_URI || 'bolt://localhost:7687',
|
||||
neo4j.auth.basic(
|
||||
process.env.NEO4J_USER || 'neo4j',
|
||||
process.env.NEO4J_PASSWORD || 'neo4j'
|
||||
)
|
||||
)
|
||||
const driver = neo4j().getDriver()
|
||||
|
||||
const MOCK = (process.env.MOCK === 'true')
|
||||
console.log('MOCK:', MOCK)
|
||||
|
||||
@ -8,7 +8,7 @@ import xssMiddleware from './xssMiddleware';
|
||||
import permissionsMiddleware from './permissionsMiddleware';
|
||||
|
||||
export default schema => [
|
||||
permissionsMiddleware.generate(schema),
|
||||
// permissionsMiddleware.generate(schema),
|
||||
passwordMiddleware,
|
||||
dateTimeMiddleware,
|
||||
sluggifyMiddleware,
|
||||
|
||||
@ -1,36 +1,16 @@
|
||||
import { rule, shield, and, or, not, allow } from 'graphql-shield'
|
||||
|
||||
const isAuthenticated = rule()(async (parent, args, ctx, info) => {
|
||||
// TODO: how to get this working while seeding?
|
||||
console.log('isSeeding', process.env.IS_SEEDING)
|
||||
if (process.env.IS_SEEDING === true) {
|
||||
return true
|
||||
}
|
||||
return ctx.user !== null
|
||||
})
|
||||
const isOwner = rule()(async (parent, args, ctx, info) => {
|
||||
// TODO: how to get this working while seeding?
|
||||
console.log('isSeeding', process.env.IS_SEEDING)
|
||||
if (process.env.IS_SEEDING === true) {
|
||||
return true
|
||||
}
|
||||
console.log('parent', parent)
|
||||
return ctx.user.id === parent.id
|
||||
})
|
||||
const isAdmin = rule()(async (parent, args, ctx, info) => {
|
||||
// TODO: how to get this working while seeding?
|
||||
console.log('isSeeding', process.env.IS_SEEDING)
|
||||
if (process.env.IS_SEEDING === true) {
|
||||
return true
|
||||
}
|
||||
return ctx.user.role === 'ADMIN'
|
||||
})
|
||||
const isModerator = rule()(async (parent, args, ctx, info) => {
|
||||
// TODO: how to get this working while seeding?
|
||||
console.log('isSeeding', process.env.IS_SEEDING)
|
||||
if (process.env.IS_SEEDING === true) {
|
||||
return true
|
||||
}
|
||||
return ctx.user.role === 'MODERATOR'
|
||||
})
|
||||
|
||||
@ -46,10 +26,10 @@ const permissions = shield({
|
||||
CreateUser: allow
|
||||
},
|
||||
// TODO: re-activate this after fixing the initial seed
|
||||
// User: {
|
||||
// email: isOwner,
|
||||
// password: isOwner
|
||||
// },
|
||||
User: {
|
||||
email: isOwner,
|
||||
password: isOwner
|
||||
},
|
||||
Post: isAuthenticated
|
||||
})
|
||||
|
||||
|
||||
@ -11,12 +11,12 @@ export default {
|
||||
return result
|
||||
},
|
||||
Comment: async (resolve, root, args, context, info) => {
|
||||
// if (typeof args.deleted !== 'boolean') {
|
||||
// args.deleted = false
|
||||
// }
|
||||
// if (typeof args.disabled !== 'boolean') {
|
||||
// args.disabled = false
|
||||
// }
|
||||
if (typeof args.deleted !== 'boolean') {
|
||||
args.deleted = false
|
||||
}
|
||||
if (typeof args.disabled !== 'boolean') {
|
||||
args.disabled = false
|
||||
}
|
||||
const result = await resolve(root, args, context, info)
|
||||
return result
|
||||
},
|
||||
|
||||
@ -44,21 +44,6 @@ enum UserGroupEnum {
|
||||
user
|
||||
}
|
||||
|
||||
type WrittenPost @relation(name: "WROTE") {
|
||||
from: User
|
||||
to: Post
|
||||
timestamp: Int # TODO: change that to custom Date Type
|
||||
}
|
||||
# type WrittenPost2 {
|
||||
# Post: Post!
|
||||
# timestamp: Int # TODO: change that to custom Date Type
|
||||
# }
|
||||
type WrittenComment @relation(name: "WROTE") {
|
||||
from: User
|
||||
to: Comment
|
||||
timestamp: Int # TODO: change that to custom Date Type
|
||||
}
|
||||
|
||||
type User {
|
||||
id: ID!
|
||||
name: String
|
||||
@ -94,7 +79,7 @@ type User {
|
||||
RETURN COUNT(r)"""
|
||||
)
|
||||
|
||||
comments: [WrittenComment]!
|
||||
comments: [Comment]! @relation(name: "WROTE", direction: "OUT")
|
||||
commentsCount: Int! @cypher(statement: "MATCH (this)-[:WROTE]->(r:Comment) WHERE NOT r.deleted = true RETURN COUNT(r)")
|
||||
|
||||
shouted: [Post]! @relation(name: "SHOUTED", direction: "OUT")
|
||||
@ -111,7 +96,7 @@ type User {
|
||||
|
||||
type Post {
|
||||
id: ID!
|
||||
author: WrittenPost
|
||||
author: User @relation(name: "WROTE", direction: "IN")
|
||||
title: String!
|
||||
slug: String
|
||||
content: String!
|
||||
@ -141,12 +126,12 @@ type Post {
|
||||
|
||||
type Comment {
|
||||
id: ID!
|
||||
author: WrittenComment
|
||||
author: User @relation(name: "WROTE", direction: "IN")
|
||||
content: String!
|
||||
contentExcerpt: String
|
||||
post: Post @relation(name: "COMMENT", direction: "OUT")
|
||||
createdAt: String,
|
||||
updatedAt: String,
|
||||
post: Post @relation(name: "COMMENTS", direction: "OUT")
|
||||
createdAt: String
|
||||
updatedAt: String
|
||||
deleted: Boolean
|
||||
disabled: Boolean
|
||||
}
|
||||
|
||||
22
src/seed/data/categories.js
Normal file
22
src/seed/data/categories.js
Normal file
@ -0,0 +1,22 @@
|
||||
export default function (data) {
|
||||
return `
|
||||
mutation {
|
||||
cat1: CreateCategory( id: "cat1", name: "Just For Fun", slug: "justforfun", icon: "categories-justforfun" ) { name }
|
||||
cat2: CreateCategory( id: "cat2", name: "Happyness & Values", slug: "happyness-values", icon: "categories-luck" ) { name }
|
||||
cat3: CreateCategory( id: "cat3", name: "Health & Wellbeing", slug: "health-wellbeing", icon: "categories-health" ) { name }
|
||||
cat4: CreateCategory( id: "cat4", name: "Environment & Nature", slug: "environment-nature", icon: "categories-environment" ) { name }
|
||||
cat5: CreateCategory( id: "cat5", name: "Animal Protection", slug: "animalprotection", icon: "categories-animal-justice" ) { name }
|
||||
cat6: CreateCategory( id: "cat6", name: "Humanrights Justice", slug: "humanrights-justice", icon: "categories-human-rights" ) { name }
|
||||
cat7: CreateCategory( id: "cat7", name: "Education & Sciences", slug: "education-sciences", icon: "categories-education" ) { name }
|
||||
cat8: CreateCategory( id: "cat8", name: "Cooperation & Development", slug: "cooperation-development", icon: "categories-cooperation" ) { name }
|
||||
cat9: CreateCategory( id: "cat9", name: "Democracy & Politics", slug: "democracy-politics", icon: "categories-politics" ) { name }
|
||||
cat10: CreateCategory( id: "cat10", name: "Economy & Finances", slug: "economy-finances", icon: "categories-economy" ) { name }
|
||||
cat11: CreateCategory( id: "cat11", name: "Energy & Technology", slug: "energy-technology", icon: "categories-technology" ) { name }
|
||||
cat12: CreateCategory( id: "cat12", name: "IT, Internet & Data Privacy", slug: "it-internet-dataprivacy", icon: "categories-internet" ) { name }
|
||||
cat13: CreateCategory( id: "cat13", name: "Art, Curlure & Sport", slug: "art-culture-sport", icon: "categories-art" ) { name }
|
||||
cat14: CreateCategory( id: "cat14", name: "Freedom of Speech", slug: "freedomofspeech", icon: "categories-freedom-of-speech" ) { name }
|
||||
cat15: CreateCategory( id: "cat15", name: "Consumption & Sustainability", slug: "consumption-sustainability", icon: "categories-sustainability" ) { name }
|
||||
cat16: CreateCategory( id: "cat16", name: "Global Peace & Nonviolence", slug: "globalpeace-nonviolence", icon: "categories-peace" ) { name }
|
||||
}
|
||||
`
|
||||
}
|
||||
80
src/seed/data/comments.js
Normal file
80
src/seed/data/comments.js
Normal file
@ -0,0 +1,80 @@
|
||||
import faker from 'faker'
|
||||
|
||||
/**
|
||||
* TODO: add a comment automatically to the correct post and relate it to the current user
|
||||
*/
|
||||
export default function (data) {
|
||||
return `
|
||||
mutation {
|
||||
c1: CreateComment(
|
||||
id: "c1",
|
||||
content: "<p>da stimm ich dir zu. Mir ging das auch nie in den kopf, und hatte jesus nie als gott gesehen </p>"
|
||||
) { id }
|
||||
c1_u1: AddCommentAuthor(from: { id: "u3" }, to: { id: "c1" }) { from { id } }
|
||||
c1_p1: AddCommentPost(
|
||||
from: { id: "c1" },
|
||||
to: { id: "p1" }
|
||||
) { from { id } }
|
||||
|
||||
c2: CreateComment(
|
||||
id: "c2",
|
||||
content: "<p>Schön das es dich gibt ❤️❤️❤️❤️❤️❤️❤️❤️❤️</p>"
|
||||
) { id }
|
||||
c2_u1: AddCommentAuthor(from: { id: "u1" }, to: { id: "c2" }) { from { id } }
|
||||
c2_p1: AddCommentPost(
|
||||
from: { id: "c2" },
|
||||
to: { id: "p1" }
|
||||
) { from { id } }
|
||||
|
||||
c3: CreateComment(
|
||||
id: "c3",
|
||||
content: "<p>Hi Dieter,</p><p>danke für Deine Info. Hast Du mal ein Foto von Deinem Cabrio mit dem Logo drauf?</p>"
|
||||
) { id }
|
||||
c3_u2: AddCommentAuthor(from: { id: "u1" }, to: { id: "c3" }) { from { id } }
|
||||
c3_p3: AddCommentPost(
|
||||
from: { id: "c3" },
|
||||
to: { id: "p3" }
|
||||
) { from { id } }
|
||||
|
||||
c4: CreateComment(
|
||||
id: "c4",
|
||||
content: "<p>Das Zusammenführen aller Gruppen, die mit uns am gleichen Strang in die gleiche Richtung ziehen, in eine gemeinsame Adressenstruktur sehe ich auch als Haupt - Aufgabe für unsere neue Netzwerkbildung an.</p>"
|
||||
) { id }
|
||||
c4_u3: AddCommentAuthor(from: { id: "u4" }, to: { id: "c4" }) { from { id } }
|
||||
c4_p2: AddCommentPost(
|
||||
from: { id: "c4" },
|
||||
to: { id: "p2" }
|
||||
) { from { id } }
|
||||
|
||||
c5: CreateComment(
|
||||
id: "c5",
|
||||
content: "${faker.lorem.paragraph()}"
|
||||
) { id }
|
||||
c5_u4: AddCommentAuthor(from: { id: "u4" }, to: { id: "c5" }) { from { id } }
|
||||
c5_p3: AddCommentPost(
|
||||
from: { id: "c5" },
|
||||
to: { id: "p3" }
|
||||
) { from { id } }
|
||||
|
||||
c6: CreateComment(
|
||||
id: "c6",
|
||||
content: "${faker.lorem.paragraph()}"
|
||||
) { id }
|
||||
c6_u3: AddCommentAuthor(from: { id: "u3" }, to: { id: "c6" }) { from { id } }
|
||||
c6_p4: AddCommentPost(
|
||||
from: { id: "c6" },
|
||||
to: { id: "p4" }
|
||||
) { from { id } }
|
||||
|
||||
c7: CreateComment(
|
||||
id: "c7",
|
||||
content: "${faker.lorem.paragraph()}"
|
||||
) { id }
|
||||
c7_u2: AddCommentAuthor(from: { id: "u2" }, to: { id: "c7" }) { from { id } }
|
||||
c7_p2: AddCommentPost(
|
||||
from: { id: "c7" },
|
||||
to: { id: "p2" }
|
||||
) { from { id } }
|
||||
}
|
||||
`
|
||||
}
|
||||
@ -2,9 +2,19 @@ import gql from 'graphql-tag'
|
||||
import helper from '../seed-helpers'
|
||||
|
||||
const seed = {
|
||||
Badges: require('./badges.js').default,
|
||||
Badge: require('./badges.js').default,
|
||||
Category: require('./categories.js').default,
|
||||
Tags: require('./tags.js').default,
|
||||
|
||||
User: require('./users.js').default,
|
||||
UserBadges: require('./users-badges.js').default
|
||||
UserBadges: require('./users-badges.js').default,
|
||||
UserBlacklist: require('./users-blacklist.js').default,
|
||||
UserFollows: require('./users-follows.js').default,
|
||||
UserFriends: require('./users-friends.js').default,
|
||||
|
||||
Post: require('./posts.js').default,
|
||||
Comment: require('./comments.js').default,
|
||||
UserShouts: require('./users-shouts.js').default
|
||||
};
|
||||
|
||||
let data = {}
|
||||
|
||||
112
src/seed/data/posts.js
Normal file
112
src/seed/data/posts.js
Normal file
@ -0,0 +1,112 @@
|
||||
import faker from 'faker'
|
||||
|
||||
export default function (data) {
|
||||
return `
|
||||
mutation {
|
||||
p1: CreatePost(
|
||||
id: "p1",
|
||||
title: "Gedanken eines Polizisten zum Einsatz im Hambacher Forst",
|
||||
content: "<p><strong>Diese Zukunftsstadt ist real und keine Computer-Animation</strong> – sondern sie ist das Lebenswerk des mittlerweile über 100 Jahre alten Futuristen und Architekten Jacque Fresco aus Florida. In 35 Jahren (seit seinem 13. Lebensjahr) hat dieser zusammen mit seiner Frau seinen futuristischen Traum von einer besonderen Zukunftsstadt auf 85.000 Quadratmetern realisiert. In den Gebäuden und Gärten befinden sich u.a. ein Forschungszentrum, Vortragsräume und unzählige seiner Modelle & Architekturentwürfe.</p><br /><p>Sein zentrales Anliegen ist eine resourcenbasierte Wirtschaft und die Abschaffung von Geld und Privatbesitz. Mit Hilfe von Roboterarbeit und dem Bedingungslosen Grundeinkommen (da nach seiner Ansicht in den kommenden Jahren fast alle Jobs automatisiert werden), möchte er eine ökologische Landwirtschaft mit Permakulturen etc. und eine effiziente Energiegewinnung (ausschließlich durch regenerative Energien) schaffen. Wenige kompatible Formen in einer sparsamen Modulbauweise (in die u.a. bereits variable Service- und Reparaturelemente integriert sind) sollen insgesamt eine soziale & ökologische Utopie im Einklang mit der Natur ermöglichen.</p><br /><p>Nachfolgend der Direkt-Link auf den interessanten Artikel von Zoltan Istvan, der den Architekten und seine Frau in Florida besuchen durfte und seinen Artikel Ende 2016 auf „MOTHERBOARD“ veröffentlicht hatte:</p><br /><p>https://motherboard.vice.com/de/article/vv34nb/ich-habe-die-zukunft-besucht-in-der-wir-ohne-geld-steuern-und-besitz-leben </p><br /><p>Da soll noch jemand behaupten, es gäbe keine Utopien mehr bzw. keine Futuristen, die ihre kreativen und zukunftsfähigen Ideen (auch in ganz großem Stil) selbst in die Tat umsetzen. LG @all :) </p><br /><p><strong>Wir sind eine Menschheitsfamilie. • Wir sind eins. • Wir sind HUMAN CONNECTION</strong> ❤️</p>",
|
||||
image: "https://picsum.photos/1280/1024?image=352",
|
||||
visibility: public,
|
||||
disabled: false,
|
||||
deleted: false
|
||||
) { title }
|
||||
p1_cat1: AddPostCategories(from: {id: "p1"}, to: {id: "cat1"}) { from { id } }
|
||||
p1_cat2: AddPostCategories(from: {id: "p1"}, to: {id: "cat2"}) { from { id } }
|
||||
ur1: AddUserContributions(from: { id: "u1" }, to: { id: "p1" }) { from { id } }
|
||||
p1_t1: AddPostTags(
|
||||
from: { id: "p1" }
|
||||
to: { id: "t1" }
|
||||
) { from { id } }
|
||||
p1_t2: AddPostTags(
|
||||
from: { id: "p1" }
|
||||
to: { id: "t2" }
|
||||
) { from { id } }
|
||||
p1_t3: AddPostTags(
|
||||
from: { id: "p1" }
|
||||
to: { id: "t3" }
|
||||
) { from { id } }
|
||||
|
||||
p2: CreatePost(
|
||||
id: "p2",
|
||||
title: "Julian Assange",
|
||||
content: "<p><strong>Diese Zukunftsstadt ist real und keine Computer-Animation</strong> – sondern sie ist das Lebenswerk des mittlerweile über 100 Jahre alten Futuristen und Architekten Jacque Fresco aus Florida. In 35 Jahren (seit seinem 13. Lebensjahr) hat dieser zusammen mit seiner Frau seinen futuristischen Traum von einer besonderen Zukunftsstadt auf 85.000 Quadratmetern realisiert. In den Gebäuden und Gärten befinden sich u.a. ein Forschungszentrum, Vortragsräume und unzählige seiner Modelle & Architekturentwürfe.</p><br /><p>Sein zentrales Anliegen ist eine resourcenbasierte Wirtschaft und die Abschaffung von Geld und Privatbesitz. Mit Hilfe von Roboterarbeit und dem Bedingungslosen Grundeinkommen (da nach seiner Ansicht in den kommenden Jahren fast alle Jobs automatisiert werden), möchte er eine ökologische Landwirtschaft mit Permakulturen etc. und eine effiziente Energiegewinnung (ausschließlich durch regenerative Energien) schaffen. Wenige kompatible Formen in einer sparsamen Modulbauweise (in die u.a. bereits variable Service- und Reparaturelemente integriert sind) sollen insgesamt eine soziale & ökologische Utopie im Einklang mit der Natur ermöglichen.</p><br /><p>Nachfolgend der Direkt-Link auf den interessanten Artikel von Zoltan Istvan, der den Architekten und seine Frau in Florida besuchen durfte und seinen Artikel Ende 2016 auf „MOTHERBOARD“ veröffentlicht hatte:</p><br /><p>https://motherboard.vice.com/de/article/vv34nb/ich-habe-die-zukunft-besucht-in-der-wir-ohne-geld-steuern-und-besitz-leben </p><br /><p>Da soll noch jemand behaupten, es gäbe keine Utopien mehr bzw. keine Futuristen, die ihre kreativen und zukunftsfähigen Ideen (auch in ganz großem Stil) selbst in die Tat umsetzen. LG @all :) </p><br /><p><strong>Wir sind eine Menschheitsfamilie. • Wir sind eins. • Wir sind HUMAN CONNECTION</strong> ❤️</p>",
|
||||
image: "https://picsum.photos/1280/1024?image=72",
|
||||
visibility: public,
|
||||
disabled: false,
|
||||
deleted: false
|
||||
) { title }
|
||||
p2_cat1: AddPostCategories(from: {id: "p2"}, to: {id: "cat1"}) { from { id } }
|
||||
p2_cat16: AddPostCategories(from: {id: "p2"}, to: {id: "cat16"}) { from { id } }
|
||||
ur2: AddUserContributions(from: { id: "u2" }, to: { id: "p2" }) { from { id } }
|
||||
p2_t4: AddPostTags(
|
||||
from: { id: "p2" }
|
||||
to: { id: "t4" }
|
||||
) { from { id } }
|
||||
|
||||
p3: CreatePost(
|
||||
id: "p3",
|
||||
title: "Hacker, Freaks und Funktionäre...Der CCC",
|
||||
content: "${faker.lorem.sentence()} ${faker.lorem.sentence()} ${faker.lorem.sentence()} ${faker.lorem.sentence()} ${faker.lorem.sentence()}",
|
||||
image: "https://picsum.photos/1280/1024?image=121",
|
||||
visibility: public,
|
||||
disabled: false,
|
||||
deleted: false
|
||||
) { title }
|
||||
p3_cat1: AddPostCategories(from: {id: "p3"}, to: {id: "cat1"}) { from { id } }
|
||||
p3_cat3: AddPostCategories(from: {id: "p3"}, to: {id: "cat3"}) { from { id } }
|
||||
p3_cat14: AddPostCategories(from: {id: "p3"}, to: {id: "cat14"}) { from { id } }
|
||||
ur3: AddUserContributions(from: { id: "u3" }, to: { id: "p3" }) { from { id } }
|
||||
p3_t2: AddPostTags(
|
||||
from: { id: "p3" }
|
||||
to: { id: "t2" }
|
||||
) { from { id } }
|
||||
p3_t4: AddPostTags(
|
||||
from: { id: "p3" }
|
||||
to: { id: "t4" }
|
||||
) { from { id } }
|
||||
|
||||
p4: CreatePost(
|
||||
id: "p4",
|
||||
title: "Lebensmittel (?)",
|
||||
content: "${faker.lorem.sentence()} ${faker.lorem.sentence()} ${faker.lorem.sentence()} ${faker.lorem.sentence()} ${faker.lorem.sentence()}",
|
||||
image: "https://picsum.photos/1280/1024?image=142",
|
||||
visibility: public,
|
||||
disabled: false,
|
||||
deleted: false
|
||||
) { title }
|
||||
p4_cat1: AddPostCategories(from: {id: "p4"}, to: {id: "cat1"}) { from { id } }
|
||||
p4_cat9: AddPostCategories(from: {id: "p4"}, to: {id: "cat9"}) { from { id } }
|
||||
p4_cat4: AddPostCategories(from: {id: "p4"}, to: {id: "cat4"}) { from { id } }
|
||||
ur4: AddUserContributions(from: { id: "u4" }, to: { id: "p4" }) { from { id } }
|
||||
|
||||
p5: CreatePost(
|
||||
id: "p5",
|
||||
title: "${faker.lorem.sentence()}",
|
||||
content: "${faker.lorem.sentence()} ${faker.lorem.sentence()} ${faker.lorem.sentence()} ${faker.lorem.sentence()} ${faker.lorem.sentence()}",
|
||||
image: "https://picsum.photos/1280/1024?image=231",
|
||||
visibility: public,
|
||||
disabled: false,
|
||||
deleted: false
|
||||
) { title }
|
||||
p5_cat8: AddPostCategories(from: {id: "p5"}, to: {id: "cat8"}) { from { id } }
|
||||
p5_cat12: AddPostCategories(from: {id: "p5"}, to: {id: "cat12"}) { from { id } }
|
||||
ur5: AddUserContributions(from: { id: "u2" }, to: { id: "p5" }) { from { id } }
|
||||
|
||||
p6: CreatePost(
|
||||
id: "p6",
|
||||
title: "${faker.lorem.sentence()}",
|
||||
content: "${faker.lorem.sentence()} ${faker.lorem.sentence()} ${faker.lorem.sentence()} ${faker.lorem.sentence()} ${faker.lorem.sentence()}",
|
||||
image: "https://picsum.photos/1280/1024?image=424",
|
||||
visibility: public,
|
||||
disabled: false,
|
||||
deleted: false
|
||||
) { title }
|
||||
p6_cat1: AddPostCategories(from: {id: "p6"}, to: {id: "cat1"}) { from { id } }
|
||||
p6_cat2: AddPostCategories(from: {id: "p6"}, to: {id: "cat2"}) { from { id } }
|
||||
p6_cat5: AddPostCategories(from: {id: "p6"}, to: {id: "cat5"}) { from { id } }
|
||||
ur6: AddUserContributions(from: { id: "u4" }, to: { id: "p6" }) { from { id } }
|
||||
}
|
||||
`
|
||||
}
|
||||
22
src/seed/data/tags.js
Normal file
22
src/seed/data/tags.js
Normal file
@ -0,0 +1,22 @@
|
||||
export default function (data) {
|
||||
return `
|
||||
mutation {
|
||||
t1: CreateTag(
|
||||
id: "t1",
|
||||
name: "Umwelt"
|
||||
) { name }
|
||||
t2: CreateTag(
|
||||
id: "t2",
|
||||
name: "Naturschutz"
|
||||
) { name }
|
||||
t3: CreateTag(
|
||||
id: "t3",
|
||||
name: "Demokratie"
|
||||
) { name }
|
||||
t4: CreateTag(
|
||||
id: "t4",
|
||||
name: "Freiheit"
|
||||
) { name }
|
||||
}
|
||||
`
|
||||
}
|
||||
@ -1,12 +1,7 @@
|
||||
export default function (data) {
|
||||
return `
|
||||
mutation {
|
||||
b1_u1: AddUserBadges(from: {id: "b1"}, to: {id: "u1"}) { from { id } }
|
||||
b2_u1: AddUserBadges(from: {id: "b2"}, to: {id: "u1"}) { from { id } }
|
||||
b3_u1: AddUserBadges(from: {id: "b3"}, to: {id: "u1"}) { from { id } }
|
||||
b6_u2: AddUserBadges(from: {id: "b6"}, to: {id: "u2"}) { from { id } }
|
||||
b3_u3: AddUserBadges(from: {id: "b3"}, to: {id: "u3"}) { from { id } }
|
||||
b5_u4: AddUserBadges(from: {id: "b5"}, to: {id: "u4"}) { from { id } }
|
||||
u1_blacklist_u4: AddUserBlacklisted(from: { id: "u1" }, to: { id: "u4" }) { from { id } }
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
12
src/seed/data/users-blacklist.js
Normal file
12
src/seed/data/users-blacklist.js
Normal file
@ -0,0 +1,12 @@
|
||||
export default function (data) {
|
||||
return `
|
||||
mutation {
|
||||
b1_u1: AddUserBadges(from: {id: "b1"}, to: {id: "u1"}) { from { id } }
|
||||
b2_u1: AddUserBadges(from: {id: "b2"}, to: {id: "u1"}) { from { id } }
|
||||
b3_u1: AddUserBadges(from: {id: "b3"}, to: {id: "u1"}) { from { id } }
|
||||
b6_u2: AddUserBadges(from: {id: "b6"}, to: {id: "u2"}) { from { id } }
|
||||
b3_u3: AddUserBadges(from: {id: "b3"}, to: {id: "u3"}) { from { id } }
|
||||
b5_u4: AddUserBadges(from: {id: "b5"}, to: {id: "u4"}) { from { id } }
|
||||
}
|
||||
`
|
||||
}
|
||||
26
src/seed/data/users-follows.js
Normal file
26
src/seed/data/users-follows.js
Normal file
@ -0,0 +1,26 @@
|
||||
export default function (data) {
|
||||
return `
|
||||
mutation {
|
||||
u1_follow_u2: AddUserFollowing(
|
||||
from: { id: "u1" },
|
||||
to: { id: "u2" }
|
||||
) { from { id } }
|
||||
u2_follow_u1: AddUserFollowing(
|
||||
from: { id: "u2" },
|
||||
to: { id: "u1" }
|
||||
) { from { id } }
|
||||
u2_follow_u3: AddUserFollowing(
|
||||
from: { id: "u2" },
|
||||
to: { id: "u3" }
|
||||
) { from { id } }
|
||||
u2_follow_u4: AddUserFollowing(
|
||||
from: { id: "u2" },
|
||||
to: { id: "u4" }
|
||||
) { from { id } }
|
||||
u4_follow_u2: AddUserFollowing(
|
||||
from: { id: "u4" },
|
||||
to: { id: "u2" }
|
||||
) { from { id } }
|
||||
}
|
||||
`
|
||||
}
|
||||
14
src/seed/data/users-friends.js
Normal file
14
src/seed/data/users-friends.js
Normal file
@ -0,0 +1,14 @@
|
||||
export default function (data) {
|
||||
return `
|
||||
mutation {
|
||||
u1_friends_u2: AddUserFriends(
|
||||
from: { id: "u1" },
|
||||
to: { id: "u2" }
|
||||
) { from { id } }
|
||||
u1_friends_u3: AddUserFriends(
|
||||
from: { id: "u1" },
|
||||
to: { id: "u3" }
|
||||
) { from { id } }
|
||||
}
|
||||
`
|
||||
}
|
||||
30
src/seed/data/users-shouts.js
Normal file
30
src/seed/data/users-shouts.js
Normal file
@ -0,0 +1,30 @@
|
||||
export default function (data) {
|
||||
return `
|
||||
mutation {
|
||||
u1s2: AddUserShouted(
|
||||
from: { id: "u1" },
|
||||
to: { id: "p2" }
|
||||
) { from { id } }
|
||||
u1s3: AddUserShouted(
|
||||
from: { id: "u1" },
|
||||
to: { id: "p3" }
|
||||
) { from { id } }
|
||||
u2s1: AddUserShouted(
|
||||
from: { id: "u2" },
|
||||
to: { id: "p1" }
|
||||
) { from { id } }
|
||||
u3s1: AddUserShouted(
|
||||
from: { id: "u3" },
|
||||
to: { id: "p1" }
|
||||
) { from { id } }
|
||||
u3s4: AddUserShouted(
|
||||
from: { id: "u3" },
|
||||
to: { id: "p4" }
|
||||
) { from { id } }
|
||||
u4s1: AddUserShouted(
|
||||
from: { id: "u4" },
|
||||
to: { id: "p1" }
|
||||
) { from { id } }
|
||||
}
|
||||
`
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
import ApolloClient from "apollo-client";
|
||||
import dotenv from "dotenv";
|
||||
import gql from 'graphql-tag'
|
||||
import seedMutations from "./seed-mutations";
|
||||
import fetch from "node-fetch";
|
||||
import { HttpLink } from "apollo-link-http";
|
||||
import { InMemoryCache } from "apollo-cache-inmemory";
|
||||
@ -9,16 +8,13 @@ import Seed from './data/index'
|
||||
|
||||
dotenv.config();
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
throw new Error('YOU CAN`T SEED IN PRODUCTION MODE')
|
||||
}
|
||||
|
||||
const client = new ApolloClient({
|
||||
link: new HttpLink({ uri: process.env.GRAPHQL_URI, fetch }),
|
||||
cache: new InMemoryCache()
|
||||
});
|
||||
|
||||
Seed(client)
|
||||
|
||||
/* client
|
||||
.mutate({
|
||||
mutation: gql(seedMutations)
|
||||
})
|
||||
.then(data => console.log(data))
|
||||
.catch(error => console.error(error)); **/
|
||||
|
||||
@ -263,10 +263,6 @@ export default `
|
||||
from: { id: "c6" },
|
||||
to: { id: "p4" }
|
||||
) { from { id } }
|
||||
c6_p1: AddCommentPost(
|
||||
from: { id: "c6" },
|
||||
to: { id: "p1" }
|
||||
) { from { id } }
|
||||
c7_p2: AddCommentPost(
|
||||
from: { id: "c7" },
|
||||
to: { id: "p2" }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user