How to use the apollo-client.IntrospectionFragmentMatcher 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 coralproject / talk / client / coral-framework / services / client.js View on Github external
// To debug queries add print(req.request.query) and import it from graphql/language/printer
        // console.log(print(req.request.query));
        next();
      },
    },
  ]);

  const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
    networkInterface,
    wsClient
  );

  const client = new ApolloClient({
    connectToDevTools: true,
    addTypename: true,
    fragmentMatcher: new IntrospectionFragmentMatcher({
      introspectionQueryResultData: introspectionData,
    }),
    dataIdFromObject: result => {
      if (result.id && result.__typename) {
        // eslint-disable-line no-underscore-dangle
        return `${result.__typename}_${result.id}`; // eslint-disable-line no-underscore-dangle
      }
      return null;
    },
    networkInterface: networkInterfaceWithSubscriptions,
  });

  client.resetWebsocket = () => {
    if (wsClient.client) {
      // Close socket connection which will also unregister subscriptions on the server-side.
      wsClient.close(true);
github coralproject / talk / client / coral-admin / src / services / fragmentMatcher.js View on Github external
import {IntrospectionFragmentMatcher} from 'apollo-client';

// TODO this is a short-term fix
// we need to set up something to query the server for the schema before ApolloClient initialization
// https://github.com/apollographql/apollo-client/issues/1555#issuecomment-295834774
const fm = new IntrospectionFragmentMatcher({
  introspectionQueryResultData: {
    __schema: {
      types: [
        {
          kind: 'INTERFACE',
          name: 'UserError',
          possibleTypes: [
            {name: 'GenericUserError'},
            {name: 'ValidationUserError'}
          ]
        },
        {
          kind: 'INTERFACE',
          name: 'Response',
          possibleTypes: [
            {name: 'CreateCommentResponse'},
github drupal-graphql / drupal-decoupled-app / frontend / app / shared / state / configureApolloClient.js View on Github external
uri: requestUri,
    });

  // Use persisted queries and GET requests in production.
  const finalNetworkInterface =
    isProduction && hasApiVersion
      ? addGetRequests(
          addPersistedQueries(apiVersion, queryMap, networkInterface),
        )
      : networkInterface;

  const apolloClient = new ApolloClient({
    reduxRootSelector: state => state.apollo,
    networkInterface: finalNetworkInterface,
    ssrMode: __SERVER__,
    fragmentMatcher: new IntrospectionFragmentMatcher({
      introspectionQueryResultData: introspectionData,
    }),
  });

  return apolloClient;
};
github drupal-graphql / drupal-decoupled-app / frontend / app / shared / state / configureApolloClient.js View on Github external
uri: requestUri,
    });

  // Use persisted queries and GET requests in production.
  const finalNetworkInterface =
    isProduction && hasApiVersion
      ? addGetRequests(
          addPersistedQueries(apiVersion, queryMap, networkInterface),
        )
      : networkInterface;

  const apolloClient = new ApolloClient({
    reduxRootSelector: state => state.apollo,
    networkInterface: finalNetworkInterface,
    ssrMode: __SERVER__,
    fragmentMatcher: new IntrospectionFragmentMatcher({
      introspectionQueryResultData: introspectionData,
    }),
  });

  return apolloClient;
};
github Skjutsgruppen / skjutsgruppen-reactnative / app / services / apollo / apollo.js View on Github external
if (!req.options.headers) {
      req.options.headers = {};
    }

    const token = await Auth.getToken();
    req.options.headers.authorization = token;
    next();
  },
}]);

const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
  networkInterface,
  wsClient,
);

const feedFragmentMatcher = new IntrospectionFragmentMatcher({
  introspectionQueryResultData: {
    __schema: {
      types: [
        {
          kind: 'INTERFACE',
          name: 'Feed',
          possibleTypes: [
            {
              name: 'GroupFeed',
            },
            {
              name: 'TripFeed',
            },
            {
              name: 'CommentFeed',
            },
github Webiks / GeoStrike / packages / client / src / app / core / configured-apollo / network / apollo.service.ts View on Github external
connectionParams: () => {
          if (!AuthorizationMiddleware.token || AuthorizationMiddleware.token === '') {
            return {};
          }

          return {'player-token': AuthorizationMiddleware.token};
        },
        connectionCallback: (error => {
          if (error) {
            AuthorizationMiddleware.setToken('');
            window.location.href = '/';
          }
        })
      });

      const fragmentMatcher = new IntrospectionFragmentMatcher({
        introspectionQueryResultData: {
          __schema: {
            types: [
              {
                'kind': 'INTERFACE',
                'name': 'User',
                'possibleTypes': [
                  {'name': 'Player'},
                  {'name': 'Viewer'}
                ]
              },
            ],
          },
        }
      });