How to use the apollo-link.ApolloLink.empty function in apollo-link

To help you get started, we’ve selected a few apollo-link 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-client / packages / apollo-client / src / __tests__ / client.ts View on Github external
it('creates query manager lazily', () => {
    const client = new ApolloClient({
      link: ApolloLink.empty(),
      cache: new InMemoryCache(),
    });

    expect(client.queryManager).toBeUndefined();

    // We only create the query manager on the first query
    client.initQueryManager();
    expect(client.queryManager).toBeDefined();
    expect(client.cache).toBeDefined();
  });
github apollographql / apollo-client / packages / apollo-client / src / ApolloClient.ts View on Github external
queryDeduplication = true,
      defaultOptions,
      assumeImmutableResults = false,
      resolvers,
      typeDefs,
      fragmentMatcher,
      name: clientAwarenessName,
      version: clientAwarenessVersion,
    } = options;

    let { link } = options;

    // If a link hasn't been defined, but local state resolvers have been set,
    // setup a default empty link.
    if (!link && resolvers) {
      link = ApolloLink.empty();
    }

    if (!link || !cache) {
      throw new InvariantError(
        "In order to initialize Apollo Client, you must specify 'link' and 'cache' properties in the options object.\n" +
        "These options are part of the upgrade requirements when migrating from Apollo Client 1.x to Apollo Client 2.x.\n" +
        "For more information, please visit: https://www.apollographql.com/docs/tutorial/client.html#apollo-client-setup"
      );
    }

    // remove apollo-client supported directives
    this.link = link;
    this.cache = cache;
    this.store = new DataStore(cache);
    this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
    this.queryDeduplication = queryDeduplication;
github apollographql / apollo-client / packages / apollo-client / src / __tests__ / local-state / initializers.ts View on Github external
it('should run initializers asynchronously', async (done) => {
    const cache = new InMemoryCache();
    const client = new ApolloClient({
      cache,
      link: ApolloLink.empty(),
    });

    client.runInitializers({
      primaryUserId: () => 100,
    });
    expect(cache.extract()).toEqual({});

    await client.runInitializers({
      secondaryUserId: () => 200,
    });
    expect(cache.extract()).toEqual({
      ROOT_QUERY: {
        primaryUserId: 100,
        secondaryUserId: 200,
      },
    });
github apollographql / apollo-client / packages / apollo-client / src / core / __tests__ / fetchPolicies.ts View on Github external
it('gives appropriate networkStatus for refetched queries', done => {
    const client = new ApolloClient({
      link: ApolloLink.empty(),
      cache: new InMemoryCache(),
      resolvers: {
        Query: {
          hero(_data, args) {
            return {
              __typename: 'Hero',
              ...args,
              name: 'Luke Skywalker',
            };
          },
        },
      },
    });

    const observable = client.watchQuery({
      query: gql`
github apollographql / apollo-client / packages / apollo-client / src / __tests__ / local-state / export.ts View on Github external
done => {
      const query = gql`
        {
          car @client {
            engine {
              torque @export(as: "torque")
            }
          }
        }
      `;

      const cache = new InMemoryCache();
      const client = new ApolloClient({
        cache,
        link: ApolloLink.empty(),
        resolvers: {},
      });

      cache.writeData({
        data: {
          car: {
            engine: {
              cylinders: 8,
              torque: 7200,
              __typename: 'Engine',
            },
            __typename: 'Car',
          },
        },
      });
github apollographql / apollo-client / packages / apollo-client / src / __tests__ / local-state / resolvers.ts View on Github external
() => {
      const query = gql`
        {
          fie: foo @client {
            bar
          }
        }
      `;

      const cache = new InMemoryCache();
      const client = new ApolloClient({
        cache,
        link: ApolloLink.empty(),
        resolvers: {},
      });

      cache.writeData({
        data: {
          foo: {
            bar: 'yo',
            __typename: 'Foo',
          },
        },
      });

      return client.query({ query }).then(({ data }) => {
        expect({ ...data }).toMatchObject({
          fie: { bar: 'yo', __typename: 'Foo' },
        });
github apollographql / apollo-client / packages / apollo-client / src / __tests__ / ApolloClient.ts View on Github external
expect(() => {
        new ApolloClient({ link: ApolloLink.empty() } as any);
      }).toThrowErrorMatchingSnapshot();
    });