Skip to content

Optionally provide callback for MockedReponse.results #8981

Open
@Samigirma1

Description

@Samigirma1

Hello! 😊

I was trying to use the MockedProvider to test a connected component. However, there's no way for me to use the variables from the query to generate a dynamic response. Would it be possible to add this feature for the mock provider?

Alternatively, the mock prop can be a object with a signature like....

// This is probably an incorrect typed definition :)
{
 callback: (
     request: DocumentNode | TypedDocumentNode<TData, TVariables>,
     variables?:  TVariables,
     addTypeName?: boolean,
   ) => {
       result?: FetchResult<TData>,
       error?: ApolloError
     },
 delay?: number |
   (
     (request?: DocumentNode | TypedDocumentNode<TData, TVariables>,
       variables?:  { [key: string]: any }) => number)
} |
 ReadonlyArray<MockedResponse>

It will use the request and its variables to create a dynamic server response. If provided, it would also delay the response by number of milliseconds specified by the delay. If delay is a callback, it will calculate the delay amount using the request and variables for each request.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions