Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

fetcherOptions.method not respected #153

Closed
arackaf opened this issue Oct 17, 2017 · 3 comments
Closed

fetcherOptions.method not respected #153

arackaf opened this issue Oct 17, 2017 · 3 comments

Comments

@arackaf
Copy link

arackaf commented Oct 17, 2017

Intended outcome:

Use http GET verb for graphQL query

Actual outcome:

POST is used. Override is not respected

How to reproduce the issue:

import { ApolloProvider, ApolloClient as RClient, gql, graphql, withApollo } from "react-apollo";
import { ApolloClient } from "apollo-client";
export const client = new ApolloClient();

const ApolloClientAny: any = ApolloClient;

import { HttpLink, createHttpLink } from "apollo-link-http";

export const client2 = new ApolloClientAny({
  link: createHttpLink({ fetcherOptions: { method: "get" } })
});

let title = null;
client2
  .query({
    query: gql`
      query GetMyBooks($title: String) {
        books2(title: $title) {
          title
        }
      }
    `,
    variables: {}
  })
  .then(res => {
    debugger;
  });

The problem may be here, in httpLink.ts

let options = fetcherOptions;
if (requestOptions.fetcherOptions)
  options = { ...requestOptions.fetcherOptions, ...options };

options is overriding whatever I send in for requestOptions.fetcherOptions (also, your docs have this option incorrectly as fetchOptions https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-http)

But I can't verify this since the relevant part of createHttpLink never executes. It appears as though ApolloClient isn't even using it? ApolloClient doesn't appear to look for a link property in its options anywhere. So depending on what's on options above, there may be two issues, though at the very least the client object does not use the link object I pass in.

@jbaxleyiii
Copy link
Contributor

@arackaf the fetcherOptions => fetchOptions will be fixed with the next release! (0.9.0). I also added a test to ensure that both the setup options and the context options could set the method of requesting.

But I can't verify this since the relevant part of createHttpLink never executes. It appears as though ApolloClient isn't even using it? ApolloClient doesn't appear to look for a link property in its options anywhere.

Looking at your sample code above, I think the issue is your apollo-client is missing a cache which is probably breaking all sorts of things. I'll add / throw a warning on the core client if link or cache is missing!

I've added an issue to track that here

@arackaf
Copy link
Author

arackaf commented Oct 17, 2017

@jbaxleyiii thanks so much!

So if specifying a cache is more or less required, I'm curious why my code was working so well otherwise - my React components were caching queries perfectly.

In any event, if I do need to specify a cache, is this what I need, in order to keep the same behavior I was seeing out of the box with React?

import InMemoryCache from "apollo-cache-inmemory";

const client = new ApolloClient({
  link: new HttpLink({ uri: "/graphql" }),
  cache: new InMemoryCache()
});

Also, can you point me in the direction of the code where adding a link to the options of ApolloClient will work? I didn't see anything in there that accounted for a link property, but I'm sure I was looking in the wrong place. (I'm mostly just curious, if it's not too much trouble :))

@peggyrayzis
Copy link
Contributor

Hi @arackaf! Sorry for the delay, we've been very busy with the new 2.0 release!

Our recently released docs site should have the answers you're looking for. I'm going to close this issue since the original request was fixed, but please open a new one regarding docs if there's anything that we could make more clear!

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

No branches or pull requests

3 participants