UNPKG

1.36 kBJavaScriptView Raw
1/**
2 @namespace GQLInterface
3 @flow
4 */
5
6import { GQLBase } from './GQLBase'
7import { GraphQLInterfaceType } from 'graphql'
8
9/**
10 * Used by Lattice to implement interface types in the schema when necessary
11 *
12 * @class GQLInterface
13 */
14export class GQLInterface extends GQLBase {
15
16 /**
17 * This needs to be able to, depending on your implementors, identify
18 * which on the data actually is given the model to work with.
19 *
20 * @memberof GQLInterface
21 * @method ⌾⠀resolveType
22 * @static
23 *
24 * @param {mixed} model the data you can use to instantiate the type of
25 * object in question.
26 * @return {string} a string matching the name of a defined GraphQL type
27 * found elsewhere in your schema
28 */
29 static resolveType(model: mixed): string {
30 throw new Error(`
31 You must override "resolveType(model)" in your GQLInterface instance
32 and determine the implementor type by the contents of the supplied
33 model. Returning "null" when nothing matches.
34 `);
35 }
36
37 /**
38 * Denotes that this GQLBase descendent is describing a graphql
39 * interface type.
40 *
41 * @memberof GQLInterface
42 * @method ⬇︎⠀GQL_TYPE
43 * @static
44 * @const
45 *
46 * @return {Function} a type, such as `GraphQLObjectType` or
47 * `GraphQLInterfaceType`
48 */
49 static get GQL_TYPE(): Function {
50 return GraphQLInterfaceType;
51 }
52}