diff --git a/package-lock.json b/package-lock.json index eb611eec..c589ba8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "graphql-faker", "version": "2.0.0-rc.25", "license": "MIT", "dependencies": { diff --git a/src/default-schema.graphql b/src/default-schema.graphql index a1db4180..af2a8e0a 100644 --- a/src/default-schema.graphql +++ b/src/default-schema.graphql @@ -11,6 +11,8 @@ # # Developed with ❤️ by APIs.guru | https://github.com/APIs-guru/graphql-faker +scalar DateTime + type Company { id: ID name: String @fake(type: companyName) @@ -26,6 +28,7 @@ type Employee { address: String @fake(type: streetAddress, options: { useFullAddress: true }) subordinates: [Employee!] @listLength(min: 0, max: 3) company: Company + hiredAt: DateTime @fake(type: dateTime, options: {dateFrom: "2022-01-01", dateTo: "2022-02-28"}) } type Query { diff --git a/src/fake.ts b/src/fake.ts index 11980406..d731c7b8 100644 --- a/src/fake.ts +++ b/src/fake.ts @@ -94,6 +94,19 @@ const fakeFunctions = { args: ['dateFormat'], func: (dateFormat) => moment(faker.date.recent()).format(dateFormat), }, + // DateTime section + dateTime: { + args: ['dateFormat', 'dateFrom', 'dateTo'], + func: (dateFormat, dateFrom, dateTo) => { + const date = moment(faker.date.between(dateFrom, dateTo)); + const datetime = moment(faker.datatype.datetime()); + return datetime.dayOfYear(date.dayOfYear()) + .year(date.year()) + .format(dateFormat) + .toString() + + } + }, // Finance section financeAccountName: () => faker.finance.accountName(), diff --git a/src/fake_definition.ts b/src/fake_definition.ts index 2b158207..a09efd02 100644 --- a/src/fake_definition.ts +++ b/src/fake_definition.ts @@ -113,6 +113,13 @@ const fakeDefinitionAST = parse(/* GraphQL */ ` hackerAbbreviation hackerPhrase + + """ + datetime + by default ISO8601 + """ + dateTime + "An image url. Configure image with options: \`imageCategory\`, \`imageWidth\`, \`imageHeight\` and \`randomizeImageUrl\`" imageUrl @@ -194,7 +201,7 @@ const fakeDefinitionAST = parse(/* GraphQL */ ` passwordLength: Int "Only for type \`lorem\`" loremSize: fake__loremSize - "Only for types \`*Date\`. Example value: \`YYYY MM DD\`. [Full Specification](http://momentjs.com/docs/#/displaying/format/)" + "Only for types \`*Date, dateTime\`. Example value: \`YYYY MM DD\`. [Full Specification](http://momentjs.com/docs/#/displaying/format/)" dateFormat: String = "YYYY-MM-DDTHH:mm:ss[Z]" "Only for types \`betweenDate\`. Example value: \`1986-11-02\`." dateFrom: String = "2010-01-01"