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

Docs for request lifecycle end hooks and responseForOperation #3475

Merged
merged 2 commits into from
Dec 30, 2019

Conversation

nwalters512
Copy link
Contributor

This PR builds on #2008 and adds documentation for request lifecycle event end hooks and the new responseForOperation event.

@apollo-cla
Copy link

@nwalters512: 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/

@abernix abernix merged commit 6bf16d4 into apollographql:master Dec 30, 2019
@abernix
Copy link
Member

abernix commented Dec 30, 2019

Thanks so much!

@DoctorVoid
Copy link

DoctorVoid commented Mar 25, 2020

@nwalters512
Can someone show how can I override the response promise by using responseForOperation?

It seems that if I try to return anything other than null from this hook, It results in a weird infinite loop inside the request pipeline.

This results in a never ending request (regardless if its an async promise or what type or result):

public responseForOperation(
        requestContext: GraphQLRequestContext<PolarisGraphQLContext> &
            Required<Pick<GraphQLRequestContext<PolarisGraphQLContext>,
                'metrics' | 'source' | 'document' | 'operationName' | 'operation'>>,
    ): Promise<GraphQLResponse | null> | GraphQLResponse | null {
        return new Promise(async () => {
            const result = await this.someOtherRequest()
            return result;
        });
    }

This is fine, but doesn't overrides the original request

public responseForOperation(
        requestContext: GraphQLRequestContext<PolarisGraphQLContext> &
            Required<Pick<GraphQLRequestContext<PolarisGraphQLContext>,
                'metrics' | 'source' | 'document' | 'operationName' | 'operation'>>,
    ): Promise<GraphQLResponse | null> | GraphQLResponse | null {
        return null;
    }

@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

Successfully merging this pull request may close these issues.

4 participants