How to use the apollo-link-http.HttpLink function in apollo-link-http

To help you get started, we’ve selected a few apollo-link-http 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 opencollective / opencollective-frontend / src / lib / initClient.js View on Github external
if (error) {
          const { message, locations, path } = error;
          console.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
          return;
        }

        console.error('[GraphQL error]: Received null error');
      });
    }

    if (networkError) {
      console.error(`[Network error]: ${networkError}`);
    }
  });

  const httpLink = new HttpLink({
    uri: getGraphqlUrl(),
    fetch,
  });

  const link = ApolloLink.from([errorLink, authLink.concat(httpLink)]);

  return new ApolloClient({
    connectToDevTools: process.browser,
    ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
    cache: cache.restore(initialState),
    link,
  });
}
github zeit / next.js / examples / with-apollo / lib / apollo.js View on Github external
function createApolloClient(initialState = {}) {
  // Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
  return new ApolloClient({
    ssrMode: typeof window === 'undefined', // Disables forceFetch on the server (so queries are only run once)
    link: new HttpLink({
      uri: 'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn', // Server URL (must be absolute)
      credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers`
      fetch,
    }),
    cache: new InMemoryCache().restore(initialState),
  })
}
github ammezie / techies / src / main.js View on Github external
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { setContext } from 'apollo-link-context'
import { InMemoryCache } from 'apollo-cache-inmemory'
import VueApollo from 'vue-apollo'
import App from './App'
import router from './router'

Vue.config.productionTip = false

// install the vue-momnet plugin
Vue.use(require('vue-moment'))

const httpLink = new HttpLink({ uri: 'http://localhost:4000/' })

const httpLinkAuth = setContext((_, { headers }) => {
  // get the authentication token from localstorage if it exists
  const token = localStorage.getItem('USER_TOKEN')

  // return the headers to the context so httpLink can read them
  return {
    headers: {
      ...headers,
      Authorization: token ? `Bearer ${token}` : ''
    }
  }
})

// Create the apollo client
const apolloClient = new ApolloClient({
github OriginProtocol / origin / experimental / origin-graphql / src / links / schema.js View on Github external
const token = localStorage.getItem('growth_auth_token')
  const returnObject = {
    headers: {
      ...headers
    }
  }

  if (token) {
    returnObject.headers['authentication'] = `{"growth_auth_token": "${token}"}`
  }

  // return the headers to the context so httpLink can read them
  return returnObject
})

const httpLink = new HttpLink({ uri: `${growthServerAddress}/graphql`, fetch })

const schema = mergeSchemas({
  schemas: [
    makeRemoteExecutableSchema({
      schema: growthSchema,
      link: authLink.concat(httpLink)
    }),
    makeExecutableSchema({ typeDefs, resolvers })
  ]
})

export default schema
github graphql-boilerplates / node-graphql-server / index.ts View on Github external
async function run() {

  // Step 1: Create local version of the CRUD API
  const link = new HttpLink({ uri: process.env.GRAPHQL_ENDPOINT, fetch })
  const graphcoolSchema = makeRemoteExecutableSchema({
    schema: await introspectSchema(link),
    link,
  })

  // Step 2: Define schema for the new API
  const extendTypeDefs = `
    extend type Query {
      viewer: Viewer!
    }

    type Viewer {
      me: User
      topPosts(limit: Int): [Post!]!
    }
github qhacks / qhacks-dashboard / packages / client / ApolloClient.js View on Github external
clientName: CLIENT_NAME,
      clientVersion: CLIENT_VERSION
    };

    operation.setContext({
      http: {
        includeExtensions: true
      }
    });

    return forward(operation);
  });

  // Terminating link to fetch data from server
  // NOTE: Reads request headers from context
  const networkLink = new HttpLink({
    uri: GRAPHQL_ENDPOINT
  });

  const apolloClient = new ApolloClient({
    cache,
    link: ApolloLink.from([
      errorLink,
      stateLink,
      authLink,
      clientIdentifierLink,
      networkLink
    ])
  });

  return {
    apolloClient,
github xing / hops / packages / react-apollo / mixin.server.js View on Github external
getApolloLink() {
    return (
      this.options.link ||
      new HttpLink({
        uri: this.config.graphqlUri,
        fetch,
      })
    );
  }
github apollographql / react-apollo / examples / rollup / main.js View on Github external
import React from 'react';
import ReactDOM from 'react-dom';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import { useQuery, ApolloProvider } from '@apollo/react-hooks';
import gql from 'graphql-tag';

const client = new ApolloClient({
  cache: new InMemoryCache(),
  link: new HttpLink({
    uri: 'http://localhost:4000/graphql'
  })
});

client.writeData({
  data: {
    isLoggedIn: false
  }
});

const IS_LOGGED_IN = gql`
  query IsUserLoggedIn {
    isLoggedIn @client
  }
`;
github revskill10 / next-template / modules / core / api / create-link.js View on Github external
function makeHttpLink(clientName, {urlMap}) {
  return new HttpLink({ uri: urlMap[clientName].uri, fetch, credentials: 'include' });
}
github GraphCMS / graphcms-examples / current / nuxt-apollo-blog / apollo / client-configs / default.js View on Github external
export default () => ({
  link: new HttpLink({ uri: GRAPHCMS_API }),
  cache: new InMemoryCache(),
  defaultHttpLink: false
})

apollo-link-http

HTTP transport layer for GraphQL

MIT
Latest version published 4 years ago

Package Health Score

64 / 100
Full package analysis