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

add option to change endpoint #78

Closed
robin-siegl opened this issue Jun 20, 2023 · 2 comments · Fixed by #80
Closed

add option to change endpoint #78

robin-siegl opened this issue Jun 20, 2023 · 2 comments · Fixed by #80
Assignees

Comments

@robin-siegl
Copy link

Is your feature request related to a problem? Please describe.
Would be helpful if we can set the endpoint like the fetchOptions.

Describe the solution you'd like
add the possibility to set the endpoint like this client.setEndpoint(string).

Describe alternatives you've considered
NA

Additional context
NA

@lynxtaa
Copy link
Owner

lynxtaa commented Jun 23, 2023

I'm a bit confused on why this is needed. The expected usage is creating a new GraphQL client for every endpoint. Changing the endpoint may have some unfortunate side effects (ex. providing HttpAgent for node-fetch in fetchOptions, then changing an endpoint to HTTPS). Could you please explain a little bit more about your use case scenario?

@robin-siegl
Copy link
Author

robin-siegl commented Jun 26, 2023

simplified use case scenario:

const graphQlClient = new AwesomeGraphQLClient({
    endpoint: DEFAULT_ENDPOINT,
});

// Cached GraphQL Request Helper
export const cachedGraphQlRequest = async (document, variables) => {
    graphQlClient.setEndpoint(CACHED_ENDPOINT).request(document, variables);
}

// Uncached GraphQL Request Helper
export const uncachedGraphQlRequest = async (document, variables) => {
    graphQlClient.setEndpoint(UNCACHED_ENDPOINT).request(document, variables);
}

Edit:

another use case

// Get Endpoint from async function
export const graphQlRequest = async (document, variables) => {
    graphQlClient.setEndpoint(await getEndpoint()).request(document, variables);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants