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

fix: set defaults on .endpoint #410

Merged
merged 4 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/with-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export function withDefaults(

return Object.assign(newApi, {
defaults: withDefaults.bind(null, newRequest),
endpoint: Request.endpoint,
endpoint: newRequest.endpoint,
});
}
57 changes: 57 additions & 0 deletions test/defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,61 @@ describe("graphql.defaults()", () => {
}
}`);
});

it("set defaults on .endpoint", () => {
const mockData = {
repository: {
issues: {
edges: [
{
node: {
title: "Foo",
},
},
{
node: {
title: "Bar",
},
},
{
node: {
title: "Baz",
},
},
],
},
},
};

const authenticatedGraphql = graphql.defaults({
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock.sandbox().post(
"https://github.acme-inc.com/api/graphql",
{ data: mockData },
{
headers: {
authorization: "token secret123",
},
}
),
},
});

const { request: _request, ...requestOptions } =
// @ts-expect-error - TODO: expets to set { url } but it really shouldn't
gr2m marked this conversation as resolved.
Show resolved Hide resolved
authenticatedGraphql.endpoint();
expect(requestOptions).toStrictEqual({
method: "POST",
url: "https://api.github.com/graphql",
headers: {
accept: "application/vnd.github.v3+json",
authorization: "token secret123",
"user-agent":
"octokit-graphql.js/0.0.0-development Node.js/18.9.0 (darwin; arm64)",
},
});
});
});