forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add type definitions for graphqurl by @hasura
Type definitions by Peter Boyer as per hasura/graphqurl#55
- Loading branch information
1 parent
7c69555
commit 23395cf
Showing
4 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createClient } from 'graphqurl'; | ||
|
||
// $ExpectType Client | ||
createClient({ | ||
endpoint: 'https://my-graphql-endpoint/graphql', | ||
headers: { | ||
Authorization: 'Bearer <token>' | ||
}, | ||
websocket: { | ||
endpoint: 'https://my-graphql-endpoint/graphql', | ||
shouldRetry: false, | ||
parameters: { someData: 'abc123' }, | ||
onConnectionSuccess: () => { }, | ||
onConnectionError: err => { }, | ||
onConnectionKeepAlive: () => { } | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// Type definitions for graphqurl 1.0 | ||
// Project: https://github.com/hasura/graphqurl | ||
// Definitions by: Peter Boyer <https://github.com/ptboyer/> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
||
export function createClient(options: Options): Client; | ||
|
||
export interface Client { | ||
query: ( | ||
queryOptions: QueryOptions, | ||
successCallback?: (response: Response) => void, | ||
errorCallback?: (error: any) => void, | ||
) => Promise<Response>; | ||
subscribe: ( | ||
subscriptionOptions: SubscriptionOptions, | ||
eventCallback?: (response: Response) => void, | ||
errorCallback?: (error: any) => void, | ||
) => Disposer; | ||
} | ||
|
||
export interface Options { | ||
/** | ||
* GraphQL endpoint | ||
*/ | ||
endpoint: string; | ||
|
||
/** | ||
* Request header, defaults to {}. These headers will be added along with | ||
* all the GraphQL queries, mutations and subscriptions made through the | ||
* client. | ||
*/ | ||
headers?: Record<string, string>; | ||
|
||
/** | ||
* Options for configuring subscriptions over websocket. Subscriptions are | ||
* not supported if this field is empty. | ||
*/ | ||
websocket?: { | ||
/** | ||
* WebSocket endpoint to run GraphQL subscriptions. | ||
*/ | ||
endpoint?: string; | ||
|
||
/** | ||
* Boolean value whether to retry closed websocket connection. Defaults to | ||
* false. | ||
*/ | ||
shouldRetry?: boolean; | ||
|
||
/** | ||
* Payload to send the connection init message with | ||
*/ | ||
parameters?: Record<string, any>; | ||
|
||
/** | ||
* Callback function called when the GraphQL connection is successful. | ||
* Please not that this is different from the websocket connection being | ||
* open. | ||
*/ | ||
onConnectionSuccess?: () => void; | ||
|
||
/** | ||
* Callback function called if the GraphQL connection over websocket is | ||
* unsuccessful | ||
*/ | ||
onConnectionError?: (error: any) => void; | ||
|
||
/** | ||
* Callback function called when the GraphQL server sends | ||
* GRAPHQL_CONNECTION_KEEP_ALIVE messages to keep the connection alive. | ||
*/ | ||
onConnectionKeepAlive?: () => void; | ||
}; | ||
} | ||
|
||
export interface QueryOptions { | ||
/** | ||
* The GraphQL query or mutation to be executed over HTTP | ||
*/ | ||
query: string; | ||
|
||
/** | ||
* GraphQL query variables. Defaults to {} | ||
*/ | ||
variables?: Record<string, any>; | ||
|
||
/** | ||
* Header overrides. If you wish to make a GraphQL query while adding to or | ||
* overriding the headers provided during initalisations, you can pass the | ||
* headers here. | ||
*/ | ||
headers?: Record<string, string>; | ||
} | ||
|
||
export interface SubscriptionOptions { | ||
/** | ||
* The GraphQL subscription to be started over WebSocket | ||
*/ | ||
subscription: string; | ||
|
||
/** | ||
* GraphQL query variables. Defaults to {} | ||
*/ | ||
variables?: Record<string, any>; | ||
|
||
/** | ||
* You can optionally pass this function as an event callback | ||
*/ | ||
onGraphQLData?: (response: Response) => void; | ||
|
||
/** | ||
* You can optionally pass this function as an error callback | ||
*/ | ||
onGraphQLError?: (error: any) => void; | ||
|
||
/** | ||
* Callback function called when the GraphQL subscription is declared as | ||
* complete by the server and no more events will be received | ||
*/ | ||
onGraphQLComplete?: () => void; | ||
} | ||
|
||
export interface Response { | ||
data: any; | ||
loading: boolean; | ||
networkStatus: number; | ||
stale: boolean; | ||
} | ||
|
||
export interface Disposer { | ||
(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": [ | ||
"es6" | ||
], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictFunctionTypes": true, | ||
"strictNullChecks": true, | ||
"baseUrl": "../", | ||
"typeRoots": [ | ||
"../" | ||
], | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.d.ts", | ||
"graphqurl-tests.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": "dtslint/dt.json" } |