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

expose ApolloServerOptions interfaces #7311

Merged

Conversation

axe-me
Copy link
Contributor

@axe-me axe-me commented Jan 17, 2023

Hi there,

I'm developing an in-house graphql framework wrapping around the apollo server. In the framework, I'm trying to create different types (gateway, subgraph or standalone) of apollo server based on some config. Thus the framework need access to all these interfaces.

Thanks for reviewing this PR.

Cheers.

@apollo-cla
Copy link

@axe-me: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@netlify
Copy link

netlify bot commented Jan 17, 2023

Deploy Preview for apollo-server-docs failed.

Built without sensitive environment variables

Name Link
🔨 Latest commit 1cb8989
🔍 Latest deploy log https://app.netlify.com/sites/apollo-server-docs/deploys/63c856bf40fa60000858518e

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 17, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1cb8989:

Sandbox Source
Apollo Server Typescript Configuration
Apollo Server Configuration

@trevor-scheer
Copy link
Member

Thanks for the PR @axe-me!

Is it safe to assume the exported ApolloServerOptions union of all of the types you're interested in is sufficient but cumbersome to work with? I'm interested to know why you need the individual types (maybe your API needs to expose just a subset of this union to your users, or the types are useful internally?). Either way this seems pretty reasonable to me, especially given that we're already exporting the top-level union.

@glasser explicitly removed their exports before we landed v4 in this PR: #6551, motivation unclear (possibly just to limit the API surface area by default, then expose if needed later like now). I'd be interested to hear if he had any motivation to keep the types private.

@glasser
Copy link
Member

glasser commented Jan 17, 2023

I think it was just "felt internal". If it's genuinely useful, it's probably fine to add back (with a quick double-check-that-we-like-the-names-enough-to-commit pass).

@axe-me
Copy link
Contributor Author

axe-me commented Jan 17, 2023

@trevor-scheer @glasser Thanks for reviewing this PR. My use case is like this:

export type CreateSubgraphServerOptions = Partial<ApolloServerOptions<AxeAppContext>> & {
  serverType: 'subgraph'
  // ...extra fields
};

export type CreateStnadaloneServerOptions = Partial<ApolloServerOptions<AxeAppContext>> & {
  serverType: 'standalone'
  // ....extra fields
};

export type CreateGatewayServerOptions = Partial<ApolloServerOptions<AxeAppContext>> & {
  serverType: 'gateway'
  // ...extra fields
};
export type CreateServerOptions = CreateSubgraphServerOptions | CreateStnadaloneServerOptions | CreateGatewayServerOptions;

in my create server function I have code to narrowing types and create different types of apollo servers:

switch (args.options.serverType) {
  case 'subgraph':
    server = await createSubgraphServer(args.options);
    break;
  case 'gateway':
    server = await createGatewayServer(args.options);
    break;
  case 'standalone':
    server = await createStandaloneServer(args.options);
    break;
  default:
    throw new Error('Unknown server type');
  }

Note that right now I have to wrap around ApolloServerOptions with Partial helper as a workaround to prevent ts complaining about the field missing. But this is not ideal. Ideally, I can do this:

interface CreateGatewayServerOptions extends ApolloServerOptionsWithGateway<Context> {
  serverType: 'gateway'
  // ... extra fields
} 

@trevor-scheer trevor-scheer merged commit 322b5eb into apollographql:main Jan 18, 2023
@github-actions github-actions bot mentioned this pull request Jan 18, 2023
trevor-scheer pushed a commit that referenced this pull request Jan 19, 2023
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @apollo/server-integration-testsuite@4.3.1

### Patch Changes

- [#7285](#7285)
[`35fa72bdd`](35fa72b)
Thanks [@glasser](https://github.com/glasser)! - Adds an integration
test verifying that Rover's introspection query works. This should not
break any integration that passes other tests.

- [#7276](#7276)
[`15c912f4c`](15c912f)
Thanks [@renovate](https://github.com/apps/renovate)! - Update
graphql-http dependency

- Updated dependencies
\[[`ec28b4b33`](ec28b4b),
[`322b5ebbc`](322b5eb),
[`3b0ec8529`](3b0ec85)]:
    -   @apollo/server@4.3.1

## @apollo/server@4.3.1

### Patch Changes

- [#7313](#7313)
[`ec28b4b33`](ec28b4b)
Thanks [@vtipparam](https://github.com/vtipparam)! - Allow case
insensitive lookup on headers. Use HeaderMap instead of plain Map for
headers in expressMiddleware.

- [#7311](#7311)
[`322b5ebbc`](322b5eb)
Thanks [@axe-me](https://github.com/axe-me)! - Export intermediate
ApolloServerOptions\* types

- [#7274](#7274)
[`3b0ec8529`](3b0ec85)
Thanks [@patrick91](https://github.com/patrick91)! - The subgraph spec
has evolved in Federation v2 such that the type of
`_Service.sdl` (formerly nullable) is now non-nullable. Apollo Server
now
    detects both cases correctly in order to determine whether to:
    1.  install / enable the `ApolloServerPluginInlineTrace` plugin
2. throw on startup if `ApolloServerPluginSchemaReporting` should not be
installed
3. warn when `ApolloServerPluginUsageReporting` is installed and
configured with the `__onlyIfSchemaIsNotSubgraph` option

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@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 this pull request may close these issues.

None yet

5 participants