Skip to content

Instantly share code, notes, and snippets.

@bogoslavskiy
Created March 5, 2020 15:07
Show Gist options
  • Save bogoslavskiy/9ba7a870dd3d8e7ac2d8c53ed46c9aa6 to your computer and use it in GitHub Desktop.
Save bogoslavskiy/9ba7a870dd3d8e7ac2d8c53ed46c9aa6 to your computer and use it in GitHub Desktop.
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