graphql-compose-relay
Version:
Plugin for `graphql-compose` which wraps graphql types with Relay specific logic.
69 lines (63 loc) • 2.19 kB
JavaScript
;
var _graphqlCompose = require("graphql-compose");
var _userTC = require("../__mocks__/userTC");
var _globalId = require("../globalId");
var _nodeFieldConfig = require("../nodeFieldConfig");
var _nodeInterface = require("../nodeInterface");
describe('nodeFieldConfig', () => {
const typeToFindByIdMap = {
User: {
resolver: _userTC.findByIdResolver,
tc: _userTC.userTC
}
};
const config = (0, _nodeFieldConfig.getNodeFieldConfig)(typeToFindByIdMap, (0, _nodeInterface.getNodeInterface)(_graphqlCompose.schemaComposer));
it('should have type GraphQLInterfaceType', () => {
expect(config).toBeTruthy();
expect(config.type).toBeInstanceOf(_graphqlCompose.InterfaceTypeComposer);
expect(config.type.getTypeName()).toBe('Node');
});
it('should have args with id', () => {
expect(config.args.id.type).toBe('ID!');
});
it('should have resolve function', () => {
expect(config.resolve).toBeDefined();
expect(config.resolve.call).toBeDefined();
expect(config.resolve.apply).toBeDefined();
});
it('should return null if args.id not defined', () => {
const source = {};
const args = {};
const context = {};
const info = {};
expect(config.resolve(source, args, context, info)).toBeNull();
});
it('should return null if findById not defined for type', () => {
const source = {};
const args = {
id: (0, _globalId.toGlobalId)('UnexistedType', 1)
};
const context = {};
const info = {};
expect(config.resolve(source, args, context, info)).toBeNull();
});
it('should return Promise if type exists, but id not exist', () => {
const source = {};
const args = {
id: (0, _globalId.toGlobalId)('User', 666)
};
const context = {};
const info = {};
expect(config.resolve(source, args, context, info)).toBeInstanceOf(Promise);
});
it('should return Promise with user data', async () => {
const source = {};
const args = {
id: (0, _globalId.toGlobalId)('User', 1)
};
const context = {};
const info = {};
const res = await config.resolve(source, args, context, info);
expect(res.name).toBe('Pavel');
});
});