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

Using this in an Apollo Gateway without schema #70

Closed
rouralberto opened this issue Dec 21, 2021 · 2 comments
Closed

Using this in an Apollo Gateway without schema #70

rouralberto opened this issue Dec 21, 2021 · 2 comments

Comments

@rouralberto
Copy link

Hi, I'm using this amazing package to control the queries in our federated ApolloGateway. The problem comes when, following the examples, I always see the schema object passed to the new ApolloServer constructor and, we don't have the schema available at Gateway level.

I would prefer to keep this cost analyser in the Gateway to avoid repeating the config in all the sub ApolloServers we have.

Is there any way to achieve this? Is there something super obvious I'm missing?

The code I'm using is:

export async function bootstrap() {
  const gateway = createApolloGateway();
  const apolloServer = new ApolloServer({
    gateway,
    plugins: [logErrorPlugin],
    introspection: (process.env.INTROSPECTION === 'true'),
    debug: (process.env.DEBUG === 'true'),
    formatError: (err) => {
    // Don't give the specific errors to the client.
    if (err.extensions.code.startsWith('DOWNSTREAM_SERVICE_ERROR')) {
      return new Error('Internal server error from subgraph ' + err.extensions.serviceName + '.  Logs are in datadog');
    }
    return err;
  },

    context: ({ req }) => {
      // Get the user token from the headers
      // Try to retrieve a user with the token
      // Add the user ID to the context
      return { req };
    },
  });
  await apolloServer.start();

  const app = express();

  configExpress(app);
  configApolloServer(apolloServer, app);

  const server = await start(app, config.port);
  attachGracefulHandlers(server);

  return { server, app };
}
@ivome
Copy link
Collaborator

ivome commented Dec 21, 2021

You need the schema to run the validation. I am not that familiar with Apollo Server, but looks like you should be able to build a plugin that uses this library here:

Here you could get the schema:
https://www.apollographql.com/docs/apollo-server/integrations/plugins-event-reference/#schemadidloadorupdate

Here's a thread with some more examples that might help:
#7

@rouralberto
Copy link
Author

Thank you @ivome for the answer. I'll keep digging to see the best way to get the schema from within a plugin. Those links helped =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants