How to use the apollo-upload-client.createUploadLink function in apollo-upload-client

To help you get started, we’ve selected a few apollo-upload-client 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 withspectrum / spectrum / shared / graphql / index.js View on Github external
);

      // Retry mutations for a looong time, those are very important to us so we want them to go through eventually
      if (isMutation) {
        return !!error && count < 25;
      }

      // Retry queries for way less long as this just ends up showing
      // loading indicators for that whole time which is v annoying
      return !!error && count < 6;
    },
  });

  // HTTP Link for queries and mutations including file uploads
  const httpLink = retryLink.concat(
    createUploadLink({
      uri: API_URI,
      credentials: 'include',
      headers,
    })
  );

  // Switch between the two links based on operation
  const link = split(
    ({ query }) => {
      const { kind, operation } = getMainDefinition(query);
      return kind === 'OperationDefinition' && operation === 'subscription';
    },
    wsLink,
    httpLink
  );
github ahrbil / TDI-Exchange / packages / web / src / apolloClient.js View on Github external
import { InMemoryCache } from "apollo-cache-inmemory";
import { ApolloClient } from "apollo-client";
import { createUploadLink } from "apollo-upload-client";

import { GQL_URI } from "./constants";

const cache = new InMemoryCache();

export const apolloClient = new ApolloClient({
  cache,
  // createUploadLink handles the file upload
  link: createUploadLink({
    uri: GQL_URI,
    credentials: "include"
  })
});
github Akryum / vue-cli-plugin-apollo / graphql-client / src / index.js View on Github external
typeDefs = undefined,
  // Local Resolvers
  resolvers = undefined,
  // Hook called when you should write local state in the cache
  onCacheInit = undefined,
}) {
  let wsClient, authLink, stateLink
  const disableHttp = websocketsOnly && !ssr && wsEndpoint

  // Apollo cache
  if (!cache) {
    cache = new InMemoryCache(inMemoryCacheOptions)
  }

  if (!disableHttp) {
    const httpLink = createUploadLink({
      uri: httpEndpoint,
      ...httpLinkOptions,
    })

    if (!link) {
      link = httpLink
    } else if (defaultHttpLink) {
      link = from([link, httpLink])
    }

    // HTTP Auth header injection
    authLink = setContext((_, { headers }) => {
      const authorization = getAuth(tokenName)
      const authorizationHeader = authorization ? { authorization } : {}
      return {
        headers: {
github DimiMikadze / create-social-network / frontend / src / utils / apollo-client.js View on Github external
export const createApolloClient = (apiUrl, websocketApiUrl) => {
  const cache = new InMemoryCache();

  const errorLink = handleErrors();
  const authLink = createAuthLink();
  const uploadLink = createUploadLink({ uri: apiUrl }); // Upload link also creates an HTTP link

  // Create WebSocket link
  const authToken = localStorage.getItem('token');
  const wsLink = new WebSocketLink({
    uri: websocketApiUrl,
    options: {
      timeout: 60000,
      reconnect: true,
      connectionParams: {
        authorization: authToken,
      },
    },
  });

  // Temporary fix for early websocket closure resulting in websocket connections not being instantiated
  // https://github.com/apollographql/subscriptions-transport-ws/issues/377
github polo13999 / airWatch / client / src / lib / initApollo.js View on Github external
function create(initialState, { getToken }) {
  let httpLink = createUploadLink({
    uri: `${envs.serverURL()}/graphql`,
    credentials: 'include'
  })
  const authLink = setContext((operation, inData) => {
    const { headers } = inData
    const token = getToken()
    console.log('token', token)
    console.log('operation', operation)
    if (token) {
      return operation[
        {
          headers: {
            ...headers,
            Cookie: token ? token : null
          }
        }
github sysgears / apollo-universal-starter-kit / modules / upload / client-react / netLink.js View on Github external
export default uri =>
  ApolloLink.split(
    ({ variables }) => extractFiles(cloneDeep(variables)).length > 0,
    createUploadLink({ uri, credentials: 'include' }),
    new BatchHttpLink({
      uri,
      credentials: 'include'
    })
  );
github benawad / fullstack-graphql-airbnb-clone / packages / app / src / apollo.ts View on Github external
import { ApolloClient } from "apollo-client";
import { InMemoryCache } from "apollo-cache-inmemory";
import { createUploadLink } from "apollo-upload-client";
import { Platform } from "react-native";

const host =
  Platform.OS === "ios" ? "http://localhost:4000" : "http://10.0.2.2:4000";

export const client = new ApolloClient({
  link: createUploadLink({
    uri: host
  }),
  cache: new InMemoryCache()
});
github jaydenseric / apollo-upload-examples / app / withApollo.js View on Github external
const createApolloClient = (cache = {}) =>
  new ApolloClient({
    ssrMode: typeof window !== 'undefined',
    cache: new InMemoryCache().restore(cache),
    link: createUploadLink({ uri: process.env.API_URI })
  })
github ian13456 / Gooseberries / frontend / src / index.js View on Github external
import './index.css'
import Gooseberries from './Gooseberries'
import * as serviceWorker from './serviceWorker'
import { AUTH_TOKEN } from './constants'
import defaults from './graphql/defaults'
import resolvers from './graphql/resolvers'

const cache = new InMemoryCache()

const stateLink = withClientState({
	resolvers,
	cache,
	defaults
})

const httpLink = createUploadLink({
	uri: 'http://localhost:8000/graphql'
})

const authLink = setContext((_, { headers }) => {
	const token = localStorage.getItem(AUTH_TOKEN)
	return {
		headers: {
			...headers,
			authorization: token ? `JWT ${token}` : ''
		}
	}
})

const client = new ApolloClient({
	link: ApolloLink.from([stateLink, authLink.concat(httpLink)]),
	cache: cache
github rshk / yawc / web / src / lib / apollo.js View on Github external
const httpLink = (() => {
    const config = {
        uri: API_URL,
        credentials: 'same-origin'
    };

    if (ENABLE_UPLOADS) {
        return createUploadLink(config);
    }
    return createHttpLink(config);
})();

apollo-upload-client

A terminating Apollo Link for Apollo Client that fetches a GraphQL multipart request if the GraphQL variables contain files (by default FileList, File, or Blob instances), or else fetches a regular GraphQL POST or GET request (depending on the config and

MIT
Latest version published 1 year ago

Package Health Score

68 / 100
Full package analysis