Add translate API (#72)
This commit is contained in:
Generated
+1269
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "graphql-server-pw",
|
"name": "graphql-server-pw",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "Photowall GraphQL API",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"exportSQL": "cd src/__test__/db_generator/ && npm install && node index.js && cd ../../../",
|
"exportSQL": "cd src/__test__/db_generator/ && npm install && node index.js && cd ../../../",
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.31.0",
|
"@aws-sdk/client-s3": "^3.31.0",
|
||||||
"@aws-sdk/client-sqs": "^3.36.1",
|
"@aws-sdk/client-sqs": "^3.36.1",
|
||||||
|
"@aws-sdk/client-translate": "^3.36.1",
|
||||||
"@aws-sdk/s3-request-presigner": "^3.31.0",
|
"@aws-sdk/s3-request-presigner": "^3.31.0",
|
||||||
"apollo-datasource": "^3.1.0",
|
"apollo-datasource": "^3.1.0",
|
||||||
"apollo-datasource-rest": "^3.2.0",
|
"apollo-datasource-rest": "^3.2.0",
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import {
|
||||||
|
TranslateClient,
|
||||||
|
TranslateTextCommand,
|
||||||
|
} from '@aws-sdk/client-translate';
|
||||||
|
|
||||||
|
export type TranslateInput = {
|
||||||
|
text: string;
|
||||||
|
// Default to 'auto'
|
||||||
|
sourceLanguageCode?: string;
|
||||||
|
targetLanguageCode: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function translateText(input: TranslateInput) {
|
||||||
|
const translateClient = new TranslateClient({
|
||||||
|
region: 'eu-west-1',
|
||||||
|
});
|
||||||
|
|
||||||
|
const translateTextCommand = new TranslateTextCommand({
|
||||||
|
SourceLanguageCode: input.sourceLanguageCode ?? 'auto',
|
||||||
|
TargetLanguageCode: input.targetLanguageCode,
|
||||||
|
Text: input.text,
|
||||||
|
});
|
||||||
|
|
||||||
|
return translateClient
|
||||||
|
.send(translateTextCommand)
|
||||||
|
.then((resp) => resp.TranslatedText);
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ import { IdNumberResult, Maybe } from '../types/types';
|
|||||||
import { BaseSQLDataSource } from './BaseSQLDataSource';
|
import { BaseSQLDataSource } from './BaseSQLDataSource';
|
||||||
import { ImageServerApi } from './imageserver-api';
|
import { ImageServerApi } from './imageserver-api';
|
||||||
import * as CONFIG from '../config';
|
import * as CONFIG from '../config';
|
||||||
import { moveS3File } from '../s3';
|
import { moveS3File } from '../aws/s3';
|
||||||
|
|
||||||
const MINUTE = 60;
|
const MINUTE = 60;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { ProductAPI } from '../datasources/product-api';
|
|||||||
|
|
||||||
const Category = {
|
const Category = {
|
||||||
async products({ id }, { includeAllSubCategories }, { dataSources, auth }) {
|
async products({ id }, { includeAllSubCategories }, { dataSources, auth }) {
|
||||||
console.log('includeAllSubCategories:', includeAllSubCategories);
|
|
||||||
checkAccess(['products.read'], auth);
|
checkAccess(['products.read'], auth);
|
||||||
if (includeAllSubCategories === true) {
|
if (includeAllSubCategories === true) {
|
||||||
return (<ProductAPI>(
|
return (<ProductAPI>(
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { EXPIRES_DEFAULT_SECS, getSignedPutObjectUrl } from '../s3';
|
import { EXPIRES_DEFAULT_SECS, getSignedPutObjectUrl } from '../aws/s3';
|
||||||
import {
|
import {
|
||||||
SignedUploadURL,
|
SignedUploadURL,
|
||||||
SignedUploadURLInput,
|
SignedUploadURLInput,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
import { DateTimeResolver, DateResolver, JSONResolver } from 'graphql-scalars';
|
import { DateTimeResolver, DateResolver, JSONResolver } from 'graphql-scalars';
|
||||||
import { interiorsQueryTypeDefs, interiorTypeDefs } from './interiors-resolver';
|
import { interiorsQueryTypeDefs, interiorTypeDefs } from './interiors-resolver';
|
||||||
import { imagesQueryTypeDefs } from './file-upload-resolvers';
|
import { imagesQueryTypeDefs } from './file-upload-resolvers';
|
||||||
|
import { TextsQueryTypeDefs } from './texts-resolver';
|
||||||
const resolvers = {
|
const resolvers = {
|
||||||
Query: {
|
Query: {
|
||||||
...orderQueryTypeDefs,
|
...orderQueryTypeDefs,
|
||||||
@@ -29,6 +30,7 @@ const resolvers = {
|
|||||||
...marketsQueryTypeDefs,
|
...marketsQueryTypeDefs,
|
||||||
...interiorsQueryTypeDefs,
|
...interiorsQueryTypeDefs,
|
||||||
...imagesQueryTypeDefs,
|
...imagesQueryTypeDefs,
|
||||||
|
...TextsQueryTypeDefs,
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
...productMutationTypeDefs,
|
...productMutationTypeDefs,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { MarketLocaleAPI } from '../datasources/market-locale-api';
|
|||||||
import { InteriorAPI } from '../datasources/interior-api';
|
import { InteriorAPI } from '../datasources/interior-api';
|
||||||
import { InteriorsLambdaAPI } from '../datasources/interiors-lambda-api';
|
import { InteriorsLambdaAPI } from '../datasources/interiors-lambda-api';
|
||||||
import { IdNumberResult } from '../types/types';
|
import { IdNumberResult } from '../types/types';
|
||||||
import { moveS3File } from '../s3';
|
import { moveS3File } from '../aws/s3';
|
||||||
import { DesignerAPI } from '../datasources/designer-api';
|
import { DesignerAPI } from '../datasources/designer-api';
|
||||||
import { checkAccess } from '../cognito/access-control';
|
import { checkAccess } from '../cognito/access-control';
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { translateText, TranslateInput } from '../aws/translate';
|
||||||
|
|
||||||
|
async function translate(_, { input }, _ctx) {
|
||||||
|
const value = await translateText(input as TranslateInput);
|
||||||
|
return { value };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TextsQueryTypeDefs = {
|
||||||
|
translate,
|
||||||
|
};
|
||||||
@@ -38,6 +38,16 @@ type Query {
|
|||||||
interiors(filter: InteriorsFilterInput): [Interior]
|
interiors(filter: InteriorsFilterInput): [Interior]
|
||||||
signedFileUploadURL(config: SignedUploadURLInput): SignedUploadURL
|
signedFileUploadURL(config: SignedUploadURLInput): SignedUploadURL
|
||||||
@cacheControl(maxAge: 0)
|
@cacheControl(maxAge: 0)
|
||||||
|
translate(input: TranslateInput!): StringResult!
|
||||||
|
}
|
||||||
|
|
||||||
|
input TranslateInput {
|
||||||
|
text: String!
|
||||||
|
"""
|
||||||
|
defaults to auto
|
||||||
|
"""
|
||||||
|
sourceLanguageCode: String
|
||||||
|
targetLanguageCode: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
input SignedUploadURLInput {
|
input SignedUploadURLInput {
|
||||||
@@ -449,6 +459,10 @@ input ProductProportionsInput {
|
|||||||
marginHeightMin: Int!
|
marginHeightMin: Int!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StringResult {
|
||||||
|
value: String!
|
||||||
|
}
|
||||||
|
|
||||||
type IdNumberResult {
|
type IdNumberResult {
|
||||||
id: Int!
|
id: Int!
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user