{"action":"closed","issue":{"url":"https://api.github.com/repos/apollographql/apollo-link/issues/264","repository_url":"https://api.github.com/repos/apollographql/apollo-link","labels_url":"https://api.github.com/repos/apollographql/apollo-link/issues/264/labels{/name}","comments_url":"https://api.github.com/repos/apollographql/apollo-link/issues/264/comments","events_url":"https://api.github.com/repos/apollographql/apollo-link/issues/264/events","html_url":"https://github.com/apollographql/apollo-link/issues/264","id":275534130,"number":264,"title":"Feature idea: Allow string or function `uri` option for HttpLink","user":{"login":"stephenkao","id":2421042,"avatar_url":"https://avatars2.githubusercontent.com/u/2421042?v=4","gravatar_id":"","url":"https://api.github.com/users/stephenkao","html_url":"https://github.com/stephenkao","followers_url":"https://api.github.com/users/stephenkao/followers","following_url":"https://api.github.com/users/stephenkao/following{/other_user}","gists_url":"https://api.github.com/users/stephenkao/gists{/gist_id}","starred_url":"https://api.github.com/users/stephenkao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stephenkao/subscriptions","organizations_url":"https://api.github.com/users/stephenkao/orgs","repos_url":"https://api.github.com/users/stephenkao/repos","events_url":"https://api.github.com/users/stephenkao/events{/privacy}","received_events_url":"https://api.github.com/users/stephenkao/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-11-20T23:27:16Z","updated_at":"2017-11-29T14:37:44Z","closed_at":"2017-11-29T14:37:44Z","author_association":"CONTRIBUTOR","body":"Hey, there!  \r\n\r\nI'm currently upgrading from apollo-client@1.9.0 to apollo-client@2.0.1, and I'm running into a slight issue since HTTPFetchNetworkInterface was removed.  Originally, I had something like the following (based on [this issue](https://github.com/apollographql/apollo-client/issues/1267)): \r\n\r\n```jsx\r\nimport { HTTPFetchNetworkInterface } from 'apollo-client';\r\n\r\nexport class CustomApolloNetworkInterface extends HTTPFetchNetworkInterface {\r\n  fetchFromRemoteEndpoint({ request, options }) {\r\n    const { _uri } = this;\r\n    const { operationName } = request;\r\n    if (operationName) this._uri += `?opname=${operationName}`;\r\n\r\n    const requestPromise = super.fetchFromRemoteEndpoint({ request, options });\r\n    this._uri = _uri;\r\n\r\n    return requestPromise;\r\n  }\r\n}\r\n\r\nexport default function createApolloClient() {\r\n  const networkInterface = new CustomApolloNetworkInterface(`${url}/graph/graphql`);\r\n  return new ApolloClient({ networkInterface });\r\n}\r\n```\r\n\r\nThis let me add the operation name as a query parameter to each request, which I used for automated alerting and graphing based on operation timings.  Since the custom network interface is no longer around, this is slightly more difficult.\r\n\r\nMy proposal is to make the `uri` option for HttpLink to be opened up to a function as well as a string.  [The actual fetch](https://github.com/apollographql/apollo-link/blob/master/packages/apollo-link-http/src/httpLink.ts#L178) would turn out to be something like:\r\n\r\n```jsx\r\nlet uriValue = typeof uri === 'function' ? uri(operation) : uri;  // do a safer function validation here :P\r\nfetcher(contextURI || uriValue, fetcherOptions).then(() => { ... });\r\n```\r\n\r\nThat'd allow for something like:\r\n```jsx\r\nexport default function createApolloClient() {\r\n  const link = new HttpLink({\r\n    uri: (operation) => `${url}/graph/graphql?opname=${operation.operationName}`\r\n  });\r\n\r\n  const client = new ApolloClient({\r\n    link,\r\n    cache: new InMemoryCache().restore(IS_BROWSER ? window.__APOLLO_STATE__ : {}),\r\n  });\r\n\r\n  return client;\r\n}\r\n```\r\n\r\nWhat do y'all think?  If there's a better way to do this, please let me know!  Thanks!"}}
{"actor":{"display_login":"jbaxleyiii"}}