Skip to content

Commit

Permalink
Ignore scalar resolver
Browse files Browse the repository at this point in the history
Signed-off-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
  • Loading branch information
ardatan committed Dec 11, 2018
1 parent d74cc12 commit 76f0fc4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/core/src/graphql-module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IResolvers, makeExecutableSchema, SchemaDirectiveVisitor, ILogger, mergeSchemas, IDirectiveResolvers, IResolverValidationOptions } from 'graphql-tools';
import { mergeGraphQLSchemas, mergeResolvers } from '@graphql-modules/epoxy';
import { Provider, Injector, ProviderScope } from '@graphql-modules/di';
import { DocumentNode, GraphQLSchema, parse } from 'graphql';
import { DocumentNode, GraphQLSchema, parse, GraphQLScalarType } from 'graphql';
import { IResolversComposerMapping, composeResolvers } from './resolvers-composition';
import { DepGraph } from 'dependency-graph';
import { DependencyModuleNotFoundError, SchemaNotValidError, DependencyModuleUndefinedError, TypeDefNotFoundError, ModuleConfigRequiredError, IllegalResolverInvocationError } from './errors';
Expand Down Expand Up @@ -399,6 +399,9 @@ export class GraphQLModule<Config = any, Request = any, Context = any> {
// tslint:disable-next-line:forin
for (const type in resolvers) {
const typeResolvers = resolvers[type];
if (typeResolvers instanceof GraphQLScalarType) {
continue;
}
// tslint:disable-next-line:forin
for (const prop in resolvers[type]) {
const resolver = typeResolvers[prop];
Expand Down
41 changes: 40 additions & 1 deletion packages/core/tests/graphql-module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
OnRequest,
ModuleConfigRequiredError,
} from '../src';
import { execute, GraphQLSchema, printSchema, GraphQLString, defaultFieldResolver, print } from 'graphql';
import { execute, GraphQLSchema, printSchema, GraphQLString, defaultFieldResolver, print, GraphQLScalarType, Kind } from 'graphql';
import { stripWhitespaces } from './utils';
import gql from 'graphql-tag';
import { SchemaDirectiveVisitor, makeExecutableSchema } from 'graphql-tools';
Expand Down Expand Up @@ -1008,4 +1008,43 @@ describe('GraphQLModule', () => {
const resolvers = gqlModule.resolvers;
expect(await resolvers['Query']['test'](null, {}, context, {})).toBe(1);
});
it('should resolve scalars correctly', async () => {
const today = new Date();
const { schema, context } = new GraphQLModule({
typeDefs: gql`
scalar Date
type Query {
today: Date
}
`,
resolvers: {
Date: new GraphQLScalarType({
name: 'Date',
description: 'Date custom scalar type',
parseValue(value) {
return new Date(value); // value from the client
},
serialize(value) {
return value.getTime(); // value sent to the client
},
parseLiteral(ast) {
if (ast.kind === Kind.INT) {
return new Date(ast.value); // ast value is always in string format
}
return null;
},
}),
Query: {
today: () => today,
},
},
});
const result = await execute({
schema,
document: gql`query { today }`,
contextValue: await context({ req: {} }),
});
expect(result.errors).toBeFalsy();
expect(result.data['today']).toBe(today.getTime());
});
});

0 comments on commit 76f0fc4

Please sign in to comment.