Skip to content

Commit

Permalink
Merge pull request #188 from oleg-nenashev/protocol-docs
Browse files Browse the repository at this point in the history
Add gRPC and GraphQL to the solution pages
  • Loading branch information
oleg-nenashev authored Sep 29, 2023
2 parents 93b1500 + e646032 commit 6f5e8fc
Show file tree
Hide file tree
Showing 15 changed files with 274 additions and 10 deletions.
15 changes: 8 additions & 7 deletions _data/doc-categories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,21 @@ record-playback:
pages:
- record-playback

protocols:
title: Protocols
pages:
- webhooks-and-callbacks
- grpc
- solutions/graphql
- https

configuration:
title: Advanced use-cases
pages:
- https
- multi-domain-mocking
- advanced/deploy-to-servlet-container
- advanced/java7

protocols:
title: Protocols
pages:
- webhooks-and-callbacks
- grpc

extensibility:
title: Extensibility
link: /docs/extending-wiremock/
Expand Down
17 changes: 14 additions & 3 deletions _docs/grpc.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
---
layout: docs
title: gRPC
meta_title: gRPC
title: Mocking gRPC services
meta_title: Mocking gRPC services
description: Mocking gRPC services with WireMock
og_image: solutions/grpc/wiremock_grpc_opengraph.png
header:
image: solutions/grpc/header.png
redirect_from:
- "/grpc.html"
- "/grpc/"
---

WireMock 3.2.0+ supports mocking of gRPC services via an extension.
WireMock 3.2.0+ supports mocking of gRPC services via the
[WireMock extension for gRPC](https://github.com/wiremock/wiremock-grpc-extension).

The extension scans for descriptor files (generated from the service's `.proto` files) in the `grpc` subdirectory of WireMock's root.

Using these, it converts incoming messages to JSON before passing them to WireMock's core stubbing system which allows the existing JSON matchers to be used when matching requests.
It also converts JSON responses back into proto messages so that all of WireMock's response definition features including templating can be used.

<img src="{{ '/images/solutions/grpc/intro_schema.png' | absolute_url }}" alt="WireMock and gRPC schema" style="width: 100%; height: auto; margin-top: 1em;"/>

The extension also adds a Java DSL that works with the Java classes generated by `protoc`, while also providing a more gRPC idiomatic way of defining stubs.

## Java usage
Expand Down Expand Up @@ -163,4 +172,6 @@ gRPC stubs are defined using WireMock's standard JSON format. Requests should al
}
```

## More Demos

For more see the [standalone demo project](https://github.com/wiremock/wiremock-grpc-demos/tree/main/standalone).
31 changes: 31 additions & 0 deletions _docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ <h2>Distributions</h2>
<img src="{{ '/images/logos/technology/helm.svg' | absolute_url }}">
Helm (Experimental)
</a>
<a class="card" href="https://www.wiremock.io/product?utm_medium=referral&utm_sourcewiremock.org&utm_content=docs_nav" target="_blank">
<img src="{{ '/images/wiremock-cloud/wiremock_cloud_favicon.svg' | absolute_url }}">
WireMock Cloud (commercial SaaS)
</a>
</div>

<h2>By use-case</h2>
Expand Down Expand Up @@ -154,6 +158,33 @@ <h2>By use-case</h2>
</a>
</div>

<h2>By protocol</h2>

<p>
WireMock can serve all HTTP-based protocols and REST API.
Through built-in features and extensions,
it provides additional capabilities for widely used protocols.
</p>

<div class="grid-container">
<a class="card" href="./webhooks-and-callbacks">
<img src="{{ '/images/logos/technology/webhooks.svg' | absolute_url }}">
Webhooks and Callbacks
</a>
<a class="card" href="./https">
<img src="{{ '/images/logos/technology/https.svg' | absolute_url }}">
HTTPs
</a>
<a class="card" href="./grpc">
<img src="{{ '/images/logos/technology/grpc.png' | absolute_url }}">
gRPC
</a>
<a class="card" href="./solutions/graphql">
<img src="{{ '/images/logos/technology/graphql.svg' | absolute_url }}">
GraphQL
</a>
</div>

<h2>By technology</h2>

<p>
Expand Down
45 changes: 45 additions & 0 deletions _docs/solutions/graphql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
layout: solution
title: "WireMock and GraphQL"
meta_title: "GraphQL Solutions | WireMock"
description: "Additional solutions for WireMock when using Golang"
logo: /images/logos/technology/graphql.svg
og_image: solutions/graphql/wiremock_graphql_opengraph.png
redirect_from:
- "/graphql.html"
- "/graphql/"
hide-disclaimer: true
---

## WireMock Extension

There is a [GraphQL extension for WireMock](https://github.com/wiremock/wiremock-graphql-extension)
that allows semantically matching GraphQL queries,
regardless of the order of the fields in the original request.
It brings powers of request matching and response templating to the
[GraphQL](https://graphql.org/) query language.

Example:

```kotlin
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock.*
import io.github.nilwurtz.GraphqlBodyMatcher

fun registerGraphQLWiremock(json: String) {
WireMock(8080).register(
post(urlPathEqualTo(endPoint))
.andMatching(GraphqlBodyMatcher.extensionName, GraphqlBodyMatcher.withRequest(json))
.willReturn(
aResponse()
.withStatus(200)
)
)
}
```

## Read More

- [GraphQL API mocking with the new WireMock extension](https://www.wiremock.io/post/graphql-api-mocking-with-the-new-wiremock-extension?utm_medium=referral&utm_source=wiremock.org&utm_content=solution-page)
blogpost by Eiki Hayashi
- [GitHub repository with documentation](https://github.com/wiremock/wiremock-graphql-extension)
8 changes: 8 additions & 0 deletions images/logos/technology/graphql.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/logos/technology/grpc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions images/logos/technology/http.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions images/logos/technology/https.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions images/logos/technology/webhooks.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/solutions/grpc/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/solutions/grpc/intro_schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/solutions/grpc/wiremock-grpc-opengraph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6f5e8fc

Please sign in to comment.