How to use the apollo-cache-inmemory.IntrospectionFragmentMatcher function in apollo-cache-inmemory

To help you get started, we’ve selected a few apollo-cache-inmemory 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 apollographql / apollo-link-state / packages / apollo-link-state / src / __tests__ / client.ts View on Github external
const local = withClientState({
      resolvers: {
        Bar: {
          bar: () => 'Bar',
        },
        Baz: {
          baz: () => 'Baz',
        },
      },
      fragmentMatcher: ({ __typename }, typeCondition) =>
        __typename === typeCondition,
    });

    const client = new ApolloClient({
      cache: new InMemoryCache({
        fragmentMatcher: new IntrospectionFragmentMatcher({
          introspectionQueryResultData: {
            __schema: {
              types: [
                {
                  kind: 'UnionTypeDefinition',
                  name: 'Foo',
                  possibleTypes: [{ name: 'Bar' }, { name: 'Baz' }],
                },
              ],
            },
          },
        }),
      }),
      link: local.concat(link),
    });
github lucapette / deloominator / ui / src / services / GraphqlClient.js View on Github external
//@flow
import {ApolloClient} from 'apollo-client';
import {createHttpLink} from 'apollo-link-http';
import {InMemoryCache, IntrospectionFragmentMatcher} from 'apollo-cache-inmemory';

const fragmentMatcher = new IntrospectionFragmentMatcher({
  introspectionQueryResultData: {
    __schema: {
      types: [
        {
          kind: 'UNION',
          name: 'QueryResult',
          possibleTypes: [{name: 'queryError'}, {name: 'results'}],
        },
      ],
    },
  },
});

type Options = {
  port: number,
};
github xing / hops / packages / graphql / mixin.browser.js View on Github external
createFragmentMatcher() {
    if (global['APOLLO_FRAGMENT_TYPES']) {
      return new IntrospectionFragmentMatcher({
        introspectionQueryResultData: global['APOLLO_FRAGMENT_TYPES'],
      });
    }
    return new HeuristicFragmentMatcher();
  }
github gitlabhq / gitlabhq / app / assets / javascripts / sidebar / graphql.js View on Github external
import { IntrospectionFragmentMatcher } from 'apollo-cache-inmemory';
import produce from 'immer';
import VueApollo from 'vue-apollo';
import getIssueStateQuery from '~/issue_show/queries/get_issue_state.query.graphql';
import createDefaultClient from '~/lib/graphql';
import introspectionQueryResultData from './fragmentTypes.json';

const fragmentMatcher = new IntrospectionFragmentMatcher({
  introspectionQueryResultData,
});

const resolvers = {
  Mutation: {
    updateIssueState: (_, { issueType = undefined, isDirty = false }, { cache }) => {
      const sourceData = cache.readQuery({ query: getIssueStateQuery });
      const data = produce(sourceData, (draftData) => {
        draftData.issueState = { issueType, isDirty };
      });
      cache.writeQuery({ query: getIssueStateQuery, data });
    },
  },
};

export const defaultClient = createDefaultClient(resolvers, {
github orbiting / republik-frontend / lib / apollo / initApollo.js View on Github external
global.fetch = fetch
}

export const dataIdFromObject = object => {
  if (object.__typename) {
    if (object.id !== undefined) {
      return `${object.__typename}:${object.id}`
    }
    if (object._id !== undefined) {
      return `${object.__typename}:${object._id}`
    }
  }
  return null
}

const fragmentMatcher = new IntrospectionFragmentMatcher({
  introspectionQueryResultData: {
    __schema: {
      types: [
        {
          kind: 'UNION',
          name: 'Reward',
          possibleTypes: [
            {
              name: 'Goodie'
            },
            {
              name: 'MembershipType'
            }
          ]
        },
        {
github aredotna / ervell / react / apollo / index.js View on Github external
import mount from 'react/util/mount';

import { Themed } from 'react/styles/theme';

import introspectionQueryResultData from 'react/apollo/fragmentTypes.json';

import clientData from 'react/apollo/localState/clientData';

const isClientSide = typeof window !== 'undefined';

const { data: { GRAPHQL_ENDPOINT, CLIENT_GRAPHQL_ENDPOINT } } = sharify;

const clientHttpLink = new BatchHttpLink({ uri: CLIENT_GRAPHQL_ENDPOINT });
const serverHttpLink = new BatchHttpLink({ uri: GRAPHQL_ENDPOINT });

const fragmentMatcher = new IntrospectionFragmentMatcher({
  introspectionQueryResultData,
});

export const initApolloClient = ({
  token: X_AUTH_TOKEN,
  currentRoute,
  isLoggedIn,
  cookies,
  serializedMe,
  sharifyData,
} = {}) => {
  if (isClientSide && window.__APOLLO_CLIENT__) {
    return window.__APOLLO_CLIENT__;
  }

  const cache = new InMemoryCache({ fragmentMatcher });
github xing / hops / packages / react-apollo / mixin.server.js View on Github external
createFragmentMatcher() {
    return !introspectionResult
      ? new HeuristicFragmentMatcher()
      : new IntrospectionFragmentMatcher({
          introspectionQueryResultData: introspectionResult,
        });
  }
github xing / hops / packages / graphql / mixin.server.js View on Github external
createFragmentMatcher() {
    return !introspectionResult
      ? new HeuristicFragmentMatcher()
      : new IntrospectionFragmentMatcher({
          introspectionQueryResultData: introspectionResult,
        });
  }