Skip to content

Commit

Permalink
Bugfix/make normalize method function (#113)
Browse files Browse the repository at this point in the history
Fix lint broken by 78b9f2b
  • Loading branch information
chuksynaza authored Sep 28, 2021
1 parent 78b9f2b commit 2e57d1a
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ const observableWithError = (error: Error): Observable<FetchResult> =>
observer.error(error)
})

/**
* Normalizes a WildcardMockedResponse removing @client directives from query
*/
const normalizeMockedResponse = (
mockedResponse: WildcardMockedResponse,
): WildcardMockedResponse => {
const newMockedResponse = { ...mockedResponse }
const newQuery = removeClientSetsFromDocument(newMockedResponse.request.query)
if (newQuery) {
newMockedResponse.request.query = newQuery
}
return newMockedResponse
}

/**
* Extends MockLink to provide the ability to match request queries independent
* of their variables and have them match 1 or more responses. Also stores the
Expand Down Expand Up @@ -188,28 +202,11 @@ export class WildcardMockLink extends ApolloLink {
}

mockedResponses.forEach((mockedResponse) => {
const normalizedMockResponse =
this.normalizeMockedResponse(mockedResponse)
const normalizedMockResponse = normalizeMockedResponse(mockedResponse)
this.addMockedResponse(normalizedMockResponse)
})
}

/**
* Normalizes a WildcardMockedResponse removing @client directives from query
*/
private normalizeMockedResponse(
mockedResponse: WildcardMockedResponse,
): WildcardMockedResponse {
const newMockedResponse = { ...mockedResponse }
const newQuery = removeClientSetsFromDocument(
newMockedResponse.request.query,
)
if (newQuery) {
newMockedResponse.request.query = newQuery
}
return newMockedResponse
}

request(op: Operation): Observable<FetchResult> | null {
const opDefNode = op.query.definitions.find(isOperationDefinitionNode)
const operationType = opDefNode?.operation
Expand Down

0 comments on commit 2e57d1a

Please sign in to comment.