Skip to content

Commit 7cad705

Browse files
committed
Updated the graphql documentation titles and note
1 parent 35965fd commit 7cad705

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

documentation/graphql.md

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,23 @@ nav_order: 18
88
# GraphQL
99

1010
<!-- TOC -->
11-
* [GraphQL](#graphql)
12-
* [Introduction](#introduction)
13-
* [What Can You Achieve with Specmatic's GraphQL Support?](#what-can-you-achieve-with-specmatics-graphql-support)
14-
* [Quick start with sample projects](#quick-start-with-sample-projects)
15-
* [Starting a stub/mock server](#starting-a-stubmock-server)
16-
* [Customizing stub/mock server](#customizing-stubmock-server)
17-
* [Returning custom responses](#returning-custom-responses)
18-
* [Providing custom examples dir](#providing-custom-examples-dir)
19-
* [Deep dive into examples](#deep-dive-into-examples)
20-
* [HTTP Headers](#http-headers)
21-
* [GraphQL Variables](#graphql-variables)
22-
* [Delayed responses](#delayed-responses)
23-
* [Dynamic Field Selection from Example Responses](#dynamic-field-selection-from-example-responses)
24-
* [Multi-Query Requests](#multi-query-requests)
25-
* [Steps to Try Out Multi-Query Requests](#steps-to-try-out-multi-query-requests)
26-
* [GraphQL Scalar Types](#graphql-scalar-types)
27-
* [Running contract tests](#running-contract-tests)
28-
* [Using your GraphQL files as your API Contracts from Central Contract Repository](#using-your-graphql-files-as-your-api-contracts-from-central-contract-repository)
11+
- [GraphQL](#graphql)
12+
- [Introduction](#introduction)
13+
- [What Can You Achieve with Specmatic's GraphQL Support?](#what-can-you-achieve-with-specmatics-graphql-support)
14+
- [Quick start with sample projects](#quick-start-with-sample-projects)
15+
- [Starting a stub server](#starting-a-stub-server)
16+
- [Stubbing out specific values using example data](#stubbing-out-specific-values-using-example-data)
17+
- [Providing a custom examples directory](#providing-a-custom-examples-directory)
18+
- [Example file file format](#example-file-file-format)
19+
- [HTTP Headers](#http-headers)
20+
- [GraphQL Variables](#graphql-variables)
21+
- [Delayed responses](#delayed-responses)
22+
- [Dynamic Field Selection from Example Responses](#dynamic-field-selection-from-example-responses)
23+
- [Multi-Query Requests](#multi-query-requests)
24+
- [Steps to Try Out Multi-Query Requests](#steps-to-try-out-multi-query-requests)
25+
- [GraphQL Scalar Types](#graphql-scalar-types)
26+
- [Running contract tests](#running-contract-tests)
27+
- [Using your GraphQL files as your API Contracts from Central Contract Repository](#using-your-graphql-files-as-your-api-contracts-from-central-contract-repository)
2928
<!-- TOC -->
3029

3130
## Introduction
@@ -50,13 +49,13 @@ Here are sample projects in different languages and frameworks that demonstrate
5049

5150
README of each of these projects include
5251
* detailed animated architecture diagram
53-
* instructions on how to start stub/mock server using graphql spec with custom examples, simulating delays, errors etc.
52+
* instructions on how to start stub server using graphql spec with custom examples, simulating delays, errors etc.
5453
* instructions on how to isolate the System Under Test when running contract tests
5554
* example CI workflow setups using GitHub Actions
5655

57-
## Starting a stub/mock server
56+
## Starting a stub server
5857

59-
To start a stub/mock server using Specmatic, you can use the following steps:
58+
To start a stub server using Specmatic, you can use the following steps:
6059

6160
**Step 1: Create a graphql SDL file**
6261

@@ -82,7 +81,7 @@ type Product {
8281
}
8382
```
8483

85-
**Step 2: Start the stub/mock server**
84+
**Step 2: Start the stub server**
8685

8786
Run the following command to start the GraphQL stub:
8887

@@ -122,9 +121,7 @@ You will receive a response with a random product ID, name, inventory, and type
122121
}
123122
```
124123

125-
## Customizing stub/mock server
126-
127-
### Returning custom responses
124+
## Stubbing out specific values using example data
128125

129126
Above, we saw Specmatic generating random output based on the provided `product-api.graphql` spec. Instead, in order to receive specific example values, you can create an example YAML files containing specific data for `findAvailableProducts` query.
130127

@@ -156,10 +153,11 @@ response: [
156153
}
157154
]
158155
```
156+
159157
{: .note}
160158
**Note:** Keep the file `product-api.graphql` and directory `product-api_examples` at same level.
161159

162-
**Step 2: Start the stub/mock server**
160+
**Step 2: Start the stub server**
163161

164162
Run the following command to start the GraphQL stub:
165163

@@ -201,11 +199,11 @@ This time though, you will receive a response with the specified example defined
201199
}
202200
```
203201

204-
#### Providing custom examples dir
202+
#### Providing a custom examples directory
205203

206204
By convention, Specmatic automatically loads all examples defined for the GraphQL SDL file, say `<graphql_sdl_filename>.graphql`, from a colocated directory called `<graphql_sdl_filename>_examples`. However, in case your examples are in a different directory, you can pass it as an argument programmatically or through CLI args while running tests or service virtualization.
207205

208-
### Deep dive into examples
206+
#### Example file file format
209207

210208
Let us now take deeper look at the external example format.
211209
* At the top level we have two YAML root nodes called `request` and `response`
@@ -214,7 +212,7 @@ Let us now take deeper look at the external example format.
214212
* `headers`: you can add your `HTTP` headers here
215213
* `response` holds responses with JSON syntax for readability, syntax highlighting and also as an aid to copy and paste of real responses from actual application logs etc.
216214

217-
#### HTTP Headers
215+
## HTTP Headers
218216

219217
Although GraphQL SDL files do not support HTTP request headers, you may directly add them to your Specmatic example files in `httpHeaders` under the `request` key, as seen in the example yaml below. The headers will be leveraged if present both by the contract tests as well as service virtualization.
220218

@@ -243,7 +241,7 @@ response: [
243241
]
244242
```
245243

246-
#### GraphQL Variables
244+
## GraphQL Variables
247245

248246
Specmatic supports usage of GraphQL variables seamlessly. You only need to make sure that the externalised example is structured such that it uses the actual field values inline instead of variables in the query. Here is an example.
249247

@@ -290,7 +288,7 @@ response: [
290288
{: .note}
291289
**Note**: It is recommended to specify the type of the variable e.g. `$pageSize: Int!`. If the type is not specified explicitly you may face some issues since Specmatic will implicitly cast the variable to a certain type which may be invalid sometimes.
292290

293-
### Delayed responses
291+
## Delayed responses
294292

295293
To simulate delay in the response, you can use the `delay-in-milliseconds` key in your example YAML file. For example:
296294

@@ -319,10 +317,11 @@ response: [
319317
]
320318

321319
delay-in-milliseconds: 5000
322-
````
320+
```
321+
323322
This will introduce a 5-second delay before the response is sent back to the client.
324323
325-
### Dynamic Field Selection from Example Responses
324+
## Dynamic Field Selection from Example Responses
326325
327326
When running a GraphQL stub using Specmatic, you can provide an example query that includes all possible fields and sub-selections. Specmatic uses this example to generate the stub response.
328327
@@ -464,7 +463,7 @@ Here are some simple steps to try this out:
464463
---
465464
This setup allows you to test how Specmatic reuses the example provided, adapting the response to the requested fields.
466465

467-
### Multi-Query Requests
466+
## Multi-Query Requests
468467

469468
The Specmatic GraphQL stub server supports multi-query requests, allowing you to send a single request with multiple queries and receive a consolidated response. This feature is useful when you want to retrieve data from different queries in a single API call. Additionally, **multi-query requests with variables** are supported, making it flexible for dynamic requests.
470469

@@ -654,7 +653,7 @@ This request showcases how Specmatic's GraphQL stub server can process multi-que
654653

655654
This example demonstrates how Specmatic processes multiple queries in a single request and returns the expected responses for each query. You can adapt this setup for various use cases, leveraging the existing folder structure for organizing examples.
656655

657-
### GraphQL Scalar Types
656+
## GraphQL Scalar Types
658657

659658
In GraphQL, you can define [custom scalar types](https://graphql.org/learn/schema/#scalar-types) to handle specialized data, such as dates or monetary values, that require specific serialization and deserialization logic. For example:
660659

0 commit comments

Comments
 (0)