How to use the apollo-server-env.Request 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-server-testing / src / ApolloServer.ts View on Github external
operation: string,
    variables?: { [name: string]: string },
    additionalHeaders?: object,
  ) {
    const body = {
      query: operation,
      variables,
    };
    const headers = new Headers({ 'Content-Type': 'application/json' });

    if (additionalHeaders) {
      for (const [name, value] of new Headers(additionalHeaders)) {
        headers.append(name, value);
      }
    }
    const request = new Request('http://localhost', {
      method: 'POST',
      headers,
      body: JSON.stringify(body),
    });

    // create the options and run the operation
    const options = this.createGraphQLServerOptions.bind(this);
    const response = await graphqlTesting(options)(request);

    // parse response and return
    const contentType = response.headers.get('Content-Type');
    if (contentType && contentType.startsWith('application/json')) {
      return response.json();
    } else {
      return response.text();
    }
github apollographql / apollo-server / packages / apollo-server-core / src / nodeHttpToRequest.ts View on Github external
export function convertNodeHttpToRequest(req: IncomingMessage): Request {
  const headers = new Headers();
  Object.keys(req.headers).forEach(key => {
    const values = req.headers[key]!;
    if (Array.isArray(values)) {
      values.forEach(value => headers.append(key, value));
    } else {
      headers.append(key, values);
    }
  });

  return new Request(req.url!, {
    headers,
    method: req.method,
  });
}
github apollographql / apollo-server / packages / apollo-datasource-rest / src / HTTPCache.ts View on Github external
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),
      );

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

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