Gathering detailed insights and metrics for graphql-date-scalars
Gathering detailed insights and metrics for graphql-date-scalars
Gathering detailed insights and metrics for graphql-date-scalars
Gathering detailed insights and metrics for graphql-date-scalars
npm install graphql-date-scalars
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2 Stars
39 Commits
4 Forks
27 Watching
2 Branches
159 Contributors
Updated on 01 Sept 2023
TypeScript (99.03%)
JavaScript (0.97%)
Cumulative downloads
Total Downloads
Last day
-3.2%
1,235
Compared to previous day
Last week
-3.3%
6,147
Compared to previous week
Last month
1.1%
25,892
Compared to previous month
Last year
-5%
441,902
Compared to previous year
GraphQL Scalars for Date (YYYY-MM-DD), DateTime (YYYY-MM-DDTHH:MM:SSZ), and Time (HH:MM:SSZ)
1import { gql, ApolloServer } from 'apollo-server'; 2import { DateScalar, TimeScalar, DateTimeScalar } from 'graphql-date-scalars'; 3 4const resolvers = { 5 // Must define resolvers for these scalars 6 Date: DateScalar, 7 Time: TimeScalar, 8 DateTime: DateTimeScalar, 9 10 // along with all your other resolvers 11 Query: { 12 exampleDateQuery: () => { 13 // Will serialize to a date string, such as 2007-12-03 14 return new Date(); 15 }, 16 exampleTimeQuery: () => { 17 // Will serialize to a time string at UTC, such as 10:15:30Z 18 return new Date(); 19 }, 20 }, 21 Mutation: { 22 exampleDateTimeMutation: () => { 23 // Will serialize to a date-time string at UTC, such as 2007-12-03T10:15:30Z 24 return new Date(); 25 }, 26 }, 27}; 28 29const typeDefs = gql` 30 scalar Date 31 scalar DateTime 32 33 extend type Query { 34 exampleDateQuery: Date! 35 exampleTimeQuery: Time! 36 } 37 38 extend type Mutation { 39 exampleDateTimeMutation: DateTime! 40 } 41`; 42 43const server = new ApolloServer({ 44 typeDefs, 45 resolvers, 46});
If you are using @graphql-codegen
then you must include these scalars in your codegen yml file under config
1schema: './example-schema.graphql' 2config: 3 scalars: 4 Date: Date 5 Time: Date 6 DateTime: Date 7generates: 8 src/types/example-schema.d.ts: 9 plugins: 10 - 'typescript'
You can also use the parse and serialize methods directly, which is useful if you are making a rest call to a 3rd party vendor.
1import { DateTimeScalar } from 'graphql-date-scalars'; 2 3const vendorResponse = await restClient.get(); 4 5const response = { 6 ...vendorResponse, 7 createdAt: DateTimeScalar.parseValue(vendorResponse.createdAt), 8};
1import { DateScalar } from 'graphql-date-scalars'; 2 3const args = { 4 ...input, 5 dateOfBirth: DateScalar.serialize(input.dateOfBirth), 6}; 7 8const response = await restClient.post(args);
npm i
npm run build
To clean the build directory run npm run clean
npm run test
package.json
CHANGELOG.md
entrynpm pack
to see what will be published then delete the .tgz
file that was creatednpm publish
1.0.0
the tag and release name would be v1.0.0
.This project started as a fork of https://github.com/excitement-engineer/graphql-iso-date
No vulnerabilities found.
No security vulnerabilities found.