How to use the apollo-boost.split function in apollo-boost

To help you get started, we’ve selected a few apollo-boost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github input-output-hk / smart-contract-backend / src / client / Client.ts View on Github external
})

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

  const link = errorLink.concat(split(
    ({ query }) => {
      const definition = getMainDefinition(query)
      return definition.kind === 'OperationDefinition' && definition.operation === 'subscription'
    },
    wsLink,
    httpLink
  ))

  const apolloClient = new ApolloClient({
    cache: new InMemoryCache(),
    defaultOptions: {
      query: { fetchPolicy: 'network-only' },
      watchQuery: { fetchPolicy: 'network-only' }
    },
    link
  })
github wendelfreitas / animavita / packages / mobile / src / apollo / client.js View on Github external
uri: `${APP_SERVER}/subscriptions`,
  options: {
    reconnect: true,
    lazy: true,
    connectionParams: async () => {
      const token = await getToken();
      return {
        headers: {
          authorization: token ? `Bearer ${token}` : '',
        },
      };
    },
  },
});

const link = split(
  ({ query }) => {
    const { kind, operation } = getMainDefinition(query);
    return kind === 'OperationDefinition' && operation === 'subscription';
  },
  wsLink,
  authLink.concat(httpLink),
);

const client = new ApolloClient({
  link,
  cache,
  onError: e => console.log(e),
});

export default client;
github TiE23 / metric-teacher / client / src / index.js View on Github external
headers: {
    authorization: token ? `Bearer ${token}` : null,
  },
});

const wsLink = new WebSocketLink({
  uri: `ws://${API_ROOT}`,
  options: {
    reconnect: true,
    connectionParams: {
      authToken: token,
    },
  },
});

const link = split(
  ({ query }) => {
    const { kind, operation } = getMainDefinition(query);
    return kind === "OperationDefinition" && operation === "subscription";
  },
  wsLink,
  httpLinkWithAuthToken,
);

const client = new ApolloClient({
  link,
  cache: new InMemoryCache({
    dataIdFromObject: object => object.id,
  }),
});

ReactDOM.render(
github MoonHighway / learning-graphql / chapter-07 / photo-share-client / src / index.js View on Github external
headers: {
            ...context.headers,
            authorization: localStorage.getItem('token')
        }
    }))
    return forward(operation)
})

const httpAuthLink = authLink.concat(httpLink)

const wsLink = new WebSocketLink({
    uri: `ws://localhost:4000/graphql`,
    options: { reconnect: true }
  })
  
const link = split(
    ({ query }) => {
        const { kind, operation } = getMainDefinition(query)
        return kind === 'OperationDefinition' && operation === 'subscription'
    }, 
    wsLink,
    httpAuthLink
)

const client = new ApolloClient({ 
    cache,
    link
})

render(