-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(package): update graphql-js to latest
- Loading branch information
1 parent
b5b670a
commit 0cef077
Showing
7 changed files
with
74 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { GraphQLScalarType } from 'graphql'; | ||
import { GraphQLError } from 'graphql/error' | ||
import { Kind } from 'graphql/language' | ||
|
||
export default new GraphQLScalarType({ | ||
name: 'Date', | ||
serialize(value) { | ||
if (!(value instanceof Date)) { | ||
throw new Error("Field error: value is not an instance of Date") | ||
} | ||
if (isNaN(value.getTime())) { | ||
throw new Error("Field error: value is an invalid Date") | ||
} | ||
return value.toJSON() | ||
}, | ||
parseValue(value) { | ||
this.serialize(value); | ||
}, | ||
parseLiteral(ast) { | ||
if (ast.kind !== Kind.STRING ) { | ||
throw new GraphQLError("Query error: Can only parse strings to dates but got a: " + ast.kind, [ast]) | ||
} | ||
let result = new Date(ast.value); | ||
if (isNaN(result.getTime())) { | ||
throw new GraphQLError("Query error: Invalid date", [ast]) | ||
} | ||
if (ast.value != result.toJSON()) { | ||
throw new GraphQLError("Query error: Invalid date format, only accepts: YYYY-MM-DDTHH:MM:SS.SSSZ", [ast]) | ||
} | ||
return result | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters