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

The MicroRequest type for apollo-server-micro is not exported correctly #6877

Closed
ChristianIvicevic opened this issue Sep 2, 2022 · 3 comments

Comments

@ChristianIvicevic
Copy link

I was attempting to type the factory for a custom context myself as follows:

import type { MicroRequest } from 'apollo-server-micro';
import { ApolloServer } from 'apollo-server-micro';

const createGraphQLContext = async (args: { req: MicroRequest }) => {
  return { /* ... */ };
};

const apolloServer = new ApolloServer({
  context: createGraphQLContext,
});

According to the docs the type of the argument for the factory should be { req: MicroRequest, res: ServerResponse } however the MicroRequest type is not accesible as it is not exported from the root of the package.

@glasser
Copy link
Member

glasser commented Sep 2, 2022

Out of curiosity, do you actually use micro? Or are you merely using apollo-server-micro because a NextJS example inexplicably uses it despite the fact that NextJS is not built on top of Micro?

@ChristianIvicevic
Copy link
Author

ChristianIvicevic commented Sep 2, 2022

Your second assumption is correct. I saw the use of apollo-server-micro documented in the Nexus documentation and was skeptical after following the docs of the transitive dependencies and seeing that micro itself has the disclaimer about Vercel in their readme.

An acquaintance guided me to your own PR using apollo-server-express that hasn't been merged yet: vercel/next.js#30082

After trying to get it running myself there were different problems with newer versions of Next not allowing for top-level awaits (v12 and SWC seem to have dropped that) and generally missing typings for other parts used within the PR.

Eventually I continued using the micro version which seems to work completely fine so far.

@glasser
Copy link
Member

glasser commented Sep 8, 2022

I guess you can just copy the MicroRequest type from https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-micro/src/types.ts

We will be releasing Apollo Server 4 soon at which point any Micro integration can be maintained by community members that actually use Micro (although as far as we can tell, nobody actually uses Micro and people who use apollo-server-micro are only using it due to the Next.JS example). Adding more functionality to this dead-end package is not a priority at this time.

Note that AS4 has more explicit APIs for supporting server environments such as Next.JS which don't allow for a standard "startup might fail and you shouldn't start handling requests until after startup has succeeded" flow, so I should be able to replace that PR with one that they hopefully will merge.

@glasser glasser closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 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

No branches or pull requests

2 participants