···272272273273This may either happen because you're missing the `__typename` and `id` or `_id` field or if the last two
274274aren't applicable to this entity a custom `keys` entry.
275275+276276+## (20) Invalid Object type <a id="20"></a>
277277+278278+> Invalid Object type: The type `???` is not an object in the defined schema,
279279+> but the `keys` option is referencing it.
280280+281281+When you're passing an introspected schema to the cache exchange, it is
282282+able to check whether your `opts.keys` is valid.
283283+This error occurs when an unknown type is found in `opts.keys`.
284284+285285+Check whether your schema is up-to-date, or whether you're using an invalid
286286+typename in `opts.keys`, maybe due to a typo.
···11import { buildClientSchema } from 'graphql';
22+import { mocked } from 'ts-jest/utils';
23import * as SchemaPredicates from './schemaPredicates';
3445describe('SchemaPredicates', () => {
···5253 expect(
5354 SchemaPredicates.isInterfaceOfType(schema, 'Todo', 'NoTodosError')
5455 ).toBeFalsy();
5656+ });
5757+5858+ it('should throw if a requested type does not exist', () => {
5959+ expect(() =>
6060+ SchemaPredicates.isFieldNullable(schema, 'SomeInvalidType', 'complete')
6161+ ).toThrow(
6262+ 'The type `SomeInvalidType` is not an object in the defined schema, but the GraphQL document is traversing it.\nhttps://bit.ly/2XbVrpR#3'
6363+ );
6464+ });
6565+6666+ it('should warn in console if a requested field does not exist', () => {
6767+ expect(
6868+ SchemaPredicates.isFieldNullable(schema, 'Todo', 'goof')
6969+ ).toBeFalsy();
7070+7171+ expect(console.warn).toBeCalledTimes(1);
7272+ const warnMessage = mocked(console.warn).mock.calls[0][0];
7373+ expect(warnMessage).toContain('The field `goof` does not exist on `Todo`');
7474+ expect(warnMessage).toContain('https://bit.ly/2XbVrpR#4');
5575 });
5676});
+20
exchanges/graphcache/src/ast/schemaPredicates.ts
···1010} from 'graphql';
11111212import { warn, invariant } from '../helpers/help';
1313+import { KeyingConfig } from '../types';
13141415export const isFieldNullable = (
1516 schema: GraphQLSchema,
···111112 5
112113 );
113114}
115115+116116+export function expectValidKeyingConfig(
117117+ schema: GraphQLSchema,
118118+ keys: KeyingConfig
119119+): void {
120120+ if (process.env.NODE_ENV !== 'production') {
121121+ const types = Object.keys(schema.getTypeMap());
122122+ Object.keys(keys).forEach(key => {
123123+ if (types.indexOf(key) === -1) {
124124+ warn(
125125+ 'Invalid Object type: The type `' +
126126+ key +
127127+ '` is not an object in the defined schema, but the `keys` option is referencing it.',
128128+ 20
129129+ );
130130+ }
131131+ });
132132+ }
133133+}