title: GraphQL.js - use Interface as a default (fallback) type in resolveType function
body: <p>I'm trying to return generic type in <code>resolveType</code> function if none of the provided types is matched. The example below shows this problem: API worked like a charm supporting <code>UserType</code> and <code>MovieType</code> until in database was added <code>BookType</code> (not supported by GraphQL schema).</p>
  
  <pre><code>const {
    graphql,
    GraphQLSchema,
    GraphQLObjectType,
    GraphQLString,
    GraphQLNonNull,
    GraphQLList,
    GraphQLInterfaceType
  } = require("graphql");
  
  const DATA = [
    {
      // UserType
      name: "catherine woolf",
      nick: "catherine"
    },
    {
      // MovieType
      name: "cat woman",
      director: "Jack Wolfgang"
    },
    {
      // --- missing type --- (BookType)
      name: "cats secrets",
      author: "Nicky Glace"
    }
  ];
  
  const resolveType = data =&gt; {
    if (data.nick) {
      return UserType;
    }
    if (data.director) {
      return MovieType;
    }
  };
  
  const SearchableType = new GraphQLInterfaceType({
    name: "Searchable",
    fields: {
      name: { type: GraphQLString }
    },
    resolveType: resolveType
  });
  
  const UserType = new GraphQLObjectType({
    name: "User",
    interfaces: [SearchableType],
    fields: {
      name: { type: GraphQLString },
      nick: { type: GraphQLString }
    }
  });
  
  const MovieType = new GraphQLObjectType({
    name: "Movie",
    interfaces: [SearchableType],
    fields: {
      name: { type: GraphQLString },
      director: { type: GraphQLString }
    }
  });
  
  const schema = new GraphQLSchema({
    types: [MovieType, UserType, SearchableType],
    query: new GraphQLObjectType({
      name: "RootQueryType",
      fields: {
        search: {
          type: new GraphQLList(SearchableType),
          args: {
            text: { type: new GraphQLNonNull(GraphQLString) }
          },
          resolve(_, { text }) {
            return DATA.filter(d =&gt; d.name.indexOf(text) !== -1);
          }
        }
      }
    })
  });
  
  const query = `
    {
      search(text: "cat") {
        name
        ... on User {
          nick
        }
        ... on Movie {
          director
        }
      }
    }
  `;
  
  graphql(schema, query).then(result =&gt; {
    console.log(JSON.stringify(result, null, 2));
  });
  </code></pre>
  
  <p>So now this code ends with error:</p>
  
  <blockquote>
    <p>"Abstract type Searchable must resolve to an Object type at runtime for field RootQueryType.search with value \"[object Object]\", received \"undefined\". Either the Searchable type should provide a \"resolveType\" function or each possible types should provide an \"isTypeOf\" function."</p>
  </blockquote>
  
  <p>This is nothing surprising since currently <code>resolveType</code> may not return any type.</p>
  
  <h2>Workaround</h2>
  
  <p>Crate type containing the same field like interface <code>SearchableType</code> (1 to 1 implementation):</p>
  
  <pre><code>const _SearchableType = new GraphQLObjectType({
    name: '_Searchable',
    interfaces: [SearchableType],
    fields: {
      name: { type: GraphQLString },
    }
  });
  </code></pre>
  
  <p>Use it as a fallback type: </p>
  
  <pre><code>const resolveType = data =&gt; {
    if (data.nick) {
      return UserType;
    }
    if (data.director) {
      return MovieType;
    }
    return _SearchableType;
  };
  </code></pre>
  
  <p>And add it to <code>types</code> in <code>schema</code> definition:</p>
  
  <pre><code>types: [MovieType, UserType, SearchableType, _SearchableType],
  </code></pre>
  
  <p>But the problem with this solution is presence of this dummy <code>_SearchableType</code> in documentation like this:</p>
  
  <p><a href="https://i.stack.imgur.com/zJAPq.png" rel="noreferrer"><img src="https://i.stack.imgur.com/zJAPq.png" alt="problematic _SearchableType in docs"></a></p>
  
  <h2>Question</h2>
  
  <p>Is there any way to return interface <code>SearchableType</code> or equivalent of it in <code>resolveType</code>? The key point for me is hiding of this "fallback type" in a documentation.</p>