github apollographql/apollo-client v3.9.0-alpha.3

latest releases: v3.12.0-rc.0, v3.11.10, v3.11.9...
pre-release12 months ago

Minor Changes

  • #11301 46ab032af Thanks @alessbell! - Add multipart subscription network adapters for Relay and urql

    Relay

    import { createFetchMultipartSubscription } from "@apollo/client/utilities/subscriptions/relay";
    import { Environment, Network, RecordSource, Store } from "relay-runtime";
    
    const fetchMultipartSubs = createFetchMultipartSubscription(
      "http://localhost:4000"
    );
    
    const network = Network.create(fetchQuery, fetchMultipartSubs);
    
    export const RelayEnvironment = new Environment({
      network,
      store: new Store(new RecordSource()),
    });

    Urql

    import { createFetchMultipartSubscription } from "@apollo/client/utilities/subscriptions/urql";
    import { Client, fetchExchange, subscriptionExchange } from "@urql/core";
    
    const url = "http://localhost:4000";
    
    const multipartSubscriptionForwarder = createFetchMultipartSubscription(url);
    
    const client = new Client({
      url,
      exchanges: [
        fetchExchange,
        subscriptionExchange({
          forwardSubscription: multipartSubscriptionForwarder,
        }),
      ],
    });

Patch Changes

  • #11275 3862f9ba9 Thanks @phryneas! - Add a defaultContext option and property on ApolloClient, e.g. for keeping track of changing auth tokens or dependency injection.

    This can be used e.g. in authentication scenarios, where a new token might be
    generated outside of the link chain and should passed into the link chain.

    import { ApolloClient, createHttpLink, InMemoryCache } from "@apollo/client";
    import { setContext } from "@apollo/client/link/context";
    
    const httpLink = createHttpLink({
      uri: "/graphql",
    });
    
    const authLink = setContext((_, { headers, token }) => {
      return {
        headers: {
          ...headers,
          authorization: token ? `Bearer ${token}` : "",
        },
      };
    });
    
    const client = new ApolloClient({
      link: authLink.concat(httpLink),
      cache: new InMemoryCache(),
    });
    
    // somewhere else in your application
    function onNewToken(newToken) {
      // token can now be changed for future requests without need for a global
      // variable, scoped ref or recreating the client
      client.defaultContext.token = newToken;
    }
  • #11297 c8c76a522 Thanks @jerelmiller! - Add an explicit return type for the useReadQuery hook called UseReadQueryResult. Previously the return type of this hook was inferred from the return value.

Don't miss a new apollo-client release

NewReleases is sending notifications on new releases.