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

feat: add setEndpoint method #80

Merged
merged 3 commits into from
Jul 30, 2023
Merged
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ const client = new AwesomeGraphQLClient(config)

- `client.setFetchOptions(fetchOptions: FetchOptions)`: Sets fetch options. See examples below
- `client.getFetchOptions()`: Returns current fetch options
- `client.getEnpoint(): string`: Returns current GraphQL endpoint
- `client.setEndpoint(): string`: Sets a new GraphQL endpoint
- `client.getEndpoint(): string`: Returns current GraphQL endpoint
- `client.request(query, variables?, fetchOptions?): Promise<data>`: Sends GraphQL Request and returns data or throws an error
- `client.requestSafe(query, variables?, fetchOptions?): Promise<{ data, response } | { error }>`: Sends GraphQL Request and returns object with 'ok: true', 'data' and 'response' or with 'ok: false' and 'error' fields. See examples below. _Notice: this function never throws_.

Expand Down
12 changes: 12 additions & 0 deletions packages/awesome-graphql-client/src/AwesomeGraphQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ export class AwesomeGraphQLClient<
return form
}


/**
* Sets a new GraphQL endpoint
*
* @param endpoint new overrides for endpoint
*/
setEndpoint(endpoint: string): void {
assert(endpoint !== undefined, 'endpoint is required')
this.endpoint = endpoint
}


/**
* Returns current GraphQL endpoint
*/
Expand Down