Skip to content

Commit

Permalink
feat(scalars): add date scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
bikov committed May 21, 2019
1 parent 3f6f0d4 commit 7bed910
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ const {CommonEntities: {commonEntityInterface, upperCaseDirective}} = require('@
const Book = `
type Book implements CommonEntity {
id: ID!
creationDate: String,
lastUpdateDate: String,
creationDate: Date,
lastUpdateDate: Date,
dataVersion: Int!,
title: String @upper,
author: String
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@
"@enigmatis/utills": "^1.3.1",
"@types/graphql": "^14.2.0",
"@types/graphql-fields": "^1.3.0",
"@types/graphql-iso-date": "^3.3.1",
"@types/koa-router": "^7.0.40",
"@types/node": "10.12.12",
"apollo-server-core": "^2.4.8",
"graphql": "^14.2.1",
"graphql-extensions": "^0.5.7",
"graphql-fields": "^2.0.3",
"graphql-iso-date": "^3.6.1",
"graphql-middleware": "^3.0.1",
"graphql-tools": "^4.0.4",
"inversify": "^5.0.1",
Expand Down
4 changes: 2 additions & 2 deletions src/schema/common/common-entity-interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const CommonEntityInterface = `interface CommonEntity {
id: ID!
creationDate: String,
lastUpdateDate: String,
creationDate: Date,
lastUpdateDate: Date,
dataVersion: Int!
}`;
7 changes: 7 additions & 0 deletions src/schema/common/date.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { gql } from 'apollo-server-core';
import { GraphQLDateTime } from 'graphql-iso-date';

export const dateSchema = gql`
scalar Date
`;
export const dateResolver = { Date: GraphQLDateTime };
14 changes: 9 additions & 5 deletions src/schema/utils/polaris-schema-creator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { buildSchema, GraphQLSchema } from 'graphql';
import { IExecutableSchemaDefinition, makeExecutableSchema } from 'graphql-tools';
import { mergeTypes } from 'merge-graphql-schemas';
import { mergeResolvers, mergeTypes } from 'merge-graphql-schemas';
import { CommonEntityInterface } from '../common/common-entity-interface';
import { dateResolver, dateSchema } from '../common/date';

export function makeExecutablePolarisSchema<TContext = any>({
typeDefs,
Expand All @@ -15,12 +16,15 @@ export function makeExecutablePolarisSchema<TContext = any>({
parseOptions,
inheritResolversFromInterfaces,
}: IExecutableSchemaDefinition<TContext>): GraphQLSchema {
const typeDefsWithCommonEntity = mergeTypes([...(typeDefs as []), CommonEntityInterface], {
all: true,
});
const typeDefsWithCommonEntity = mergeTypes(
[CommonEntityInterface, dateSchema, ...(typeDefs as [])],
{
all: true,
},
);
return makeExecutableSchema({
typeDefs: typeDefsWithCommonEntity,
resolvers,
resolvers: mergeResolvers([dateResolver, ...(resolvers as [])]), // resolvers,
connectors,
logger,
allowUndefinedInResolve,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const Book = `type Book implements CommonEntity {
id: ID!
creationDate: String,
lastUpdateDate: String,
creationDate: Date,
lastUpdateDate: Date,
dataVersion: Int!,
title: String,
author: String,
Expand Down

0 comments on commit 7bed910

Please sign in to comment.