Skip to content

Commit

Permalink
fix(typescript): Only use data in return type for functions
Browse files Browse the repository at this point in the history
Fixes #50
  • Loading branch information
wolfy1339 committed Aug 23, 2019
1 parent c1fa150 commit 246bc4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { request as Request } from "@octokit/request";
import { GraphqlError } from "./error";
import { Endpoint, Parameters, GraphQlQueryResponse } from "./types";
import { Endpoint, Parameters, GraphQlQueryResponseData } from "./types";

const NON_VARIABLE_OPTIONS = [
"method",
Expand All @@ -15,7 +15,7 @@ export function graphql(
request: typeof Request,
query: string | Parameters,
options?: Parameters
): Promise<GraphQlQueryResponse> {
): Promise<GraphQlQueryResponseData> {
options =
typeof query === "string"
? (options = Object.assign({ query }, options))
Expand Down
10 changes: 7 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ export interface graphql {
*
* @param {object} endpoint Must set `method` and `url`. Plus URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
*/
(options: Parameters): Promise<GraphQlQueryResponse>;
(options: Parameters): Promise<GraphQlQueryResponseData>;

/**
* Sends a request based on endpoint options
*
* @param {string} route Request method + URL. Example: `'GET /orgs/:org'`
* @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
*/
(query: Query, parameters?: Parameters): Promise<GraphQlQueryResponse>;
(query: Query, parameters?: Parameters): Promise<GraphQlQueryResponseData>;

/**
* Returns a new `endpoint` with updated route and parameters
Expand All @@ -30,8 +30,12 @@ export interface graphql {
endpoint: typeof request.endpoint;
}

export type GraphQlQueryResponseData = {
[key: string]: any;
} | null;

export type GraphQlQueryResponse = {
data: { [key: string]: any } | null;
data: GraphQlQueryResponseData;
errors?: [
{
message: string;
Expand Down

0 comments on commit 246bc4f

Please sign in to comment.