From 4488cc9864acad6839b33da84b9fe59f3e72a4fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Tue, 19 Feb 2019 01:43:11 +0100 Subject: [PATCH] Seed comments --- src/seed/data/comments.js | 80 ----------------------- src/seed/data/index.js | 6 -- src/seed/data/posts.js | 112 --------------------------------- src/seed/factories/comments.js | 37 +++++++++++ src/seed/factories/index.js | 4 +- src/seed/factories/posts.js | 1 - src/seed/seed-db.js | 52 ++++++++------- 7 files changed, 69 insertions(+), 223 deletions(-) delete mode 100644 src/seed/data/comments.js delete mode 100644 src/seed/data/index.js delete mode 100644 src/seed/data/posts.js create mode 100644 src/seed/factories/comments.js diff --git a/src/seed/data/comments.js b/src/seed/data/comments.js deleted file mode 100644 index ac1849b86..000000000 --- a/src/seed/data/comments.js +++ /dev/null @@ -1,80 +0,0 @@ -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: "

da stimm ich dir zu. Mir ging das auch nie in den kopf, und hatte jesus nie als gott gesehen

" - ) { 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: "

Schön das es dich gibt ❤️❤️❤️❤️❤️❤️❤️❤️❤️

" - ) { 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: "

Hi Dieter,

danke für Deine Info. Hast Du mal ein Foto von Deinem Cabrio mit dem Logo drauf?

" - ) { 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: "

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.

" - ) { 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 } } - } - ` -} diff --git a/src/seed/data/index.js b/src/seed/data/index.js deleted file mode 100644 index a77c6e6fb..000000000 --- a/src/seed/data/index.js +++ /dev/null @@ -1,6 +0,0 @@ -export default { - - Comment: require('./comments.js').default, - - // Reports: require('./reports.js').default -} diff --git a/src/seed/data/posts.js b/src/seed/data/posts.js deleted file mode 100644 index 8624c422d..000000000 --- a/src/seed/data/posts.js +++ /dev/null @@ -1,112 +0,0 @@ -import faker from 'faker' - -export default function (data) { - return ` - mutation { - p1: CreatePost( - id: "p1", - title: "Gedanken eines Polizisten zum Einsatz im Hambacher Forst", - content: "

Diese Zukunftsstadt ist real und keine Computer-Animation – 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.


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.


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:


https://motherboard.vice.com/de/article/vv34nb/ich-habe-die-zukunft-besucht-in-der-wir-ohne-geld-steuern-und-besitz-leben


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 :)


Wir sind eine Menschheitsfamilie. • Wir sind eins. • Wir sind HUMAN CONNECTION❤️

", - 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: "

Diese Zukunftsstadt ist real und keine Computer-Animation – 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.


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.


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:


https://motherboard.vice.com/de/article/vv34nb/ich-habe-die-zukunft-besucht-in-der-wir-ohne-geld-steuern-und-besitz-leben


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 :)


Wir sind eine Menschheitsfamilie. • Wir sind eins. • Wir sind HUMAN CONNECTION❤️

