Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update defs to use Partial instead of deprecated $Shape #4438

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Large diffs are not rendered by default.

@@ -0,0 +1,119 @@
// @flow

import * as React from 'react';
import { it, describe } from 'flow-typed-test';
import {
ApolloProvider,
ApolloConsumer,
parser,
operationName,
type DocumentType,
type IDocumentDefinition
} from '@apollo/react-common';

const gql = (strings, ...args) => {}; // graphql-tag stub

const query = gql`
{
foo
}
`;
const mutation = gql`
mutation {
foo
}
`;

type Hero = {
name: string,
id: string,
appearsIn: string[],
friends: Hero[],
...
};

const HERO_QUERY = gql`
query GetCharacter($episode: String!, $offset: Int) {
hero(episode: $episode, offset: $offset) {
name
id
friends {
name
id
appearsIn
}
}
}
`;

describe('<ApolloProvider />', () => {
it('works when passed client', () => {
// $FlowExpectedError Should be an instance of ApolloClient
const client = {};
<ApolloProvider client={client}>
<div />
</ApolloProvider>;
});

it('raises an error when not passed a client', () => {
// $FlowExpectedError ApolloProvider requires client prop
<ApolloProvider>
<div />
</ApolloProvider>;
});

it('raises an error when not passed children', () => {
// Should be an instance of ApolloClient
const client = {};

// $FlowExpectedError ApolloProvider requires client prop
<ApolloProvider client={client} />;
});
});

describe('<ApolloConsumer />', () => {
it('passes ApolloClient to the consumer children', () => {
<ApolloConsumer>
{client => {
const onClick = () => {
client.resetStore();
client.query({ query: HERO_QUERY });
client.readQuery({
query: HERO_QUERY,
variables: { episode: 'episode' },
});
// $FlowExpectedError doSomethingElse is not a method of ApolloClient
client.doSomethingElse();
};
return <button onClick={onClick}>Click</button>;
}}
</ApolloConsumer>;
});
});

describe('parser', () => {
it('returns IDocumentDefinition', () => {
const document = {};

const result = parser({});

(result: IDocumentDefinition);
// $FlowExpectedError
(result: number);
})
})

describe('operationName', () => {
it('works', () => {
const result = operationName('Query');

(result: string);
// $FlowExpectedError
(result: number);
})

it('requires DocumentType', () => {
// $FlowExpectedError must be a DocumentType
const result = operationName('foo');
})
})