How to use the apollo-client function in apollo-client

To help you get started, we’ve selected a few apollo-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 ilyaskarim / apollo-graphql-chat / client / src / Apollo.js View on Github external
});

// using the ability to split links, you can send data to each link
// depending on what kind of operation is being sent
export const link = split(
  // split based on operation type
  ({ query }) => {
    const { kind, operation } = getMainDefinition(query);
    return kind === 'OperationDefinition' && operation === 'subscription';
  },
  wsLink,
  httpLink,
);

// Instantiate client
export const client = new ApolloClient({
  link,
  uri: GRAPHQL_URI,
  cache: new InMemoryCache()
})
github strues / boldr / web / src / shared / core / createApolloClient.js View on Github external
return result.__typename + result.id; // eslint-disable-line no-underscore-dangle
      }
      return null;
    },
    networkInterface,
  };
  if (__CLIENT__) {
    if (window.__APOLLO_STATE__) {
      params.initialState = window.__APOLLO_STATE__;
    }
    params.ssrForceFetchDelay = 100;
  } else {
    params.ssrMode = true;
  }

  return new ApolloClient(params);
};
github birkir / kvikmyndr-app / src / store / index.js View on Github external
import config from '../config';
import UI from './UI';
import Auth from './Auth';

if (__DEV__) { // eslint-disable-line
  const nativeXMLHttpRequest = XMLHttpRequest; // eslint-disable-line
  const devXMLHttpRequest = GLOBAL.originalXMLHttpRequest ? GLOBAL.originalXMLHttpRequest : GLOBAL.XMLHttpRequest; // eslint-disable-line
  GLOBAL.XMLHttpRequest = devXMLHttpRequest;
}

// Create new Apollo client
const link = new Link({
  uri: config.GRAPHQL_ENDPOINT,
});
const cache = new InMemoryCache();
const client = new ApolloClient({
  link,
  cache,
});


export default class Store {
  client = client;
  ui = new UI();
  auth = new Auth();
  
  async setup() {
    return true;
  }
}

export class StoreProvider extends PureComponent {
github apollographql / react-apollo / test / react-native / __tests__ / component.js View on Github external
it('renders correctly', () => {
    const query = gql`query people { allPeople(first: 1) { people { name } } }`;
    const data = { allPeople: { people: { name: 'Luke Skywalker' } } };
    const networkInterface = mockNetworkInterface({ request: { query }, result: { data } });
    const client = new ApolloClient({ networkInterface });

    const ContainerWithData = graphql(query)(({ data }) => {
      if (data.loading) return 
      return ;
    });
    const output = renderer.create(
      
    )
    expect(output.toJSON()).toMatchSnapshot();
  });
github joshleblanc / apollo-next-now-test / client / lib / initApolloClient.js View on Github external
cache.writeData({
                data: {
                    token: null
                }
            });
            Cookies.remove('token');
            Router.push('/');
        }
    })

    const link = createHttpLink({
        uri: host,
        fetch: fetch,
        credentials: 'same-origin'
    })
    return new ApolloClient({
        connectToDevTools: process.browser,
        ssrMode: !process.browser,
        link: authLink.concat(errorLink).concat(link),
        cache,
        resolvers
    });
}
github webiny / webiny-js / packages / demo-site / server / server.js View on Github external
const createClient = req => {
    return new ApolloClient({
        ssrMode: true,
        link: ApolloLink.from([
            createOmitTypenameLink(),
            createHttpLink({
                uri: process.env.REACT_APP_API_HOST + "/function/api",
                credentials: "same-origin",
                headers: {
                    cookie: req.header("Cookie")
                }
            })
        ]),
        cache: new InMemoryCache({
            addTypename: true,
            dataIdFromObject: obj => obj.id || null
        })
    });
github react-native-training / apollo-graphql-mongodb-react-native / apolloclient / index.android.js View on Github external
const Client = () => {
  const networkInterface = createNetworkInterface({
    uri: 'http://localhost:8080/graphql'
  })
  const client = new ApolloClient({
    networkInterface
  });
  return (
    
      
    )
}
github tsirlucas / soundplace / src / core / apollo / Client.ts View on Github external
new RetryLink({
        delay: {
          initial: 300,
          max: Infinity,
          jitter: true,
        },
        attempts: {
          max: 3,
          retryIf: (error, _operation) => !!error,
        },
      }),
      wsLink,
    ]);

    this.resolver(
      new ApolloClient({
        link,
        cache,
        defaultOptions: {
          query: {
            fetchPolicy: 'cache-and-network',
          },
        },
      }),
    );
  }
github notadamking / React-Realtime-Chat / client / index.js View on Github external
networkInterface.use([{
  applyMiddleware(req, next) {
    if (!req.options.headers) {
      req.options.headers = {};
    }
    req.options.headers.authorization = localStorage.getItem(config.authTokenName);
    next();
  }
}]);

const host = location.origin.replace(/^http/, 'ws');
const wsClient = new Client(host);
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(networkInterface, wsClient);

const client = new ApolloClient({
  networkInterface: networkInterfaceWithSubscriptions,
  dataIdFromObject: (result) => {
    if (result.id && result.__typename) {
      return result.__typename + result.id;
    }
    return null;
  },
  shouldBatch: true,
  initialState: window.__APOLLO_STATE__,
  ssrForceFetchDelay: 100,
});

const initialState = window.__INITIAL_STATE__;
const store = configureStore({ initialState, client });

function render() {
github rabbotio / nap / lib / initClient.js View on Github external
const createClient = headers => {
  return new ApolloClient({
    ssrMode: !process.browser,
    headers,
    dataIdFromObject: result => result.id || null,
    networkInterface
  })
}