Skip to content

Commit

Permalink
Update README file with instructions on how to test the stub
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshnikam671 committed Oct 8, 2024
1 parent de85a4a commit 2da1138
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 55 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,32 @@ npm test
npm run specmatic:stub
```

### Testing the Specmatic stub

Use the following curl commands to test if the stub is working as expected -

1. Simple query
```shell
curl -X POST http://localhost:8080/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "query { findAvailableProducts(type: gadget, pageSize: 10) { id name inventory type } }"
}'
```

2. Query with variables
```shell
curl -X POST http://localhost:8080/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "query FindAvailableProducts($type: ProductType!, $pageSize: Int!) { findAvailableProducts(type: $type, pageSize: $pageSize) { id name inventory type } }",
"variables": {
"type": "gadget",
"pageSize": 10
}
}'
```

### Start the application

```shell
Expand Down
24 changes: 0 additions & 24 deletions graphl_examples/createProduct.md

This file was deleted.

28 changes: 0 additions & 28 deletions graphl_examples/findAvailableProductsTest.md

This file was deleted.

22 changes: 22 additions & 0 deletions graphql_examples/createProduct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
request:
body: |
mutation {
createProduct(newProduct: {
name: "The Almanac",
inventory: 10,
type: book
}) {
id
name
inventory
type
}
}
response:
{
"id": "10",
"name": "The Almanac",
"inventory": 10,
"type": "book"
}

24 changes: 24 additions & 0 deletions graphql_examples/findAvailableProductsTest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
request:
body: |
query {
findAvailableProducts(type: gadget, pageSize: 10) {
id
name
inventory
type
}
}
response: [
{
"id": "10",
"name": "The Almanac",
"inventory": 10,
"type": "book"
},
{
"id": "20",
"name": "iPhone",
"inventory": 15,
"type": "gadget"
}
]
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"test": "react-scripts test --coverage --detectOpenHandles --forceExit --transformIgnorePatterns \"node_modules/(?!axios)/\"",
"eject": "react-scripts eject",
"graphiql": "node graphiql-server.js",
"specmatic:stub": "java -jar node_modules/specmatic-beta/graphql/specmatic-graphql-all.jar stub --port 8080",
"specmatic:stub": "java -jar node_modules/specmatic-beta/graphql/specmatic-graphql-all.jar virtualize --port 8080 --examples=graphql_examples",
"test-ci": "cross-env SPECMATIC_LOG_LEVEL=debug DEBUG=specmatic-order-graphql-ui-react:* npm run test"
},
"eslintConfig": {
Expand Down

0 comments on commit 2da1138

Please sign in to comment.