How to use apollo-link-rest - 10 common examples

To help you get started, we’ve selected a few apollo-link-rest 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 oslabs-beta / hypnos / client / App.jsx View on Github external
// instantiated errorLink
  // const httpLink = createHttpLink({ uri: proxy + endpoint });

  const headersOptions = {
    'Content-Type': 'application/json'
    // 'Access-Control-Allow-Origin': '*',
  };

  if (apiKey !== '' && headersKey !== '') {
    // console.log('apiKey: ', apiKey);
    // console.log('headersKey: ', headersKey);
    headersOptions[headersKey] = apiKey;
    // console.log('headersOptions ', headersOptions);
  }

  const restLink = new RestLink({
    // might be able to use custom fetch here for error checking?
    uri: proxy + endpoint,
    fetchOptions: {
      mode: 'no-cors'
    },
    headers: headersOptions,
    // onError: ({ networkError, graphQLErrors }) => {
    //   console.log('graphQLErrors', graphQLErrors);
    //   console.log('networkError', networkError);
    // },
    customFetch: (uri, fetchOptions) =>
      // console.log('in custom fetch. fetchOptions: ', fetchOptions);
      new Promise((resolve, reject) => {
        fetch(uri, fetchOptions)
          .then(res => {
            // const clone = res.clone();
github demokratie-live / democracy-client / src / graphql / client.js View on Github external
}
    },
    onCancel: () => {
      if (Platform.OS === 'ios') {
        networkActivity.onFinish += 1;
        if (networkActivity.onFinish === networkActivity.onRequest) {
          StatusBar.setNetworkActivityIndicatorVisible(false);
        }
      }
    },
  },
});

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

const restLink = new RestLink({
  uri: 'https://democracy-deutschland.de/api.php', // ?call=donation_status
});

client = new ApolloClient({
  cache,
  link: ApolloLink.from([
    loadingIndicator,
    networkStatusNotifierLink,
    authLinkMiddleware,
    authLinkAfterware,
    stateLink,
    restLink,
    new HttpLink({ uri: Configuration.GRAPHQL_URL }),
  ]),
});
export default client;
github valstu / follari / src / App.js View on Github external
return null;
      }
      return {
        ...data.racks[key],
        __typename: 'Rack',
        stopCode: data.racks[key].stopCode || null,
      };
    });

    // eslint-disable-next-line no-param-reassign
    data.racks = racksArr.filter(Boolean);
    return data;
  },
};

const restLink = new RestLink({
  uri: 'https://data.foli.fi/',
  typePatcher,
  fieldNameNormalizer: key => camelCase(key),
});

const client = new ApolloClient({
  link: restLink,
  cache: new InMemoryCache(),
});

const App = () => (
  
    
  
);
github codefordenver / members / src / createApolloClient.ts View on Github external
if (bearerToken) {
    authHeader = `Bearer ${bearerToken}`;
  }

  return {
    headers: {
      authorization: authHeader || null
      // TODO: Figure out if we should include a nonce header for graphcool
    }
  };
});

// Create a RestLink for the REST API
// If you are using multiple link types, restLink should go before httpLink,
// as httpLink will swallow any calls that should be routed through rest!
const restLink = new RestLink({
  endpoints: {
    github: 'https://api.github.com/'
  },
  credentials: 'omit',
  headers: {
    'Content-Type': 'application/json'
  }
});

export default function createApolloClient() {
  return new ApolloClient({
    link: ApolloLink.from([restLink, middlewareLink, httpLink]),
    cache: new InMemoryCache(),
    connectToDevTools: devMode
  });
}
github guandjoy / redfish / src / react-app / src / apolloClient.js View on Github external
uri: process.env.REACT_APP_SERVER_URL + process.env.REACT_APP_GRAPHQL_ENDPOINT
});

const authLink = setContext((_, { headers }) => {
  // get the authentication token from local storage if it exists
  const token = localStorage.getItem("token");
  // return the headers to the context so httpLink can read them
  return {
    headers: {
      ...headers,
      authorization: token ? `Token ${localStorage.getItem("token")}` : ""
    }
  };
});

