UNPKG

charlotte-graphql

Version:

Generates GraphQL type definitions and resolvers off of a concise spec.

61 lines (54 loc) 1.71 kB
'use strict'; const { strictEqual } = require('assert'); const { expandTypes } = require('../lib/helpers'); describe('Type expansion...', () => { describe('given type "TopicRelation" with two sibling fields of type "Topic"', () => { describe('called "from" and "to"', () => { it('should create reciprocal fields on "Topic" called "topicRelationsTo" and "topicRelationsFrom"', () => { const { Topic: { fields: { topicRelationsTo, topicRelationsFrom } }, TopicRelation } = expandTypes({ Topic: { name: 'String!' }, TopicRelation: { from: 'Topic!', to: 'Topic!' } }); strictEqual(!!topicRelationsTo && !!topicRelationsFrom, true); strictEqual(topicRelationsTo.type.name, TopicRelation.name); strictEqual(topicRelationsFrom.type.name, TopicRelation.name); }); }); describe('called "topic1" and "topic2"', () => { const { Topic: { fields: { topicRelations } } } = expandTypes({ Topic: { name: 'String!' }, TopicRelation: { topic1: 'Topic!', topic2: 'Topic!' } }); it('should create a reciprocal field on "Topic" called "topicRelations"', () => { strictEqual(!!topicRelations, true); }); it('should contain the combined fields in "reciprocalOf" property on "topicRelations" field', () => { strictEqual(topicRelations.reciprocalOf.map(f => f.name).sort().join(' '), 'topic1 topic2'); }); }); }); });