How to use the apollo-server-env.Response function in apollo-server-env

To help you get started, we’ve selected a few apollo-server-env 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-server / packages / apollo-datasource-rest / src / HTTPCache.ts View on Github external
);
    }

    const { policy: policyRaw, ttlOverride, body } = JSON.parse(entry);

    const policy = CachePolicy.fromObject(policyRaw);
    // Remove url from the policy, because otherwise it would never match a request with a custom cache key
    policy._url = undefined;

    if (
      (ttlOverride && policy.age() < ttlOverride) ||
      (!ttlOverride &&
        policy.satisfiesWithoutRevalidation(policyRequestFrom(request)))
    ) {
      const headers = policy.responseHeaders();
      return new Response(body, {
        url: policy._url,
        status: policy._status,
        headers,
      });
    } else {
      const revalidationHeaders = policy.revalidationHeaders(
        policyRequestFrom(request),
      );
      const revalidationRequest = new Request(request, {
        headers: revalidationHeaders,
      });
      const revalidationResponse = await this.httpFetch(revalidationRequest);

      const { policy: revalidatedPolicy, modified } = policy.revalidatedPolicy(
        policyRequestFrom(revalidationRequest),
        policyResponseFrom(revalidationResponse),
github apollographql / apollo-server / packages / apollo-datasource-rest / src / HTTPCache.ts View on Github external
const body = await response.text();
    const entry = JSON.stringify({
      policy: policy.toObject(),
      ttlOverride,
      body,
    });

    await this.keyValueCache.set(cacheKey, entry, {
      ttl,
    });

    // We have to clone the response before returning it because the
    // body can only be used once.
    // To avoid https://github.com/bitinn/node-fetch/issues/151, we don't use
    // response.clone() but create a new response from the consumed body
    return new Response(body, {
      url: response.url,
      status: response.status,
      statusText: response.statusText,
      headers: response.headers,
    });
  }
}
github apollographql / apollo-server / packages / apollo-server-cloudflare / src / cloudflareApollo.ts View on Github external
({ graphqlResponse, responseInit }) =>
        new Response(graphqlResponse, responseInit),
      (error: HttpQueryError) => {
github apollographql / apollo-server / packages / apollo-server-cloudflare / src / cloudflareApollo.ts View on Github external
(error: HttpQueryError) => {
        if ('HttpQueryError' !== error.name) throw error;

        const res = new Response(error.message, {
          status: error.statusCode,
          headers: error.headers,
        });

        return res;
      },
    );
github apollographql / apollo-server / packages / apollo-datasource-rest / src / HTTPCache.ts View on Github external
} else {
      const revalidationHeaders = policy.revalidationHeaders(
        policyRequestFrom(request),
      );
      const revalidationRequest = new Request(request, {
        headers: revalidationHeaders,
      });
      const revalidationResponse = await this.httpFetch(revalidationRequest);

      const { policy: revalidatedPolicy, modified } = policy.revalidatedPolicy(
        policyRequestFrom(revalidationRequest),
        policyResponseFrom(revalidationResponse),
      );

      return this.storeResponseAndReturnClone(
        new Response(modified ? await revalidationResponse.text() : body, {
          url: revalidatedPolicy._url,
          status: revalidatedPolicy._status,
          headers: revalidatedPolicy.responseHeaders(),
        }),
        request,
        revalidatedPolicy,
        cacheKey,
        options.cacheOptions,
      );
    }
  }

apollo-server-env

This package is used internally by Apollo Server and not meant to be consumed directly.

MIT
Latest version published 3 years ago

Package Health Score

72 / 100
Full package analysis