question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Version 3 breaking changes

See original GitHub issue

Some changes have been made in the branch v2.2 that got me thinking, do we really need to have custom configs to create an ApolloClient ? it would be much simpler to just have support for any ApolloClient, specially because I think most people will go for apollo-boost, the only downside I see is to implement subscriptions and other stuff that’s not yet in apollo-boost (related to this issue) but even for that we can just create our custom ApolloClient and follow Apollo’s docs to integrate the different links

Related to #12

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
lfadescommented, Sep 28, 2018

Here’s an example that creates the same ApolloClient created by this package using every possible option:

import ApolloClient from 'apollo-client';
import { ApolloLink, split } from 'apollo-link';
import { HttpLink } from 'apollo-link-http'
import { WebSocketLink } from 'apollo-link-ws'
import { setContext } from 'apollo-link-context';
import { onError } from 'apollo-link-error';
import { InMemoryCache } from 'apollo-cache-inmemory'
import { getMainDefinition } from 'apollo-utilities';
import withApollo from 'next-with-apollo'
import { GRAPHQL_URL, WS_URL } from '../configs'

export default withApollo(({ headers = {} }) => {
  const ssrMode = !process.browser

  const httpLink = new HttpLink({
    uri: GRAPHQL_URL
  })

  const wsLink = !ssrMode && new WebSocketLink({
    uri: WS_URL,
    options: {
      reconnect: true,
      connectionParams: {
        authorization: headers.authorization
      }
    }
  })

  const contextLink = setContext(
    async () => ({
      headers: {
        authorization: headers.authorization
      }
    })
  )

  const errorLink = onError(
    ({ graphQLErrors, networkError }) => {
      if (graphQLErrors) {
        graphQLErrors.map(err =>
          console.log(`[GraphQL error]: Message: ${err.message}`)
        )
      }
      if (networkError) console.log(`[Network error]: ${networkError}`)
    }
  )

  let link = ApolloLink.from([errorLink, contextLink, httpLink])

  if (!ssrMode) {
    link = split(
      // split based on operation type
      ({ query }) => {
        const definition = getMainDefinition(query);
        return (
          definition.kind === 'OperationDefinition' &&
          definition.operation === 'subscription'
        )
      },
      wsLink,
      link
    )
  }

  const cache = new InMemoryCache({
    dataIdFromObject: ({ id, __typename }) =>
      id && __typename ? __typename + id : null
  })

  return new ApolloClient({ link, ssrMode, cache })
})

The code is not really heavy to understand, but there are a lot of dependencies

1reaction
lfadescommented, May 23, 2018

@LawJolla you’re right, I’ll update the comment with a fix

Read more comments on GitHub >

github_iconTop Results From Across the Web

Breaking changes version 3 - Optimizely
This topic describes breaking changes in the Content Delivery API. Suggest Edits. A breaking change may cause a component to fail. When a...
Read more >
Breaking Changes · microsoft/TypeScript Wiki - GitHub
These changes list where implementation differs between versions as the spec and compiler are simplified and inconsistencies are corrected. For ...
Read more >
Version 3.x - Breaking Changes :: Documentation for Senzing
Version 3.x - Breaking Changes. Senzing Hardware and Software Requirements Changes. Supported Operating Systems have been updated to newer versions.
Read more >
Breaking changes - Flutter documentation
A list of migration guides for breaking changes in Flutter. ... Released in Flutter 3; Released in Flutter 2.10; Released in Flutter 2.5;...
Read more >
Upgrade to Prisma 3
Prisma 3 introduces a number of breaking changes if you are upgrading from an earlier version (any 2.x version), therefore, it is important...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found