const restLink = new RestLink({
  uri: process.env.REACT_APP_SERVER_URL
});

const apolloClient = new ApolloClient({
  link: ApolloLink.from([restLink, stateLink, authLink.concat(httpLink)]),
  cache,
  resolvers
});

export default apolloClient;
github arkhn / pyrog / client / src / app.tsx View on Github external
definition.kind === "OperationDefinition" &&
      definition.operation === "subscription"
    );
  },
  wsLink,
  httpLinkAuth
);

// Aggregate all links
const links = [];
if (process.env.NODE_ENV === "development") {
  links.push(errorLink);
}
if (process.env.CLEANING_SCRIPTS_URI) {
  links.push(
    new RestLink({
      uri: process.env.CLEANING_SCRIPTS_URI + "/",
      headers: {
        "Content-Type": "application/json"
      }
    })
  );
}
links.push(coreLink);

// Client
export const client = new ApolloClient({
  cache: new InMemoryCache(),
  connectToDevTools: true,
  link: ApolloLink.from(links)
});
github replicatedhq / kots / web / src / ShipClientGQL.js View on Github external
if (window.env.ENVIRONMENT === "development") {
    newGraphqlEndpoint = graphqlEndpoint;
  } else {
    newGraphqlEndpoint = window.location.origin + graphqlEndpoint;
  }

  const httpLink = createHttpLink({
    uri: newGraphqlEndpoint,
    fetch: fetcher ? fetcher : fetch,
  });

  if (fetcher) {
    global.Headers = fetcher.Headers;
  }

  const restLink = new RestLink({
    uri: `${restEndpoint}/v1`,
    endpoints: {
      "v1": `${restEndpoint}/v1`,
    },
    customFetch: fetcher ? fetcher : undefined,
  });

  const authLink = setContext(async (_, { headers }) => {
    return {
      headers: {
        ...headers,
        authorization: await tokenFunction(),
      },
    };
  });
github thicodes / rest-fullstack / packages / web / src / App.tsx View on Github external
import React from 'react';
import { hot } from 'react-hot-loader';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloProvider } from 'react-apollo';
import { RestLink } from 'apollo-link-rest';

import Routes from './Routes';
import './style.css';

const restLink = new RestLink({
  uri: 'http://jsonplaceholder.typicode.com',
});

const client = new ApolloClient({
  link: restLink,
  cache: new InMemoryCache(),
});

const App: React.SFC<{}> = () => (
  
    
  
);

export default hot(module)(App);
github Rsullivan00 / apollo-link-json-api / examples / simple / src / App.js View on Github external
import React, { Component } from 'react';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloProvider } from 'react-apollo';
import { RestLink } from 'apollo-link-rest';
import Person from './Person';
import './App.css';

const restLink = new RestLink({
  uri: 'https://swapi.co/api/',
});

const client = new ApolloClient({
  link: restLink,
  cache: new InMemoryCache(),
});

class App extends Component {
  render() {
    return (
      <div>
        <header>
          <h1>Welcome to Apollo Rest Link Example</h1>
        </header>
        </div>
github Rsullivan00 / apollo-link-json-api / examples / advanced / src / App.js View on Github external
import React, { Component } from 'react';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloProvider } from 'react-apollo';
import { RestLink } from 'apollo-link-rest';
import SearchShow from './SearchShow';
import './App.css';

const restLink = new RestLink({
  uri: 'https://api.tvmaze.com/',
});

const client = new ApolloClient({
  link: restLink,
  cache: new InMemoryCache(),
});

class App extends Component {
  render() {
    return (
      <div>
        <header>
          <h1>Welcome to Apollo Rest Link Example</h1>
        </header>
        </div>

apollo-link-rest

Query existing REST services with GraphQL

MIT
Latest version published 1 year ago

Package Health Score

68 / 100
Full package analysis

Popular apollo-link-rest functions

Similar packages