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

Added lib defs for apollo-link-http@1.2.x #1552

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
declare module "apollo-link-http" {
declare export interface FetchOptions {
uri?: string;
//todo change to type of Global['fetch']
fetch?: any;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is Global['fetch']? What is the type of Global['fetch']? (This is how the value is assigned in the source.)

Is it OK to use any here? Or mixed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any is fine, as it matches the ts definition.

includeExtensions?: boolean;
credentials?: string;
headers?: any;
fetchOptions?: any;
Copy link
Author

@ctgardner ctgardner Nov 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should mixed be used here instead (for both headers and fetchOptions)?

Copy link
Member

@gantoine gantoine Dec 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any is fine, as it matches the ts definition.

}

//todo change return type to ApolloLink from 'apollo-link'
declare export function createHttpLink(opts: FetchOptions): any;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite the name, the createHttpLink function seems to return an ApolloLink which is from the apollo-link package. What is the appropriate way to declare this? (Keep in mind, apollo-link might not have lib defs either.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in my last comment: #1552 (discussion comment)


declare export class HttpLink {
//todo change type to RequestHandler from 'apollo-link'
requester: any;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of requester is RequestHandler from the apollo-link package. What is the appropriate way to declare this? (Keep in mind, apollo-link might not have lib defs either.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependencies between libdefs will probably been handled in the coming 3.0 release, which is currently discussed in #1494.

For now I think it's best to just duplicate the RequestHandler inside this libdef (like it's done in react-router-dom & react-router-native for the duplicate types from react-router) and add a // TODO: to delete this in the future when dependencies between libdefs are handled.

constructor(opts: FetchOptions): HttpLink;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// @flow
import { createHttpLink, HttpLink } from "apollo-link-http";
import type { FetchOptions } from "apollo-link-http";

const options: FetchOptions = {};

// $ExpectError
options.uri = 123;
options.uri = "/uri";

//todo test options.fetch

// $ExpectError
options.includeExtensions = "false";
options.includeExtensions = false;

// $ExpectError
options.credentials = 123;
options.credentials = "credentials";

// $ExpectError
options.foobar = "foobar";

//todo change type to ApolloLink from 'apollo-link'
let apolloLink: any;
// $ExpectError
apolloLink = createHttpLink({ uri: 123 });
apolloLink = createHttpLink(options);

let httpLink: HttpLink;
// $ExpectError
httpLink = new HttpLink({ uri: 123 });
httpLink = new HttpLink(options);

//todo change type to RequestHandler from 'apollo-link'
const requester: any = httpLink.requester;