Created
March 5, 2020 15:07
-
-
Save bogoslavskiy/9ba7a870dd3d8e7ac2d8c53ed46c9aa6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { GraphQLScalarType } from 'graphql'; | |
import { Kind, ValueNode } from 'graphql/language'; | |
import { gql } from 'apollo-server'; | |
const parse = (v: string) => { | |
if (v === undefined || v === null) { | |
throw new Error('field should be String'); | |
} | |
return v; | |
}; | |
const literal = (ast: ValueNode) => { | |
if (ast.kind === Kind.INT) { | |
return parse(ast.value); | |
} | |
throw new Error('field should be String'); | |
}; | |
export default { | |
declaration: gql` | |
scalar Timestamp | |
`, | |
type: { | |
Timestamp: new GraphQLScalarType({ | |
name: 'Timestamp', | |
description: 'Timestamp format', | |
serialize: parse, | |
parseValue: parse, | |
parseLiteral: literal | |
}), | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment