Heisenberg
Heisenberg

Reputation: 5279

Apollo-client without graphql endpoint

When I see sample apps which uses Apollo-client I see following constructor.When I read HttpLink document, it seems that graphql endpoint must be set as uribut in following code, I couldn't find them.

export const getApolloClient = (): ApolloClient<NormalizedCacheObject> =>
  new ApolloClient({
    cache: new InMemoryCache(),
    link: new HttpLink({ credentials: 'same-origin', fetch: customFetch }),
  });

My question is why this code work well ? I am totally novice of that, if someone knows this will you please let me know. Thanks

Upvotes: 0

Views: 314

Answers (1)

Matt Fikowski
Matt Fikowski

Reputation: 162

The HttpLink constructor option uri has a default value of /graphql. So as long as that is the correct path it will work without passing a uri option into the constructor.

So your example code:

HttpLink({ credentials: 'same-origin', fetch: customFetch })

is equivalent to

HttpLink({ credentials: 'same-origin', fetch: customFetch, uri: '/graphql' })

Upvotes: 1

Related Questions