Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Reduce size impact of populateExchange #122

Merged
merged 11 commits into from
Dec 8, 2019
7 changes: 5 additions & 2 deletions docs/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,14 @@ field somewhere, maybe due to a typo.

## (18) Invalid TypeInfo state <a id="18"></a>

> Invalid TypeInfo state: Found an abstract type when none was expected.
> Invalid TypeInfo state: Found no flat schema type when one was expected.

When you're using the populate exchange with an introspected schema, it will
start collecting used fragments and selection sets on all of your queries.
This error may occur if it hits unexpected abstract types when doing so.
This error may occur if it hits unexpected types or inexistent types when doing so.

Check whether your schema is up-to-date or whether you're using an invalid
field somewhere, maybe due to a typo.

Please open an issue if it happens on a query that you expect to be supported
by the `populateExchange`.
13 changes: 12 additions & 1 deletion src/ast/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import {
InlineFragmentNode,
FieldNode,
FragmentDefinitionNode,
GraphQLOutputType,
Kind,
isListType,
isNonNullType,
} from 'graphql';

import { SelectionSet } from '../types';
import { SelectionSet, GraphQLFlatType } from '../types';

/** Returns the name of a given node */
export const getName = (node: { name: NameNode }): string => node.name.value;
Expand Down Expand Up @@ -40,3 +43,11 @@ export const isFieldNode = (node: SelectionNode): node is FieldNode =>
export const isInlineFragment = (
node: SelectionNode
): node is InlineFragmentNode => node.kind === Kind.INLINE_FRAGMENT;

export const unwrapType = (
kitten marked this conversation as resolved.
Show resolved Hide resolved
type: null | undefined | GraphQLOutputType
): GraphQLFlatType | null => {
return type && (isListType(type) || isNonNullType(type))
? type.ofType
: type || null;
};
3 changes: 2 additions & 1 deletion src/cacheExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CacheOutcome,
} from 'urql';

import { IntrospectionQuery } from 'graphql';
import { filter, map, merge, pipe, share, tap } from 'wonka';
import { query, write, writeOptimistic } from './operations';
import { SchemaPredicates } from './ast/schemaPredicates';
Expand Down Expand Up @@ -85,7 +86,7 @@ export interface CacheExchangeOpts {
resolvers?: ResolverConfig;
optimistic?: OptimisticMutationConfig;
keys?: KeyingConfig;
schema?: object;
schema?: IntrospectionQuery;
}

export const cacheExchange = (opts?: CacheExchangeOpts): Exchange => ({
Expand Down
File renamed without changes.
Loading