How to use the apollo-client.ApolloClient 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 fusionjs / fusionjs / fusion-plugin-apollo / src / __tests__ / integration.node.js View on Github external
async function testApp(el, {typeDefs, resolvers}, enhanceApp) {
  const port = await getPort();
  const endpoint = `http://localhost:${port}/graphql`;
  const app = new App(el);
  const schema = makeExecutableSchema({typeDefs, resolvers});
  const client = new ApolloClient({
    cache: new InMemoryCache({
      addTypename: false,
    }).restore({}),
    link: new HttpLink({
      endpoint,
      fetch: async (url, options) => {
        // required since the url here is only the path
        const result = await fetch(endpoint, options);
        return result;
      },
    }),
  });
  app.enhance(RenderToken, ApolloRenderEnhancer);
  app.register(GraphQLSchemaToken, schema);
  app.register(ApolloClientToken, ApolloClientPlugin);
  if (enhanceApp) {
github MacKentoch / react-redux-graphql-apollo-bootstrap-webpack-starter / src / server / SSR / src / middleware / ssr.js View on Github external
export default async function serverRender(req, res) {
  const location = req.url;
  const apolloClient = new ApolloClient({
    ssrMode: true,
    link: new HttpLink({ uri, fetch }),
    cache: new InMemoryCache(),
  });
  const context = {};
  let store = configureStore();
  const sheet = new ServerStyleSheet();

  console.log('serverRendering');

  // just for demo, replace with a "usefull" async. action to feed your state
  try {
    const { info } = await fakeFetch();
    const currentTime = format(new Date());
    const currentState = store.getState();
github bkinsey808 / graphql-fullstack-seed / client / src / app / app-module / client.ts View on Github external
applyMiddleware(req, next) {
    if (!req.options.headers) {
      req.options.headers = {};  // Create the header object if needed.
    }
    const token = AuthService.getJwtToken();
    if (token) {
      req.options.headers['authorization'] = AuthService.getJwtToken();
      console.log('got token: ', token);
    } else {
      console.log('did not get token', console.log(localStorage.getItem('id_token')));
    }
    next();
  }
}]);

const client = new ApolloClient({ networkInterface });

export function getClient(): ApolloClient {
  return client;
}
github genie-team / graphql-genie / src / main.ts View on Github external
// 	_root: any,
	// 	_args: { [key: string]: any },
	// 	_context: any,
	// 	_info: GraphQLResolveInfo,
	// ): any => {
	// 	const selections = computeIncludes(_info.operation.selectionSet.selections[0], 'GraphQLDirective');
	// 	console.info('selections');
	// 	console.info(selections);
	// 	console.info(JSON.stringify(selections));
	// 	console.log(_root);
	// 	console.log(_args);
	// 	console.log(_context);
	// 	console.log(_info);
	// });
	// addResolvers('GraphQLDirective', resolversMap);
	const client = new ApolloClient({
		link: new SchemaLink({ schema: schema }),
		cache: new InMemoryCache(),
		connectToDevTools: true
	});
	client.initQueryManager();

const createPost = gql`
	mutation createPost($title: String!) {
		createPost(title: $title) {
			id
		}
	}
`;

const createUser = gql`
mutation createUser($name: String!) {
github tsoporan / fittrak / fittrak-client / src / main.js View on Github external
attempts: {
      max: MAX_RETRIES,
      retryIf: error => !!error
    }
  }),
  errorLink,
  new HttpLink({
    uri: API_URL,
    credentials: DEBUG ? "include" : "same-origin",
    headers: {
      "x-csrftoken": Cookies.get("csrftoken")
    }
  })
]);

const apolloClient = new ApolloClient({
  link,
  cache: new InMemoryCache(),
  connectToDevTools: !DEBUG
});

const apolloProvider = new VueApollo({
  defaultClient: apolloClient
});

Vue.use(VueApollo);

/* eslint-disable no-new */
new Vue({
  el: "#app",
  router,
  apolloProvider,
github newsuk / times-components / packages / ssr / src / lib / run-client.js View on Github external
networkInterfaceOptions.headers["content-type"] =
      "application/x-www-form-urlencoded";
    networkInterfaceOptions.useGETForQueries = true;
  }

  if (
    typeof window !== "undefined" &&
    window.nuk &&
    !options.skipAuthorization
  ) {
    const acsTnlCookie = window.nuk.getCookieValue("acs_tnl");
    const sacsTnlCookie = window.nuk.getCookieValue("sacs_tnl");
    networkInterfaceOptions.headers.Authorization = `Cookie acs_tnl=${acsTnlCookie};sacs_tnl=${sacsTnlCookie}`;
  }

  return new ApolloClient({
    cache: new InMemoryCache({ fragmentMatcher }).restore(
      options.initialState || {}
    ),
    link: createHttpLink(networkInterfaceOptions)
  });
};
github atomicobject / ts-react-graphql-starter-kit / modules / graphql-api / context.ts View on Github external
constructor(
    public pg: db.Knex = db.getConnection(),
    schema: GraphQLSchema = executableSchema
  ) {
    this.apolloClient = new ApolloClient({
      ssrMode: true,
      cache: new InMemoryCache(),
      link: new SchemaLink({
        schema: schema,
        context: this
      })
    });
  }
github smooth-code / smooth.js / packages / smooth / src / server / apollo.js View on Github external
export function createApolloClient({ schema, context, fragmentTypes }) {
  return new ApolloClient({
    ssrMode: true,
    link: ApolloLink.from([
      new ValidateLink({ schema }),
      new SchemaLink({ schema, context }),
    ]),
    cache: new InMemoryCache({
      fragmentMatcher: new IntrospectionFragmentMatcher({
        introspectionQueryResultData: fragmentTypes,
      }),
    }),
  })
}
github m-inan / react-native-music-app / src / graphql / client.js View on Github external
const httpLink = new HttpLink({
	uri: 'http://localhost:4000/'
})

const authLink = setContext(async (_, { headers }) => {
	const token = await AsyncStorage.getItem('@App:token')

	return {
		headers: {
			...headers,
			authorization: token
		}
	}
})

const client = new ApolloClient({
	link: authLink.concat(httpLink),
	cache: new InMemoryCache()
})

export default client