lynxtaa / awesome-graphql-client

GraphQL Client with file upload support for NodeJS and browser
https://npm.im/awesome-graphql-client
MIT License
59 stars 7 forks source link

add option to change endpoint #78

Closed robin-siegl closed 1 year ago

robin-siegl commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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);
}