From b13ec57408451ba05176c8c554319235c517447f Mon Sep 17 00:00:00 2001 From: SmEiTo Date: Thu, 12 Apr 2018 16:00:47 +0200 Subject: [PATCH 1/3] Json validator test --- .../src/commands/import/Validator.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cli/packages/graphcool-cli-core/src/commands/import/Validator.test.ts b/cli/packages/graphcool-cli-core/src/commands/import/Validator.test.ts index 1ec3c944a..fdb437ba6 100644 --- a/cli/packages/graphcool-cli-core/src/commands/import/Validator.test.ts +++ b/cli/packages/graphcool-cli-core/src/commands/import/Validator.test.ts @@ -129,6 +129,26 @@ describe('Validator', () => { }), ).toBe(true) }) + + test('Json', () => { + const types = ` + type Post { + id: ID! + json: Json! + } + ` + const validator = new Validator(types) + expect(() => + validator.validateNode({ _typeName: 'Post', id: '25', Json: '' }), + ).toThrow() + expect( + validator.validateNode({ + _typeName: 'Post', + id: '25', + date: '{"test": "json"}', + }), + ).toBe(true) + }) test('Int', () => { const types = ` From b85e7de059116c7462633ec6286ef70d0935216c Mon Sep 17 00:00:00 2001 From: SmEiTo Date: Thu, 12 Apr 2018 16:02:04 +0200 Subject: [PATCH 2/3] Json validator --- .../graphcool-cli-core/src/commands/import/Validator.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cli/packages/graphcool-cli-core/src/commands/import/Validator.ts b/cli/packages/graphcool-cli-core/src/commands/import/Validator.ts index fef8ac80b..46523a111 100644 --- a/cli/packages/graphcool-cli-core/src/commands/import/Validator.ts +++ b/cli/packages/graphcool-cli-core/src/commands/import/Validator.ts @@ -59,6 +59,14 @@ export class Validator { ) ) }, + Json: (str) => { + try { + JSON.parse(str); + } catch (e) { + return false; + } + return true; + }, Boolean: isBoolean, } constructor(typesString: string) { From f8bef30cb3b025bf8ed7a805c0cfcc523d3931f8 Mon Sep 17 00:00:00 2001 From: SmEiTo Date: Mon, 21 May 2018 10:17:00 +0200 Subject: [PATCH 3/3] JSON field is always valid Because already parsed --- .../graphcool-cli-core/src/commands/import/Validator.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/cli/packages/graphcool-cli-core/src/commands/import/Validator.ts b/cli/packages/graphcool-cli-core/src/commands/import/Validator.ts index 46523a111..bf9fdb4f0 100644 --- a/cli/packages/graphcool-cli-core/src/commands/import/Validator.ts +++ b/cli/packages/graphcool-cli-core/src/commands/import/Validator.ts @@ -59,14 +59,7 @@ export class Validator { ) ) }, - Json: (str) => { - try { - JSON.parse(str); - } catch (e) { - return false; - } - return true; - }, + Json: () => true, Boolean: isBoolean, } constructor(typesString: string) {