Hello Everyone, I'm mocking a graphql API using wi...
# help
d
Hello Everyone, I'm mocking a graphql API using wiremock. I'm using the graphql Extension for wiremock. My request body looks something like this (variables\":{\"storesIds\":[3888],\"startDate\":\"2023-12-10\",\"endDate\":\"2023-12-16\")and when I create the mapping file for this query, it seems like it has to be an exact match for the Variables and Query, the variables change based on the week that we are on so I'm not sure how to make this a dynamic mock irrespective of the start and end date. Please refer to the screenshots and advise. Note: I'm using the standalone jar for the extension and running wiremock on a docker container - If needed I can send the docker config.
b
I’ve not used the GraphQL extension yet, so I don’t know if it supports all the matchers that WireMock supports. In WireMock, there is a way to match on dates and times: https://wiremock.org/docs/request-matching/#dates-and-times My first question, though, would be: do you even need to match on the dates, too? Is just the ID not enough? It would make your mocks easier to write and maintain..
d
Thanks @Bas Dijkstra for the response. I was trying to do something like this but it didn't work. (variables":{"storesIds":[([-\w])+],"startDate":"([-\w])+","endDate":"([-\w])+") The thing is it looks for a exact match and doesn't match if the date has regex or any helpers in them.
b
Hmm.. As I said, I've not used the GraphQL extension myself. Do you really need to match on the dates?
d
The graphql URL and headers are similar for all the requests, the request varies on the Variables and the query, and for a particular query call the variables vary based on what is queried. So this week the start date and end date would be 10-dec-2023 & 16-Dec-2023, Next week it will be 17-Dec-2023 & 24-Dec-2023 and so on. https://oleg-nenashev.github.io/wiremock.org/docs/graphql-extension/docs/MatchStrategy/#queries
b
Yes, I see, but that wasn’t my question. Isn’t just matching on the store ID not enough? Do you need to supply different responses for the same store ID for different dates? If not you could just forget about the dates.
d
Yes the issue is with the request matching. If I ignore the dates then the matcher doesn't work.
b
OK. You'll have to ask someone who has experience with the GraphQL extension then.