fix(graphql): fix dates in google sheet transform types

This commit is contained in:
Sam Tolmay 2020-11-20 16:10:47 +02:00
parent 7201a4f351
commit c842f7e712
7 changed files with 23 additions and 14 deletions

1
.pnp.js generated
View File

@ -3813,6 +3813,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["graphql-type-json", "virtual:7fa6405098723f150ab741c1e73c906de11a676b4cc641bac8b3397ea2dd6efbb913e72a780932220533241b442cc586b41b26c7b5ac786de486992cd2db054c#npm:0.3.2"],
["jest", "npm:26.6.3"],
["mingo", "npm:3.1.0"],
["moment", "npm:2.29.1"],
["mongodb", "virtual:7fa6405098723f150ab741c1e73c906de11a676b4cc641bac8b3397ea2dd6efbb913e72a780932220533241b442cc586b41b26c7b5ac786de486992cd2db054c#npm:3.6.3"],
["webpack", "virtual:7fa6405098723f150ab741c1e73c906de11a676b4cc641bac8b3397ea2dd6efbb913e72a780932220533241b442cc586b41b26c7b5ac786de486992cd2db054c#npm:5.4.0"],
["webpack-cli", "virtual:7fa6405098723f150ab741c1e73c906de11a676b4cc641bac8b3397ea2dd6efbb913e72a780932220533241b442cc586b41b26c7b5ac786de486992cd2db054c#npm:4.2.0"]

View File

@ -52,6 +52,7 @@
"graphql": "15.4.0",
"graphql-type-json": "0.3.2",
"mingo": "3.1.0",
"moment": "2.29.1",
"mongodb": "3.6.3"
},
"devDependencies": {

View File

@ -266,7 +266,7 @@ test('googleSheetGetMany, columnTypes', async () => {
id: '1',
name: 'John',
age: 34,
birth_date: new Date('2020/04/26'),
birth_date: new Date('2020-04-26T00:00:00.000Z'),
married: true,
},
{
@ -275,7 +275,7 @@ test('googleSheetGetMany, columnTypes', async () => {
id: '2',
name: 'Steve',
age: 43,
birth_date: new Date('2020/04/27'),
birth_date: new Date('2020-04-27T00:00:00.000Z'),
married: false,
},
{
@ -284,7 +284,7 @@ test('googleSheetGetMany, columnTypes', async () => {
id: '3',
name: 'Tim',
age: 34,
birth_date: new Date('2020/04/28'),
birth_date: new Date('2020-04-28T00:00:00.000Z'),
married: false,
},
{

View File

@ -211,7 +211,7 @@ test('googleSheetGetOne, columnTypes', async () => {
id: '1',
name: 'John',
age: 34,
birth_date: new Date('2020/04/26'),
birth_date: new Date('2020-04-26T00:00:00.000Z'),
married: true,
});
});

View File

@ -27,13 +27,7 @@ async function authenticate({ doc, apiKey, client_email, private_key }) {
}
}
async function getSheet({ connection }) {
const { apiKey, client_email, private_key, sheetId, sheetIndex, spreadsheetId } = connection;
const doc = new GoogleSpreadsheet(spreadsheetId);
await authenticate({ doc, apiKey, client_email, private_key });
await doc.loadInfo();
function getSheetFromDoc({ doc, sheetId, sheetIndex }) {
let sheet;
if (sheetId) {
sheet = doc.sheetsById[sheetId];
@ -49,4 +43,15 @@ async function getSheet({ connection }) {
return sheet;
}
async function getSheet({ connection }) {
const { apiKey, client_email, private_key, sheetId, sheetIndex, spreadsheetId } = connection;
const doc = new GoogleSpreadsheet(spreadsheetId);
await authenticate({ doc, apiKey, client_email, private_key });
await doc.loadInfo();
return getSheetFromDoc({ doc, sheetId, sheetIndex });
}
export default getSheet;

View File

@ -15,6 +15,7 @@
*/
import { type } from '@lowdefy/helpers';
import moment from 'moment';
const readTransformers = {
string: (value) => value,
@ -25,9 +26,9 @@ const readTransformers = {
},
boolean: (value) => value === 'TRUE',
date: (value) => {
const date = new Date(value);
if (isNaN(date.getTime())) return null;
return date;
const date = moment.utc(value);
if (!date.isValid()) return null;
return date.toDate();
},
json: (value) => {
try {

View File

@ -2998,6 +2998,7 @@ __metadata:
graphql-type-json: 0.3.2
jest: 26.6.3
mingo: 3.1.0
moment: 2.29.1
mongodb: 3.6.3
webpack: 5.4.0
webpack-cli: 4.2.0