-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Default fetch URL #14
Comments
It needs to be set for every query component; with this design multiple GraphQL APIs can be queried and components have final say about fetch options. What you can do is make a component for each API you want to query like this: import { Query } from 'graphql-react'
const pokemonFetchOptionsOverride = options => {
options.url = 'https://graphql-pokemon.now.sh'
}
const PokemonQuery = props => (
<Query
fetchOptionsOverride={pokemonFetchOptionsOverride}
{...props}
/>
) Then you can just use |
Perfect, thanks! |
@jaydenseric This took a while to find. I thought I was reading the docs incorrectly for setting a default url for my GraphQL instance. Might I suggest adding a section on this near the top of the docs? |
@jthegedus I think it's only confusing for people who are used to how Apollo Client sets the GraphQL endpoint People who read the
The usage example also shows how the GraphQL endpoint URL is specified for queries: I did notice that it is not documented for the |
The thing that sent me down the wrong path was the fact it is named as an "Override", implying a default. And when I couldn't find a default I thought that maybe it was me who had not set the default. I think the language could be made clearer here. And while the sentence
is correct, it wasn't helpful in correcting my understanding of how to reuse a URI. Since reusing a URI is such a common use case for any GraphQL client, I would expect a simple example as you gave above to feature somewhere early within the documentation, say in the Usage section under the existing Pokemon example. eg: In the case of reusing a single URI throughout your application, abstracting your API into it's own API Query component is as simple as: import React from 'react'
import { Query } from 'graphql-react'
const pokemonFetchOptionsOverride = options => {
options.url = 'https://graphql-pokemon.now.sh'
}
const PokemonQuery = props => (
<Query
fetchOptionsOverride={pokemonFetchOptionsOverride}
{...props}
/>
)
export default PokemonQuery Alternatively, an FAQ would also work. Just my 2c, thanks for the awesome tool 💯 |
I didn't see this in the docs. Does the fetch URL have to be set as an override for every single query, or is there an option to set a default one when instantiating the client?
The text was updated successfully, but these errors were encountered: