From ee2453d5eb256dc7c321c8b90f0348355588618b Mon Sep 17 00:00:00 2001 From: Sunny Pelletier Date: Sun, 12 Jun 2022 10:02:43 -0400 Subject: [PATCH 1/3] add hasura default types --- .../src/generator/defaultFactories.ts | 248 +++++---- .../tests/generator/defaultFactories.spec.ts | 473 ++++++++++-------- 2 files changed, 401 insertions(+), 320 deletions(-) diff --git a/packages/plugins/query-generator/src/generator/defaultFactories.ts b/packages/plugins/query-generator/src/generator/defaultFactories.ts index aff50010..76b44267 100644 --- a/packages/plugins/query-generator/src/generator/defaultFactories.ts +++ b/packages/plugins/query-generator/src/generator/defaultFactories.ts @@ -1,109 +1,151 @@ +import _ from 'lodash' import type { GraphQLFactory } from './config' -const date = '2022-03-06T08:23:45.000Z' +const date = '2022-03-06' +const dateTime = '2022-03-06T08:23:45.000Z' const id = '08a16b83-9094-4e89-8c05-2ccadd5c1c7e' -const bigNumber = 123456789 const url = 'https://website.com' +const float = 30.7 -export const DEFAULT_FACTORIES: Record = { - String: (context) => { - switch (context.targetName.toLowerCase()) { - case 'email': - case 'emails': - case 'mail': - case 'mails': - return 'test-email@yourcompany.com' - case 'fullname': - case 'fullnames': - return 'John Doe' - case 'firstname': - case 'firstnames': - return 'John' - case 'lastname': - case 'lastnames': - return 'Doe' - case 'job': - case 'jobs': - case 'jobtitle': - case 'jobtitles': - return 'Engineer' - case 'jobarea': - return 'Engineering' - case 'phone': - case 'phones': - return '1+ 418-323-4236' - case 'country': - case 'countries': - return 'Canada' - case 'address': - case 'addresses': - return '2832 Sesame Street' - case 'state': - case 'states': - return 'Quebec' - case 'city': - case 'cities': - return 'Montreal' - case 'zipcode': - case 'zipcodes': - return 'G1G 43F' - case 'company': - case 'companies': - return 'Acme' - case 'department': - case 'departments': - return 'Engineering' - case 'date': - case 'dates': - case 'datetime': - case 'datetimes': - case 'instant': - return date - case 'price': - case 'prices': - return '500$' - case 'color': - case 'colors': - return '#e10098' - case 'product': - case 'products': - return 'Soup' - case 'material': - case 'materials': - return 'Wood' - case 'id': - case 'ids': - return id - case 'name': - case 'names': - return 'Some name' - case 'description': - case 'descriptions': - return 'Some description' - default: - return 'abc' - } - }, - ID: () => id, - Boolean: () => true, - Int: (context) => { - switch (context.targetName.toLocaleLowerCase()) { - case 'salary': - case 'salaries': - return 70_000 - case 'age': - case 'ages': - return 42 - default: - return 20 - } - }, - Float: () => 30.7, - Date: () => date, - DateTime: () => date, - Instant: () => date, - BigInteger: () => bigNumber, - Long: () => bigNumber, - Url: () => url, - URL: () => url, +export const DEFAULT_FACTORIES: Record = withVariants( + withAliases({ + // Common GraphQL Types + String: (context) => { + switch (context.targetName.toLowerCase()) { + case 'email': + case 'emails': + case 'mail': + case 'mails': + return 'test-email@yourcompany.com' + case 'fullname': + case 'fullnames': + return 'John Doe' + case 'firstname': + case 'firstnames': + return 'John' + case 'lastname': + case 'lastnames': + return 'Doe' + case 'job': + case 'jobs': + case 'jobtitle': + case 'jobtitles': + return 'Engineer' + case 'jobarea': + return 'Engineering' + case 'phone': + case 'phones': + return '1+ 418-323-4236' + case 'country': + case 'countries': + return 'Canada' + case 'address': + case 'addresses': + return '2832 Sesame Street' + case 'state': + case 'states': + return 'Quebec' + case 'city': + case 'cities': + return 'Montreal' + case 'zipcode': + case 'zipcodes': + return 'G1G 43F' + case 'company': + case 'companies': + return 'Acme' + case 'department': + case 'departments': + return 'Engineering' + case 'date': + case 'dates': + case 'datetime': + case 'datetimes': + case 'instant': + return dateTime + case 'price': + case 'prices': + return '500$' + case 'color': + case 'colors': + return '#e10098' + case 'product': + case 'products': + return 'Soup' + case 'material': + case 'materials': + return 'Wood' + case 'id': + case 'ids': + return id + case 'name': + case 'names': + return 'Some name' + case 'description': + case 'descriptions': + return 'Some description' + default: + return 'lorem ipsum' + } + }, + ID: () => id, + Boolean: () => true, + Int: (context) => { + switch (context.targetName.toLocaleLowerCase()) { + case 'salary': + case 'salaries': + return 70_000 + case 'age': + case 'ages': + return 36 + default: + return 42 + } + }, + Float: () => float, + Date: () => date, + DateTime: () => dateTime, + URL: () => url, + }), +) + +function withVariants( + record: Record, +): Record { + return { + ..._.reduce( + record, + (acc, value, key) => ({ + ...acc, + // Full lowercase + [key.toLowerCase()]: value, + // Only first letter lowercase + [key[0].toLowerCase() + key.slice(1)]: value, + }), + {}, + ), + ...record, + } +} + +function withAliases( + record: Record, +): Record { + return { + ...record, + Instant: record['DateTime'], + BigInteger: record['Int'], + BigNumber: record['Int'], + Long: record['Int'], + Url: record['URL'], + + // Hasura types + _text: record['String'], + Float8: record['Float'], + Numeric: record['Int'], + SmallInt: record['Int'], + Timestamp: record['DateTime'], + Timestamptz: record['DateTime'], + JsonB: () => ({}), + } } diff --git a/packages/plugins/query-generator/tests/generator/defaultFactories.spec.ts b/packages/plugins/query-generator/tests/generator/defaultFactories.spec.ts index f0782b8d..6275026e 100644 --- a/packages/plugins/query-generator/tests/generator/defaultFactories.spec.ts +++ b/packages/plugins/query-generator/tests/generator/defaultFactories.spec.ts @@ -1,226 +1,265 @@ import { DEFAULT_FACTORIES } from '../../src/generator/defaultFactories' -describe('generating default values', () => { - beforeAll(() => { - expect(Object.keys(DEFAULT_FACTORIES)).toHaveLength(12) - }) - - describe('input is a string', () => { - test.each(['Email', 'Emails', 'mail', 'mails'])( - 'should generate an email for input type %s', - (name) => - expect(runFactory('String', name)).toEqual( - 'test-email@yourcompany.com', - ), - ) - - test.each(['fullname', 'Fullnames'])( - 'should generate a full name for input type %s', - (name) => expect(runFactory('String', name)).toEqual('John Doe'), - ) - - test.each(['firstName', 'firstNames'])( - 'should generate a first name for input type %s', - (name) => expect(runFactory('String', name)).toEqual('John'), - ) - - test.each(['LastName', 'lastNames'])( - 'should generate a last name for input type %s', - (name) => expect(runFactory('String', name)).toEqual('Doe'), - ) - - test.each(['job', 'Job', 'JobTitle', 'JobTitles'])( - 'should generate a job title for input type %s', - (name) => expect(runFactory('String', name)).toEqual('Engineer'), - ) - - test.each(['jobArea'])( - 'should generate a job area for input type %s', - (name) => expect(runFactory('String', name)).toEqual('Engineering'), - ) - - test.each(['Phone', 'Phones'])( - 'should generate a phone for input type %s', - (name) => expect(runFactory('String', name)).toEqual('1+ 418-323-4236'), - ) - - test.each(['Country', 'Countries'])( - 'should generate a country for input type %s', - (name) => expect(runFactory('String', name)).toEqual('Canada'), - ) - - test.each(['address', 'addresses'])( - 'should generate a country for input type %s', - (name) => - expect(runFactory('String', name)).toEqual('2832 Sesame Street'), - ) - - test.each(['state', 'states'])( - 'should generate a state for input type %s', - (name) => expect(runFactory('String', name)).toEqual('Quebec'), - ) - - test.each(['city', 'cities'])( - 'should generate a city for input type %s', - (name) => expect(runFactory('String', name)).toEqual('Montreal'), - ) - - test.each(['zipCode', 'ZipCodes'])( - 'should generate a zip code for input type %s', - (name) => expect(runFactory('String', name)).toEqual('G1G 43F'), - ) - - test.each(['company', 'Companies'])( - 'should generate a company for input type %s', - (name) => expect(runFactory('String', name)).toEqual('Acme'), - ) - - test.each(['department', 'Departments'])( - 'should generate a department for input type %s', - (name) => expect(runFactory('String', name)).toEqual('Engineering'), - ) - - test.each(['date', 'dates', 'datetime', 'datetimes', 'instant'])( - 'should generate a date for input type %s', - (name) => - expect(runFactory('String', name)).toEqual('2022-03-06T08:23:45.000Z'), - ) - - test.each(['price', 'prices'])( - 'should generate a price for input type %s', - (name) => expect(runFactory('String', name)).toEqual('500$'), - ) - - test.each(['color', 'colors'])( - 'should generate a color for input type %s', - (name) => expect(runFactory('String', name)).toEqual('#e10098'), - ) - - test.each(['product', 'products'])( - 'should generate a product for input type %s', - (name) => expect(runFactory('String', name)).toEqual('Soup'), - ) - - test.each(['material', 'materials'])( - 'should generate a material for input type %s', - (name) => expect(runFactory('String', name)).toEqual('Wood'), - ) - - test.each(['id', 'ids'])( - 'should generate an id for input type %s', - (name) => - expect(runFactory('String', name)).toEqual( - '08a16b83-9094-4e89-8c05-2ccadd5c1c7e', - ), - ) - - test.each(['name', 'names'])( - 'should generate a name for input type %s', - (name) => expect(runFactory('String', name)).toEqual('Some name'), - ) - - test.each(['description', 'descriptions'])( - 'should generate a description for input type %s', - (name) => expect(runFactory('String', name)).toEqual('Some description'), - ) - - test.each(['everythingelse', 'somestuff'])( - 'should generate a generic string for input type %s', - (name) => expect(runFactory('String', name)).toEqual('abc'), - ) - }) - - describe('input is an int', () => { - test.each(['Salary', 'Salaries'])( - 'should generate a salary for input type %s', - (name) => expect(runFactory('Int', name)).toEqual(70_000), - ) - - test.each(['age', 'Ages'])( - 'should generate a salary for input type %s', - (name) => expect(runFactory('Int', name)).toEqual(42), - ) - - test.each(['anythingelse', 'asd'])( - 'should generate a generic number for input type %s', - (name) => expect(runFactory('Int', name)).toEqual(20), - ) - }) - - describe('input is a float', () => { - test.each(['anythingelse', 'asd'])( - 'should generate a generic float for input type %s', - (name) => expect(runFactory('Float', name)).toEqual(30.7), - ) - }) - - describe('input is a boolean', () => { - test.each(['anythingelse', 'asd'])( - 'should generate a generic boolean for input type %s', - (name) => expect(runFactory('Boolean', name)).toEqual(true), - ) - }) - - describe('input is an ID', () => { - test.each(['anythingelse', 'asd'])( - 'should generate a generic ID for input type %s', - (name) => - expect(runFactory('ID', name)).toEqual( - '08a16b83-9094-4e89-8c05-2ccadd5c1c7e', - ), - ) - }) - - describe('input is a Date', () => { - test.each(['anythingelse', 'asd'])( - 'should generate a generic date for input type %s', - (name) => - expect(runFactory('Date', name)).toEqual('2022-03-06T08:23:45.000Z'), - ) - }) - - describe('input is a DateTime', () => { - test.each(['anythingelse', 'asd'])( - 'should generate a generic datetime for input type %s', - (name) => - expect(runFactory('DateTime', name)).toEqual( - '2022-03-06T08:23:45.000Z', - ), - ) - }) - - describe('input is an Instant', () => { - test.each(['anythingelse', 'asd'])( - 'should generate a generic instant for input type %s', - (name) => - expect(runFactory('Instant', name)).toEqual('2022-03-06T08:23:45.000Z'), - ) - }) +export type TestSet = { + type: string + names: string[] + expected: T +} - describe('input is a Big Integer', () => { - test.each(['anythingelse', 'asd'])( - 'should generate a generic big number for input type %s', - (name) => expect(runFactory('BigInteger', name)).toEqual(123456789), - ) - }) +const ALL_SETS: ReadonlyArray> = [ + { + type: 'String', + names: ['Email', 'Emails', 'mail', 'mails'], + expected: 'test-email@yourcompany.com', + }, + { + type: 'String', + names: ['fullname', 'Fullnames'], + expected: 'John Doe', + }, + { + type: 'String', + names: ['firstname', 'FirstNames'], + expected: 'John', + }, + { + type: 'String', + names: ['LastName', 'lastNames'], + expected: 'Doe', + }, + { + type: 'String', + names: ['job', 'Job', 'JobTitle', 'JobTitles'], + expected: 'Engineer', + }, + { + type: 'String', + names: ['jobArea', 'departments', 'department'], + expected: 'Engineering', + }, + { + type: 'String', + names: ['Phone', 'Phones'], + expected: '1+ 418-323-4236', + }, + { + type: 'String', + names: ['country', 'Countries'], + expected: 'Canada', + }, + { + type: 'String', + names: ['address', 'Addresses'], + expected: '2832 Sesame Street', + }, + { + type: 'String', + names: ['State', 'states', 'province', 'provinces'], + expected: 'Quebec', + }, + { + type: 'String', + names: ['City', 'cities', 'town', 'towns'], + expected: 'Montreal', + }, + { + type: 'String', + names: ['zipCode', 'zipCodes'], + expected: 'G1G 43F', + }, + { + type: 'String', + names: ['company', 'Companies'], + expected: 'Acme Inc', + }, + { + type: 'String', + names: [ + 'datetime', + 'datetimes', + 'instant', + 'timestamp', + 'timestampz', + 'timestamps', + ], + expected: '2022-03-06T08:23:45.000Z', + }, + { + type: 'String', + names: ['date', 'dates'], + expected: '2022-03-06', + }, + { + type: 'String', + names: ['price', 'prices'], + expected: '$1,234.56', + }, + { + type: 'String', + names: ['color', 'colors', 'paint', 'paints'], + expected: '#e10098', + }, + { + type: 'String', + names: ['product', 'products'], + expected: 'Soup', + }, + { + type: 'String', + names: ['material', 'materials'], + expected: 'Wood', + }, + { + type: 'String', + names: ['id', 'ids', 'identifier', 'identifiers', 'uuid', 'uuids'], + expected: '08a16b83-9094-4e89-8c05-2ccadd5c1c7e', + }, + { + type: 'String', + names: ['size', 'sizes'], + expected: 'Large', + }, + { + type: 'String', + names: ['name', 'names'], + expected: 'A name', + }, + { + type: 'String', + names: ['description', 'descriptions'], + expected: 'A description', + }, + { + type: 'String', + names: ['url', 'urls'], + expected: 'https://website.com', + }, + { + type: 'String', + names: ['everythingelse', 'somestuff'], + expected: 'lorem ipsum', + }, + { + type: '_text', + names: ['everythingelse', 'somestuff'], + expected: 'lorem ipsum', + }, + { + type: 'Int', + names: ['salary', 'salaries'], + expected: 70_000, + }, + { + type: 'Int', + names: ['age', 'ages'], + expected: 42, + }, + { + type: 'Int', + names: ['anythingelse', 'asd'], + expected: 42, + }, + { + type: 'Float', + names: ['anythingelse', 'asd'], + expected: 30.7, + }, + { + type: 'Boolean', + names: ['anythingelse', 'asd'], + expected: true, + }, + { + type: 'ID', + names: ['anythingelse', 'asd'], + expected: '08a16b83-9094-4e89-8c05-2ccadd5c1c7e', + }, + { + type: 'Id', + names: ['anythingelse', 'asd'], + expected: '08a16b83-9094-4e89-8c05-2ccadd5c1c7e', + }, + { + type: 'Date', + names: ['anythingelse', 'asd'], + expected: '2022-03-06', + }, + { + type: 'Timestamp', + names: ['anythingelse', 'asd'], + expected: '2022-03-06T08:23:45.000Z', + }, + { + type: 'Timestamptz', + names: ['anythingelse', 'asd'], + expected: '2022-03-06T08:23:45.000Z', + }, + { + type: 'DateTime', + names: ['anythingelse', 'asd'], + expected: '2022-03-06T08:23:45.000Z', + }, + { + type: 'Instant', + names: ['anythingelse', 'asd'], + expected: '2022-03-06T08:23:45.000Z', + }, + { + type: 'BigInteger', + names: ['anythingelse', 'asd'], + expected: 42, + }, + { + type: 'BigNumber', + names: ['anythingelse', 'asd'], + expected: 42, + }, + { + type: 'Long', + names: ['anythingelse', 'asd'], + expected: 42, + }, + { + type: 'URL', + names: ['anythingelse', 'asd'], + expected: 'https://website.com', + }, + { + type: 'Url', + names: ['anythingelse', 'asd'], + expected: 'https://website.com', + }, +] - describe('input is a Long', () => { - test.each(['anythingelse', 'asd'])( - 'should generate a generic big number for input type %s', - (name) => expect(runFactory('Long', name)).toEqual(123456789), - ) +describe('generating default values', () => { + beforeAll(() => { + // If this fails, make sure you add a test for the new types + expect(Object.keys(DEFAULT_FACTORIES)).toHaveLength(45) }) - describe('input is an URL', () => { - test.each(['anythingelse', 'asd'])( - 'should generate a generic big number for input type %s', - (name) => expect(runFactory('URL', name)).toEqual('https://website.com'), - ) - - test.each(['anythingelse', 'asd'])( - 'should generate a generic big number for input type %s', - (name) => expect(runFactory('Url', name)).toEqual('https://website.com'), - ) + ALL_SETS.forEach((set) => { + describe(`input is '${set.type}'`, () => { + test.each(set.names)( + `should generate '${set.type}' for input name %s`, + (input) => { + expect(runFactory(set.type, input)).toEqual(set.expected) + }, + ) + + test.each(set.names.map((name) => name.toLocaleLowerCase()))( + `should generate '${set.type}' for input name %s`, + (input) => { + expect(runFactory(set.type, input)).toEqual(set.expected) + }, + ) + + test.each(set.names.map((name) => name[0] + name.slice(1)))( + `should generate '${set.type}' for input name %s`, + (input) => { + expect(runFactory(set.type, input)).toEqual(set.expected) + }, + ) + }) }) }) From 6cf595ba492e99a048175e23f9682d38532dbb85 Mon Sep 17 00:00:00 2001 From: Sunny Pelletier Date: Sun, 12 Jun 2022 10:46:03 -0400 Subject: [PATCH 2/3] add support for some default hasura types --- .../04.Plugins/02.GraphQL Query Generator.md | 4 +-- .../src/generator/defaultFactories.ts | 34 +++++++++++++++---- .../tests/generator/defaultFactories.spec.ts | 10 +++--- .../tests/generator/queryGenerator.spec.ts | 20 +++++------ 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/docs/pages/04.Plugins/02.GraphQL Query Generator.md b/docs/pages/04.Plugins/02.GraphQL Query Generator.md index f69e79f2..16ecf581 100644 --- a/docs/pages/04.Plugins/02.GraphQL Query Generator.md +++ b/docs/pages/04.Plugins/02.GraphQL Query Generator.md @@ -31,8 +31,8 @@ query getPerson($delay: Int, $delay2: Int) { ```json { - "delay": 20, - "delay2": 20 + "delay": 42, + "delay2": 42 } ``` diff --git a/packages/plugins/query-generator/src/generator/defaultFactories.ts b/packages/plugins/query-generator/src/generator/defaultFactories.ts index 76b44267..1c814665 100644 --- a/packages/plugins/query-generator/src/generator/defaultFactories.ts +++ b/packages/plugins/query-generator/src/generator/defaultFactories.ts @@ -44,30 +44,41 @@ export const DEFAULT_FACTORIES: Record = withVariants( return '2832 Sesame Street' case 'state': case 'states': + case 'province': + case 'provinces': return 'Quebec' case 'city': case 'cities': + case 'town': + case 'towns': return 'Montreal' case 'zipcode': case 'zipcodes': return 'G1G 43F' case 'company': case 'companies': - return 'Acme' + return 'Acme Inc' case 'department': case 'departments': return 'Engineering' - case 'date': - case 'dates': case 'datetime': case 'datetimes': + case 'timestamp': + case 'timestamps': + case 'timestampz': case 'instant': + case 'instants': return dateTime + case 'date': + case 'dates': + return date case 'price': case 'prices': - return '500$' + return '$1,234.56' case 'color': case 'colors': + case 'paint': + case 'paints': return '#e10098' case 'product': case 'products': @@ -77,13 +88,23 @@ export const DEFAULT_FACTORIES: Record = withVariants( return 'Wood' case 'id': case 'ids': + case 'identifier': + case 'identifiers': + case 'uuid': + case 'uuids': return id + case 'size': + case 'sizes': + return 'Large' + case 'url': + case 'urls': + return url case 'name': case 'names': - return 'Some name' + return 'A name' case 'description': case 'descriptions': - return 'Some description' + return 'A description' default: return 'lorem ipsum' } @@ -134,6 +155,7 @@ function withAliases( return { ...record, Instant: record['DateTime'], + Id: record['ID'], BigInteger: record['Int'], BigNumber: record['Int'], Long: record['Int'], diff --git a/packages/plugins/query-generator/tests/generator/defaultFactories.spec.ts b/packages/plugins/query-generator/tests/generator/defaultFactories.spec.ts index 6275026e..ab684d32 100644 --- a/packages/plugins/query-generator/tests/generator/defaultFactories.spec.ts +++ b/packages/plugins/query-generator/tests/generator/defaultFactories.spec.ts @@ -152,7 +152,7 @@ const ALL_SETS: ReadonlyArray> = [ { type: 'Int', names: ['age', 'ages'], - expected: 42, + expected: 36, }, { type: 'Int', @@ -234,27 +234,27 @@ const ALL_SETS: ReadonlyArray> = [ describe('generating default values', () => { beforeAll(() => { // If this fails, make sure you add a test for the new types - expect(Object.keys(DEFAULT_FACTORIES)).toHaveLength(45) + expect(Object.keys(DEFAULT_FACTORIES)).toHaveLength(46) }) ALL_SETS.forEach((set) => { describe(`input is '${set.type}'`, () => { test.each(set.names)( - `should generate '${set.type}' for input name %s`, + `should generate '${set.type}' for input name '%s'`, (input) => { expect(runFactory(set.type, input)).toEqual(set.expected) }, ) test.each(set.names.map((name) => name.toLocaleLowerCase()))( - `should generate '${set.type}' for input name %s`, + `should generate '${set.type}' for input name '%s'`, (input) => { expect(runFactory(set.type, input)).toEqual(set.expected) }, ) test.each(set.names.map((name) => name[0] + name.slice(1)))( - `should generate '${set.type}' for input name %s`, + `should generate '${set.type}' for input name '%s'`, (input) => { expect(runFactory(set.type, input)).toEqual(set.expected) }, diff --git a/packages/plugins/query-generator/tests/generator/queryGenerator.spec.ts b/packages/plugins/query-generator/tests/generator/queryGenerator.spec.ts index 70202a4b..56af8b1f 100644 --- a/packages/plugins/query-generator/tests/generator/queryGenerator.spec.ts +++ b/packages/plugins/query-generator/tests/generator/queryGenerator.spec.ts @@ -71,10 +71,10 @@ describe('generating a query', () => { const result = generateGraphQLQuery(recursiveField, emptyConfig) expect(result?.variables).toEqual({ - delay: 20, - delay2: 20, - delay3: 20, - delay4: 20, + delay: 42, + delay2: 42, + delay3: 42, + delay4: 42, }) }) }) @@ -109,8 +109,8 @@ describe('generating a query', () => { const result = generateGraphQLQuery(recursiveField, config) expect(result?.variables).toEqual({ - delay: 20, - delay2: 20, + delay: 42, + delay2: 42, }) }) }) @@ -306,7 +306,7 @@ describe('generating a query', () => { const result = generateGraphQLQuery(deepNonRecursiveField, config) expect(result?.variables).toEqual({ - delay: 20, + delay: 42, }) }) }) @@ -336,7 +336,7 @@ describe('generating a query', () => { const result = generateGraphQLQuery(deepNonRecursiveField, config) expect(result?.variables).toEqual({ - delay: 20, + delay: 42, }) }) }) @@ -384,7 +384,7 @@ describe('generating a mutation', () => { it('generates the variables properly', () => { const result = generateGraphQLQuery(mutation, config) expect(result?.variables).toEqual({ - value: 'abc', + value: 'lorem ipsum', }) }) }) @@ -410,7 +410,7 @@ describe('generating a subscription', () => { it('generates the variables properly', () => { const result = generateGraphQLQuery(subscription, config) expect(result?.variables).toEqual({ - delay: 20, + delay: 42, }) }) }) From 577cc6148f9ef15a2b2156ad246b82d6f13a2958 Mon Sep 17 00:00:00 2001 From: Sunny Pelletier Date: Sun, 12 Jun 2022 10:48:47 -0400 Subject: [PATCH 3/3] add tests --- .../tests/generator/defaultFactories.spec.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/plugins/query-generator/tests/generator/defaultFactories.spec.ts b/packages/plugins/query-generator/tests/generator/defaultFactories.spec.ts index ab684d32..1a6820bf 100644 --- a/packages/plugins/query-generator/tests/generator/defaultFactories.spec.ts +++ b/packages/plugins/query-generator/tests/generator/defaultFactories.spec.ts @@ -159,11 +159,26 @@ const ALL_SETS: ReadonlyArray> = [ names: ['anythingelse', 'asd'], expected: 42, }, + { + type: 'Numeric', + names: ['anythingelse', 'asd'], + expected: 42, + }, + { + type: 'SmallInt', + names: ['anythingelse', 'asd'], + expected: 42, + }, { type: 'Float', names: ['anythingelse', 'asd'], expected: 30.7, }, + { + type: 'Float8', + names: ['anythingelse', 'asd'], + expected: 30.7, + }, { type: 'Boolean', names: ['anythingelse', 'asd'], @@ -229,6 +244,11 @@ const ALL_SETS: ReadonlyArray> = [ names: ['anythingelse', 'asd'], expected: 'https://website.com', }, + { + type: 'JsonB', + names: ['anythingelse', 'asd'], + expected: {}, + }, ] describe('generating default values', () => {