Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AS4 regression: cannot set HTTP headers or status from gateway #7069

Closed
glasser opened this issue Oct 21, 2022 · 0 comments · Fixed by #7071
Closed

AS4 regression: cannot set HTTP headers or status from gateway #7069

glasser opened this issue Oct 21, 2022 · 0 comments · Fixed by #7071

Comments

@glasser
Copy link
Member

glasser commented Oct 21, 2022

The compatibility layer between AS4 and the gateway interface used by @apollo/gateway ignores any HTTP headers or status codes that might be set by the gateway (say, by a GraphQLDataSource).

import {ApolloServer as AS4 } from '@apollo/server';
import {startStandaloneServer} from '@apollo/server/standalone'
import { ApolloGateway, RemoteGraphQLDataSource } from '@apollo/gateway';
import { buildSubgraphSchema } from '@apollo/subgraph';
import gql from 'graphql-tag';

const subgraph3 = new AS4({ schema: buildSubgraphSchema({ typeDefs: gql`type Query{x: ID}` }) });
await startStandaloneServer(subgraph3, {listen: {port: 4343}});

const gateway = new ApolloGateway({
  serviceList: [{ name: 's', url: 'http://localhost:4343/' }],
  buildService({ url, name }) {
    return new (class extends RemoteGraphQLDataSource {
      willSendRequest( options) {
        if (options.kind === 'incoming operation') {
          options.incomingRequestContext.response.http.headers.set('x-foo', 'bar');
        }
      }
    })({
      url,
    });
  }
});

const supergraph3 = new AS4({ gateway });
await startStandaloneServer(supergraph3, {listen: {port: 4344}});

Run {x}. The equivalent AS3 code sets the x-foo header but AS4 does not.

I know how to fix this but it'll have to wait until next week.

glasser added a commit that referenced this issue Oct 24, 2022
The shim layer between AS4 and Gateway (which creates an argument for
the Gateway's executor which looks like AS3's GraphQLRequestContext) did
not copy changes to response headers or HTTP status back to the real
GraphQLRequestContext. This PR makes the shimmed HTTP response object
use the real response objects as backing storage.

Fixes #7069.
glasser added a commit that referenced this issue Oct 24, 2022
…ata (#7071)

The shim layer between AS4 and Gateway (which creates an argument for
the Gateway's executor which looks like AS3's GraphQLRequestContext) did
not copy changes to response headers or HTTP status back to the real
GraphQLRequestContext. This PR makes the shimmed HTTP response object
use the real response objects as backing storage.

Fixes #7069.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant