Skip to content

Commit

Permalink
Add "Timestamp" scalar type for convinience
Browse files Browse the repository at this point in the history
* rm unnecessary files
  • Loading branch information
piglovesyou committed Sep 22, 2018
1 parent d07020a commit 787bbed
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 53 deletions.
32 changes: 32 additions & 0 deletions src/data/graphql/Scalar/Timestamp/index.js
@@ -0,0 +1,32 @@
// @flow

import { GraphQLScalarType } from 'graphql';
import { Kind } from 'graphql/language';

export const schema = [
`
# GraphQL cannot handle long - normal timestamp will go failed.
# In that case, use Timestamp.
type Timestamp
`,
];

export const resolvers = {
Timestamp: new GraphQLScalarType({
name: 'Timestamp',
description: 'Timestamp custom scalar type',
parseValue(value) {
return value;
},
serialize(value) {
return value;
},
parseLiteral(ast) {
if (ast.kind === Kind.INT) {
return ast.value;
}
return null;
},
}),
};
10 changes: 10 additions & 0 deletions src/data/graphql/Scalar/schema.js
@@ -0,0 +1,10 @@
import merge from 'lodash.merge';

import {
schema as TimestampSchema,
resolvers as TimestampResolvers,
} from './Timestamp';

export const schema = [...TimestampSchema];

export const resolvers = merge(TimestampResolvers);
8 changes: 7 additions & 1 deletion src/data/schema.js
Expand Up @@ -22,6 +22,11 @@ import {
queries as DatabaseQueries,
} from './graphql/Database/schema';

import {
schema as TimestampSchema,
resolvers as TimestampResolvers,
} from './graphql/Scalar/Timestamp';

const RootQuery = [
`
# # React-Starter-Kit Querying API
Expand Down Expand Up @@ -68,10 +73,11 @@ const SchemaDefinition = [

// Merge all of the resolver objects together
// Put schema together into one array of schema strings
const resolvers = merge(NewsResolvers, DatabaseResolvers);
const resolvers = merge(NewsResolvers, DatabaseResolvers, TimestampResolvers);

const schema = [
...SchemaDefinition,
...TimestampSchema,
...RootQuery,
...Mutation,

Expand Down
27 changes: 0 additions & 27 deletions src/data/types/NewsItemType.js

This file was deleted.

25 changes: 0 additions & 25 deletions src/data/types/UserType.js

This file was deleted.

0 comments on commit 787bbed

Please sign in to comment.