", - 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 } } - } - ` -} diff --git a/src/seed/factories/comments.js b/src/seed/factories/comments.js new file mode 100644 index 000000000..184b06bf0 --- /dev/null +++ b/src/seed/factories/comments.js @@ -0,0 +1,37 @@ +import faker from 'faker' + +export default function (params) { + const { + id = `c${faker.random.number()}`, + content = [ + faker.lorem.sentence(), + faker.lorem.sentence() + ].join('. '), + disabled = false, + deleted = false + } = params + + + return ` + mutation { + ${id}: CreateComment( + id: "${id}", + content: "${content}", + disabled: ${disabled}, + deleted: ${deleted} + ) { id } + } + ` +} + +export function relate(type, params) { + const { from, to } = params + return ` + mutation { + ${from}_${type}_${to}: AddComment${type}( + from: { id: "${from}" }, + to: { id: "${to}" } + ) { from { id } } + } + ` +} diff --git a/src/seed/factories/index.js b/src/seed/factories/index.js index 93916f376..89fa6144e 100644 --- a/src/seed/factories/index.js +++ b/src/seed/factories/index.js @@ -22,6 +22,7 @@ const builders = { 'user': require('./users.js').default, 'organization': require('./organizations.js').default, 'post': require('./posts.js').default, + 'comment': require('./comments.js').default, 'category': require('./categories.js').default, 'tag': require('./tags.js').default } @@ -29,7 +30,8 @@ const builders = { const relationBuilders = { 'user': require('./users.js').relate, 'organization': require('./organizations.js').relate, - 'post': require('./posts.js').relate + 'post': require('./posts.js').relate, + 'comment': require('./comments.js').relate } const buildMutation = (model, parameters) => { diff --git a/src/seed/factories/posts.js b/src/seed/factories/posts.js index e96eb61f2..e547efb01 100644 --- a/src/seed/factories/posts.js +++ b/src/seed/factories/posts.js @@ -1,4 +1,3 @@ - import faker from 'faker' export default function (params) { diff --git a/src/seed/seed-db.js b/src/seed/seed-db.js index 1a259f4cc..bab59a966 100644 --- a/src/seed/seed-db.js +++ b/src/seed/seed-db.js @@ -1,8 +1,5 @@ import { create, relate, apolloClient, seedServerHost as host } from './factories' import { authenticatedHeaders } from '../jest/helpers.js' -import gql from 'graphql-tag' -import asyncForEach from '../helpers/asyncForEach' -import seed from './data' /* eslint-disable no-multi-spaces */ (async function () { @@ -147,6 +144,33 @@ import seed from './data' relate('user', 'Shouted', { from: 'u4', to: 'p1' }) ]) + await Promise.all([ + create('comment', { id: "c1"}), + create('comment', { id: "c2"}), + create('comment', { id: "c3"}), + create('comment', { id: "c4"}), + create('comment', { id: "c5"}), + create('comment', { id: "c6"}), + create('comment', { id: "c7"}), + ]) + + await Promise.all([ + relate('comment', 'Author', { from: 'u3', to: 'c1'}), + relate('comment', 'Post', { from: 'c1', to: 'p1'}), + relate('comment', 'Author', { from: 'u1', to: 'c2'}), + relate('comment', 'Post', { from: 'c2', to: 'p1'}), + relate('comment', 'Author', { from: 'u1', to: 'c3'}), + relate('comment', 'Post', { from: 'c3', to: 'p3'}), + relate('comment', 'Author', { from: 'u4', to: 'c4'}), + relate('comment', 'Post', { from: 'c4', to: 'p2'}), + relate('comment', 'Author', { from: 'u4', to: 'c5'}), + relate('comment', 'Post', { from: 'c5', to: 'p3'}), + relate('comment', 'Author', { from: 'u3', to: 'c6'}), + relate('comment', 'Post', { from: 'c6', to: 'p4'}), + relate('comment', 'Author', { from: 'u2', to: 'c7'}), + relate('comment', 'Post', { from: 'c7', to: 'p2'}), + ]) + await Promise.all([ create('organization', { id: "o1", name: "Democracy Deutschland", description: "Description for democracy-deutschland."}), create('organization', { id: "o2", name: "Human-Connection", description: "Description for human-connection." }), @@ -160,31 +184,13 @@ import seed from './data' relate('organization', 'OwnedBy', {from: 'u2', to: 'o2'}), relate('organization', 'OwnedBy', {from: 'u2', to: 'o3'}) ]) - - + /* eslint-disable-next-line no-console */ + console.log('Seeded Data...') } catch (err) { /* eslint-disable-next-line no-console */ console.error(err) process.exit(1) } - let data = {} - // legacy seeds - await asyncForEach(Object.keys(seed), async key => { - const mutations = seed[key] - try { - const res = await apolloClient - .mutate({ - mutation: gql(mutations(data)) - }) - data[key] = Object.assign(data[key] || {}, res.data) - } catch (err) { - /* eslint-disable-next-line no-console */ - console.error(err) - process.exit(1) - } - }) - /* eslint-disable-next-line no-console */ - console.log('Seeded Data...') })() /* eslint-enable no-multi-spaces */