Skip to content

Field in type IntrospectionResultData defined incorrectly #2959

Closed
@dotansimha

Description

@dotansimha

in TypeScript >=2.7 (since this PR), the definition of type[] and [type] are different.
[type] also enforces a length of 1 for the array, while type[] just enforces the Array type without length.

Related to this PR: (fixed the inner array)
#1763

Actual outcome:
Field types in IntrospectionResultData defined as:

export type IntrospectionResultData = {
  __schema: {
    types: [{
      kind: string;
      name: string;
      possibleTypes: {
        name: string;
      }[];
    }];
  };
};

Intended outcome:

It should be:

export type IntrospectionResultData = {
  __schema: {
    types: {
      kind: string;
      name: string;
      possibleTypes: {
        name: string;
      }[];
    }[];
  };
};

How to reproduce the issue:
Use typescript@2.7.1 and define IntrospectionResultData with more than one type, for example:

const cache = new InMemoryCache({
  fragmentMatcher: new IntrospectionFragmentMatcher({
    introspectionQueryResultData: {
      __schema: {
        types: [{
            kind: 'UNION',
            name: 'A',
            possibleTypes: [
              { name: 'AA' },
              { name: 'AB' },
            ]
          }, {
            kind: 'UNION',
            name: 'B',
            possibleTypes: [
              { name: 'BA' },
              { name: 'BB' }
            ]
          },
        ]
      },
    }
  }),
});

As a temporary workaround, it's possible to add as any to the types array value.

Version

  • apollo-client@2.2.2
  • apollo-cache-inmemory@1.17

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions