Skip to content

Commit 09372d3

Browse files
committed
feat(Query): add labels query for translations
1 parent 40aaec8 commit 09372d3

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"lint": "tslint -p ."
1111
},
1212
"dependencies": {
13-
"@vichurch/model": "1.1.1",
13+
"@vichurch/model": "1.1.2",
1414
"bara": "2.4.0",
1515
"bcryptjs": "2.4.3",
1616
"graphql-yoga": "1.17.4",
Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
11
import { Context } from '../../utils'
22

3-
export async function getLocalizationsByLang(
3+
export interface Label {
4+
key: string
5+
text: string
6+
}
7+
8+
export async function labels(
49
parent,
5-
{ lang },
10+
{ code },
611
ctx: Context,
7-
info,
8-
) {
9-
console.log('Fetch localization for lang', lang)
10-
const map = new Map()
11-
const localizations = await ctx.prisma.localizations()
12-
for (let l of localizations) {
13-
const key = l.key
14-
console.log(key)
15-
}
16-
return localizations
12+
): Promise<Array<Label>> {
13+
const query = `
14+
query labels($code: String) {
15+
translations(where: {language: {code: $code}}) {
16+
language {
17+
name
18+
}
19+
localization {
20+
key
21+
}
22+
text
23+
}
24+
}
25+
`
26+
const res = await ctx.prisma.$graphql(query, { code })
27+
const labels = res.translations.map((r: any) => ({
28+
key: r.localization.key,
29+
text: r.text,
30+
}))
31+
return labels
32+
}
33+
34+
export async function localizations(parent, args, ctx: Context) {
35+
return ctx.prisma.localizations()
1736
}

src/schema.graphql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type Query {
55
activitySchedules: [ActivitySchedule!]
66
localizations: [Localization!]
77
me: User
8-
getLocalizationsByLang(lang: String!): [Localization!]!
8+
labels(code: String!): [Label!]!
99
}
1010

1111
type Mutation {
@@ -19,6 +19,11 @@ type Subscription {
1919
profileSubscription: Profile
2020
}
2121

22+
type Label {
23+
key: String!
24+
text: String!
25+
}
26+
2227
type AuthPayload {
2328
token: String!
2429
user: User!

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@
190190
version "0.5.4"
191191
resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.5.4.tgz#b863a4191e525206819e008097ebf0fb2e3a1cdc"
192192

193-
"@vichurch/[email protected].1":
194-
version "1.1.1"
195-
resolved "https://registry.yarnpkg.com/@vichurch/model/-/model-1.1.1.tgz#004c0c52adec1115f76fb9fbf704a1f4faea4cca"
196-
integrity sha512-7igPPXLJTavbGMozJsM3iaT5O+dvUO70UK5aczvqWLbcVPpl9ZHMG+D09t5XScNb7JzKC021MK1I3lKbAxlATg==
193+
"@vichurch/[email protected].2":
194+
version "1.1.2"
195+
resolved "https://registry.yarnpkg.com/@vichurch/model/-/model-1.1.2.tgz#835a602c02e4fe17837baeca7663cd7d5b450a33"
196+
integrity sha512-gd571cir/qZkU0pkLIzf1XJncYomsjtdIHx7yv64hbLloOXyaEYE+vZQUHRli3xGlu0LgUmciY5BK+8VgQRNag==
197197
dependencies:
198198
graphql "14.1.1"
199199
prisma-client-lib "1.26.3"

0 commit comments

Comments
 (0)