From 5986ab2070dfa3cf12844d1ceeac63d59f7ef2fa Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Mon, 10 Jun 2019 17:12:00 -0300 Subject: [PATCH 1/8] Create Posts with a specified language, or fallback --- backend/src/schema/resolvers/posts.spec.js | 18 ++++++++++- backend/src/schema/types/type/Post.gql | 30 +++++++++++------- webapp/components/ContributionForm/index.vue | 33 +++++++++++++++++++- webapp/graphql/PostMutations.js | 10 +++--- 4 files changed, 74 insertions(+), 17 deletions(-) diff --git a/backend/src/schema/resolvers/posts.spec.js b/backend/src/schema/resolvers/posts.spec.js index 9e2ec70a2..86f0665a0 100644 --- a/backend/src/schema/resolvers/posts.spec.js +++ b/backend/src/schema/resolvers/posts.spec.js @@ -19,7 +19,7 @@ afterEach(async () => { describe('CreatePost', () => { const mutation = ` mutation { - CreatePost(title: "I am a title", content: "Some content") { + CreatePost(title: "I am a title", content: "Some content", language: "en") { title content slug @@ -74,6 +74,22 @@ describe('CreatePost', () => { await expect(client.request(mutation)).resolves.toMatchObject(expected) }) }) + + describe('language', () => { + it('allows a user to set the language of the post', async () => { + const createPostWithLanguageMutation = ` + mutation { + CreatePost(title: "I am a title", content: "Some content", language: "en") { + language + } + } + ` + const expected = { CreatePost: { language: 'en' } } + await expect(client.request(createPostWithLanguageMutation)).resolves.toEqual( + expect.objectContaining(expected), + ) + }) + }) }) }) diff --git a/backend/src/schema/types/type/Post.gql b/backend/src/schema/types/type/Post.gql index c402a1233..271d92750 100644 --- a/backend/src/schema/types/type/Post.gql +++ b/backend/src/schema/types/type/Post.gql @@ -15,29 +15,37 @@ type Post { disabledBy: User @relation(name: "DISABLED", direction: "IN") createdAt: String updatedAt: String - - relatedContributions: [Post]! @cypher( - statement: """ + language: String + relatedContributions: [Post]! + @cypher( + statement: """ MATCH (this)-[:TAGGED|CATEGORIZED]->(categoryOrTag)<-[:TAGGED|CATEGORIZED]-(post:Post) RETURN DISTINCT post LIMIT 10 - """ - ) + """ + ) tags: [Tag]! @relation(name: "TAGGED", direction: "OUT") categories: [Category]! @relation(name: "CATEGORIZED", direction: "OUT") comments: [Comment]! @relation(name: "COMMENTS", direction: "IN") - commentsCount: Int! @cypher(statement: "MATCH (this)<-[:COMMENTS]-(r:Comment) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(r)") + commentsCount: Int! + @cypher( + statement: "MATCH (this)<-[:COMMENTS]-(r:Comment) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(r)" + ) shoutedBy: [User]! @relation(name: "SHOUTED", direction: "IN") - shoutedCount: Int! @cypher(statement: "MATCH (this)<-[:SHOUTED]-(r:User) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)") + shoutedCount: Int! + @cypher( + statement: "MATCH (this)<-[:SHOUTED]-(r:User) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)" + ) # Has the currently logged in user shouted that post? - shoutedByCurrentUser: Boolean! @cypher( - statement: """ + shoutedByCurrentUser: Boolean! + @cypher( + statement: """ MATCH (this)<-[:SHOUTED]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1 - """ - ) + """ + ) } diff --git a/webapp/components/ContributionForm/index.vue b/webapp/components/ContributionForm/index.vue index cf90a23b4..3e059d7cd 100644 --- a/webapp/components/ContributionForm/index.vue +++ b/webapp/components/ContributionForm/index.vue @@ -6,6 +6,12 @@ +
{{ $t('actions.cancel') }} @@ -28,6 +34,7 @@