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

Apollo testing - query finish event #2537

Closed
asfernandes opened this issue Apr 6, 2019 · 1 comment
Closed

Apollo testing - query finish event #2537

asfernandes opened this issue Apr 6, 2019 · 1 comment

Comments

@asfernandes
Copy link

When using apollo-server-express, I open the context (a database connection) that needs to be closed. So I do it in this way:

const server = new ApolloServer({
    schema,
    context: (req: express.Request) => req.res.locals.context
});

const app = express();

app.use((req, res, next) => {
    logger.debug('Query start');
    res.locals.context = new Context();

    next();

    res.on("finish", () => {
        logger.debug('Query finish');
        const context: Context = res.locals.context;
        context.connection.close();
    });
});

server.applyMiddleware({ app });

When using createTestClient of apollo-server-testing I do not known how to close it. Here is the code:

const server = new ApolloServerBase({
    schema,
    context: () => new Context()    //// FIXME: not closing
});

const client = createTestClient(server);

So the database connection is not closed. How to have a hook/event informing that execution ended?

Also looking into the code, it seems the context function is called many times, so I'm not sure it's the way to put a resource into the testing server.

I don't found anything in the documentation regarding that matter.

@zionts zionts added the 🚧👷‍♀️👷‍♂️🚧 in triage Issue currently being triaged label Jul 8, 2019
@zionts
Copy link
Contributor

zionts commented Jul 8, 2019

The new request pipeline that's in progress has support for setting up lifecycle hooks for opening and closing database connections both on server startup and during request handling in Apollo Server 3.0 roadmap (#2360). You can see the WIP documentation for these lifecycle hooks and try them out, too! We're going to be tracking these features on the roadmap item rather than spreading them out over issues, so I'll close this out for now. Thank you for the report!

@zionts zionts closed this as completed Jul 8, 2019
@abernix abernix removed 🚧👷‍♀️👷‍♂️🚧 in triage Issue currently being triaged labels Jul 9, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 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

3 participants