excitement-engineer / graphql-iso-date Goto Github PK
View Code? Open in Web Editor NEWA set of RFC 3339 compliant date/time GraphQL scalar types.
License: MIT License
A set of RFC 3339 compliant date/time GraphQL scalar types.
License: MIT License
Looks like the datetime regex rejects the following:
DateTime cannot represent an invalid date-time-string 2017-07-06T00:00:00.
...because there is no trailing "Z". Is that an accurate interpretation of the specification?
Here are some regexes in the wild that successfully match it:
http://jsfiddle.net/wq7tjec7/14/
https://www.myintervals.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/
https://www.regextester.com/94925
Thanks for the package!
I'm using DateTime in my model, but when I use simple date formats like '1-1-2020' in my queries, they fail validation. Why is that? The back-end date may contain both a date and a time, but like any other query language I want to be able to query these fields with simple date formats or with more specific DateTime formats. Why can't I query a DateTime with a Date?
I'm trying to figure out the best way to accomplish the above and having some trouble with it. Any advice?
Hello,
There's a problem here when the number is more than 32bit and I believe it will be a problem in the future. Could you please fix this?
If Service A has a mutation accepting a GraphQLDate input and it needs to delegate or forward that to another Service B with the same signature, the GraphQLDate yyyy-mm-dd
string will be converted to a full DateTime string yyyy-mm-ddT00:00:00Z
before arriving at Service B which fails validation.
For example, if the same mutation exists both in Service A and Service B, with A delegating the mutation to Service B:
Mutation {
updateUser(input: UserInput!): User!
}
type User {
id: ID!
dob: GraphQLDate!
}
input UserInput {
id: ID!
dob: GraphQLDate!
}
And a client mutates Service A with the following
mutation updateUser($input: UserInput) {
updateUser(input: $input) {
id
dob
}
}
{
"input": {
"id": "1234",
"dob": "2000-01-01"
}
}
When service B receives the mutation, it will see the following as the input because it is being parsed to a JS Date object in service A:
{
"input": {
"id": "1234",
"dob": "2000-01-01T00:00:00Z"
}
}
Which fails validation.
You are already stripping the time component when serializing the GraphQL date. Can we do the same when parsing so that values can be passed from service to service?
eg I have a type E with following statements
const GraphqlISODate = require('graphql-iso-date');
const {GraphQLDate} = GraphqlISODate;
module.exports = gql`
type E {
...
purchaseDate: GraphQLDate
}
`
But I got error with GraphQLDate not found, how can I resolved it?
Export flow type definitions for the library so that people using flow will also be able to use in combination with this library.
There should be a space in the description here.
Consider this example:
# Schema
type LogInput {
message: String!
createdAt: Date!
}
type Log {
id: ID!
message: String!
createdAt: Date!
}
type Mutation {
createLog(log: LogInput!): Log!
}
# query
mutation {
createLog({
message: "Hello, World!",
createdAt: "2017-01-001" # invalid
}) {
message,
createdAt
}
}
In this example, parsing silently fails and sets the createdAt
to null
. I think it would be more useful to thrown an error in this case.
Please add an example for using graphsql-iso-date with the 'makeExecutableSchema' function from 'graphql-tools'
Thanks !!
> new Date('10/30/1975').getDate()
30
> new Date('1975-10-30').getDate()
29
I'm on EDT (US eastern daylight time). My server is not, so it gets 30
for both.
Use the Travis build stages to simplify the deployment process. This will remove the need for the travis-after-all script.
I am using Typescript 2.3.4 and got this error:
TS7016: Could not find a declaration file for module 'graphql-iso-date'. '<project>/node_modules/graphql-iso-date/dist/index.js' implicitly has an 'any' type.
A declaration file could be added here or on https://github.com/DefinitelyTyped/DefinitelyTyped
I think it would be very useful to allow posix timestamps (kind== int or string) to be parsed into DateTime format. Any reason you can think of not to include this?
Where an RFC 3339 compliant date-time string has a time-zone other than UTC, it is shifted to UTC. For example, the date-time string "2016-01-01T14:10:20+01:00" is shifted to "2016-01-01T13:10:20Z".
Would there be consideration to add a type that allows offsets?
Could you implement the same formats (including the time ones) that you propose in graphql/graphql-js#557 ?
This is a good foundation and a good interim solution, but it only covers date (without timezone) not time.
Thanks in advance
Hi,
i am getting bellow error can someone please help me. in typedef.graphql file i am using bellow
type TimestampType {
createdAt: DateTime
createdBy: ProfileType
modifiedAt: DateTime
modifiedBy: ProfileType
}
mergeSchemas.js:49
throw new Error("Can't find type " + name + ".");
^
Error: Can't find type DateTime.
I just updated to Apollo Server 2.0 and I keep getting the following error whenever I run any query/mutation which uses the Date
scalar type I've defined using graphql-iso-date
:
Unknown type "DateTime". Did you mean "Date"?
resolvers.js
const { GraphQLDateTime } = require('graphql-iso-date')
const scalarResolvers = {
Date: GraphQLDateTime
}
...
const resolvers = [scalarResolvers, exampleResolver1, exampleResolver2]
module.exports = mergeResolvers(resolvers)
types.js
const scalarTypes = gql`
scalar Date
`
const typeDefs = [scalarTypes, exampleType1, exampleType2]
module.exports = mergeTypes(typeDefs)
Query type definition:
type Query {
allUsers(
limit: Int
page: Int
sort: String
minDate: Date
maxDate: Date
): paginatedUsers
}
I get the error whenever I execute this:
query ($limit: Int!, $page: Int!, $sort: String!, $minDate: Date, $maxDate: Date) {
allUsers(
limit: $limit
page: $page
sort: $sort
minDate: $minDate
maxDate: $maxDate
) {
docs {
_id
firstName
lastName
permanentAddress
createdAt
}
total
limit
page
pages
prev
next
}
}
Another weird thing is that on introspection, the schema in GraphQL Playground says minDate
and maxDate
are DateTime
even though I've defined them as Date
in my schema definition.
allUsers(
limit: Int
page: Int
sort: String
minDate: DateTime
maxDate: DateTime
): paginatedUsers
Update peerDependencies in package.json
.
How to return null instead of throw Error for invalid DateTime?
Is there any plan to support GraphQL 15 as the peer dependency goes up to ^14.0.0
Returning null in the resolver for a nullable DateTime gives 1970-01-01T00:00:00.000Z
typeDefs = `
type User {
dob: DateTime
}
`
resolvers = {
User: {
dob: () => null
}
}
I would expect returning null to have the query response also be null instead of 1970-01-01T00:00:00.000Z
Seems odd that ES native expression of time (UNIX timestamp in milliseconds) is not supported as a valid input; only the truncated (seconds) format is accepted. This requires a superfluous new Date(timestamp)
wrapper.
I have datetime strings that are not recognized as a valid value, it throws following error:
found "2021-10-31T05:55:00+0000"; DateTime cannot represent an invalid date-time-string 2021-10-31T05:55:00+0000
If I add a colon it works: "2021-10-31T05:55:00+00:00"; Is it possible to add support for the non-colon datetime string as it is also a valid iso string?
GraphQL versions 15 and 16 are currently not supported in the dependencies. Opening this issue to upgrade the dependencies.
How does one use this custom scalar if we're using buildSchema
to build our schema, e.g.:
module.exports = buildSchema(`
type User {
id: ID!
email: String!
firstName: String!
lastName: String!
signupDate: DateTime!
}
Currently TypeError
s are thrown when parsing or serialization fails. I think these should be wrapped with locatedError
.
This gives more insightful results:
{
"errors": [{
"message": "Variable \"$dateTime\" got invalid value {\"dateTime\":\"0\"}; Expected type DateTime at value.dateTime; DateTime cannot represent an invalid date-time-string 0.",
"locations": [{
"line": 2,
"column": 11
}]
}]
}
Folks customizing formatError()
will be able to identify the thrown exception as coming from the GraphQL layer, rather than being an exception thrown by resolver code. This is important to avoid leaking implementation errors, whilst still returning feedback to clients when they send incorrect values.
Would you take a PR that makes this change?
Will you support graphql 16.3.0?
In my resolvers, I use something like:
const resolvers = {
AllowedColor: {
RED: '#f00',
GREEN: '#0f0',
BLUE: '#00f',
}
};
(example taken from the Apollo Docs)
Unfortunately, adding these internal values results in an error:
C:...\node_modules\graphql-tools\dist\transforms\visitSchema.js:1
Error: Can't find type DateTime.
Everything works fine when using "regular" enums without internal values. On the other hand, the code above works as intended when graphql-iso-date isn't used.
I made this codesandbox, just uncomment the section with the enum resolver to see the problem in action.
Any ideas how to fix this issue?
It can be recognized by new Date(), but I have to add resolver for DateTime:
createdAt({ createdAt }) {
return new Date(createdAt);
},
I just begin a tutorial with graphql that use your lib, they use [email protected] so I had to do npm i -force
to install your lib since you don't allow GraphQL 15, is there a reason or will that be possible soon ?
Hi,
I have dates in the format of 2019-12-18T04:41:32.428+0000
and I get the error DateTime cannot represent an invalid date-time-string 2019-12-18T04:41:32.428+0000.
. I think this is a valid date however. Any idea why it doesn't like this?
Hi,
I think it would be helpful to add an example on how to use the package from the client side ( JS for example ) specially when using a date argument as mutation input.
I'm receiving dates in the ISO8601 compatible format 2018-06-13T18:24:53.000+0000 from a database.
GraphQLDateTime from graphql-iso-date won't parse these strings into dates because of the lack of a colon in the timezone offset part.
I'm automatically creating resolvers and objects from a database schema (salesforce describe), and it's a bit hacky to test if i'm receiving a date field from the database and then convert from the 8601 string to a Date object or a 3339 string.
Ideally graphql-iso-date should also support the limited ISO8601 grammar as described in Appendix A of the ISO3339 RFC. This would allow for parsing most dates, without having to handle the full mess that is the ISO8601 format.
I'll probably open a pull request in a few days once I get some free time and see how big an undertaking this will be
graphql-iso-date version 3.6.1
graphql version 14.3.0
I input a UTC time string in graphql as "14:30:00Z", and it is returned correctly as "14:30:00.000Z", but in the mysql database the time is stored a few hours off according to my system timezone (10:30:00). Mysql is set to use UTC, so I am not sure why this is happening.
Branch | Build failing π¨ |
---|---|
Dependency | eslint-plugin-flowtype |
Current Version | 2.30.0 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As eslint-plugin-flowtype is βonlyβ a devDependency of this project it might not break production or downstream projects, but βonlyβ your build or test tools β preventing new deploys or publishes.
I recommend you give this issue a high priority. Iβm sure you can resolve this πͺ
The new version differs by 10 commits (ahead by 10, behind by 2).
c2f959e
2.30.1
2243076
fix: force release
5de0277
chore: use babel-preset-env
51ae588
refactor: use standard export syntax
e939596
fix: use semantic-release
0f23196
chore: remove commitmsg linting
751ac95
chore: release 2.30.0
def54e1
docs: update documentation
1242ab4
fix: ensure colon is not null in typeColonSpacing reporter (#197)
42ba3e4
docs: fix typo (#195)
See the full diff.
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot π΄
In newer versions of Flow (>=0.95) the types for JSON.stringify
have been changed which is causing errors when using graphql-iso-date
.
Error ββββββββββββββββββββββββββββββββββββββββββββββββββββββ node_modules/graphql-iso-date/dist/date/index.js.flow:48:11
Cannot add 'Date canno...' and JSON.stringify(...) because undefined [1] is incompatible with string [2].
node_modules/graphql-iso-date/dist/date/index.js.flow
44β )
45β } else {
46β throw new TypeError(
[2] 47β 'Date cannot represent a non string, or non Date type ' +
48β JSON.stringify(value)
49β )
50β }
51β },
/private/tmp/flow/flowlib_2a9f9c93/core.js
[1] 491β ): string | void;
Error ββββββββββββββββββββββββββββββββββββββββββββββββββββββ node_modules/graphql-iso-date/dist/date/index.js.flow:55:50
Cannot coerce JSON.stringify(...) to string because undefined [1] should not be coerced.
node_modules/graphql-iso-date/dist/date/index.js.flow
52β parseValue (value) {
53β if (!(typeof value === 'string' || value instanceof String)) {
54β throw new TypeError(
55β `Date cannot represent non string type ${JSON.stringify(value)}`
56β )
57β }
58β
/private/tmp/flow/flowlib_2a9f9c93/core.js
[1] 491β ): string | void;
Error ββββββββββββββββββββββββββββββββββββββββββββββββββ node_modules/graphql-iso-date/dist/dateTime/index.js.flow:64:43
Cannot add 'DateTime c...' + 'non numeri...' and JSON.stringify(...) because undefined [1] is incompatible with
string [2].
node_modules/graphql-iso-date/dist/dateTime/index.js.flow
60β )
61β } else {
62β throw new TypeError(
[2] 63β 'DateTime cannot be serialized from a non string, ' +
64β 'non numeric or non Date type ' + JSON.stringify(value)
65β )
66β }
67β },
/private/tmp/flow/flowlib_2a9f9c93/core.js
[1] 491β ): string | void;
Error ββββββββββββββββββββββββββββββββββββββββββββββββββ node_modules/graphql-iso-date/dist/dateTime/index.js.flow:71:54
Cannot coerce JSON.stringify(...) to string because undefined [1] should not be coerced.
node_modules/graphql-iso-date/dist/dateTime/index.js.flow
68β parseValue (value) {
69β if (!(typeof value === 'string' || value instanceof String)) {
70β throw new TypeError(
71β `DateTime cannot represent non string type ${JSON.stringify(value)}`
72β )
73β }
74β
/private/tmp/flow/flowlib_2a9f9c93/core.js
[1] 491β ): string | void;
Error ββββββββββββββββββββββββββββββββββββββββββββββββββββββ node_modules/graphql-iso-date/dist/time/index.js.flow:55:31
Cannot add 'Time canno...' + 'or non Dat...' and JSON.stringify(...) because undefined [1] is incompatible with
string [2].
node_modules/graphql-iso-date/dist/time/index.js.flow
51β )
52β } else {
53β throw new TypeError(
[2] 54β 'Time cannot be serialized from a non string, ' +
55β 'or non Date type ' + JSON.stringify(value)
56β )
57β }
58β },
/private/tmp/flow/flowlib_2a9f9c93/core.js
[1] 491β ): string | void;
Error ββββββββββββββββββββββββββββββββββββββββββββββββββββββ node_modules/graphql-iso-date/dist/time/index.js.flow:62:50
Cannot coerce JSON.stringify(...) to string because undefined [1] should not be coerced.
node_modules/graphql-iso-date/dist/time/index.js.flow
59β parseValue (value: mixed): Date {
60β if (!(typeof value === 'string' || value instanceof String)) {
61β throw new TypeError(
62β `Time cannot represent non string type ${JSON.stringify(value)}`
63β )
64β }
65β
/private/tmp/flow/flowlib_2a9f9c93/core.js
[1] 491β ): string | void;
Found 6 errors
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.