|
| 1 | +/** |
| 2 | + * Copyright (c) 2015, Facebook, Inc. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | + * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | + */ |
| 9 | + |
| 10 | +import { |
| 11 | + GraphQLSchema, |
| 12 | + GraphQLInterfaceType, |
| 13 | + GraphQLObjectType, |
| 14 | + GraphQLString |
| 15 | +} from '../'; |
| 16 | + |
| 17 | +import { describe, it } from 'mocha'; |
| 18 | +import { expect } from 'chai'; |
| 19 | + |
| 20 | +const InterfaceType = new GraphQLInterfaceType({ |
| 21 | + name : 'Interface', |
| 22 | + fields : { fieldName : { type : GraphQLString } }, |
| 23 | + resolveType() { |
| 24 | + return ImplementingType; |
| 25 | + } |
| 26 | +}); |
| 27 | + |
| 28 | +const ImplementingType = new GraphQLObjectType({ |
| 29 | + name : 'Object', |
| 30 | + interfaces : [InterfaceType], |
| 31 | + fields : { fieldName : { type: GraphQLString, resolve: () => '' }} |
| 32 | +}); |
| 33 | + |
| 34 | +const Schema = new GraphQLSchema({ |
| 35 | + query: new GraphQLObjectType({ |
| 36 | + name: 'Query', |
| 37 | + fields : { |
| 38 | + getObject : { |
| 39 | + type : InterfaceType, |
| 40 | + resolve() { |
| 41 | + return {}; |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + }) |
| 46 | +}); |
| 47 | + |
| 48 | +describe('Type System: Schema', () => { |
| 49 | + describe('Getting possible types', () => { |
| 50 | + it('throws human-reable error if schema.types is not defined', () => { |
| 51 | + const checkPossible = () => { |
| 52 | + return Schema.isPossibleType(InterfaceType, ImplementingType); |
| 53 | + }; |
| 54 | + expect(checkPossible).to.throw( |
| 55 | + 'Could not find possible implementing types for Interface in schema. ' + |
| 56 | + 'Check that schema.types is defined and is an array ofall possible ' + |
| 57 | + 'types in the schema.' |
| 58 | + ); |
| 59 | + }); |
| 60 | + }); |
| 61 | +}); |
0 commit comments