Skip to content

Commit

Permalink
feat: add example folder
Browse files Browse the repository at this point in the history
  • Loading branch information
smyrick committed Oct 2, 2024
1 parent 3c5cfad commit 3c2cacf
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 11 deletions.
7 changes: 7 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Example

This small example starts up using the `latest` docker image. Feel free to edit the config locally and try for yourself.

* Run `./config-schema.sh` to generate a new config json file to help with YAML autocomplete
* Run `./start.sh` to quickly run the latest image with all the config files in the local folder

203 changes: 203 additions & 0 deletions example/config-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Config",
"type": "object",
"required": [
"common",
"endpoints"
],
"properties": {
"common": {
"description": "The common configuration for the server",
"allOf": [
{
"$ref": "#/definitions/ServerConfig"
}
]
},
"endpoints": {
"description": "The list of endpoints that the server should expose",
"type": "array",
"items": {
"$ref": "#/definitions/Endpoint"
}
}
},
"definitions": {
"Endpoint": {
"type": "object",
"required": [
"path",
"pq_id"
],
"properties": {
"body_params": {
"description": "The body parameters that the endpoint should accept",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/Parameter"
}
},
"method": {
"description": "The method that the endpoint should accept",
"default": "GET",
"allOf": [
{
"$ref": "#/definitions/HttpMethod"
}
]
},
"path": {
"description": "The path that the endpoint should be exposed on",
"type": "string"
},
"path_arguments": {
"description": "The path arguments that the endpoint should accept",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/Parameter"
}
},
"pq_id": {
"description": "The persisted query ID that the endpoint should use",
"type": "string"
},
"query_params": {
"description": "The query parameters that the endpoint should accept",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/Parameter"
}
}
}
},
"HttpMethod": {
"description": "The HTTP method for the endpoint to accept",
"type": "string",
"enum": [
"GET",
"POST",
"PUT",
"PATCH",
"DELETE"
]
},
"LogLevel": {
"description": "The log level that the server should use",
"type": "string",
"enum": [
"trace",
"debug",
"info",
"warn",
"error"
]
},
"Logging": {
"type": "object",
"properties": {
"format": {
"description": "The format that the logs should be output in",
"default": "pretty",
"type": "string"
},
"level": {
"description": "The log level that the server should use",
"default": "info",
"allOf": [
{
"$ref": "#/definitions/LogLevel"
}
]
}
}
},
"ParamKind": {
"description": "The kind of parameter that is expected if it is not a string",
"type": "string",
"enum": [
"int",
"string",
"float",
"object",
"array",
"boolean"
]
},
"Parameter": {
"type": "object",
"required": [
"from"
],
"properties": {
"from": {
"description": "The parameter name that the user will use; e.g. `id` in `/user/:id` or /user/?id=1234",
"type": "string"
},
"kind": {
"description": "The kind of parameter that is expected if it is not a string",
"default": "string",
"allOf": [
{
"$ref": "#/definitions/ParamKind"
}
]
},
"required": {
"description": "Whether the parameter is required or not; by default it is false",
"default": false,
"type": "boolean"
},
"to": {
"description": "If the operation uses a different name, this is the name the variable should be renamed to",
"type": [
"string",
"null"
]
}
}
},
"ServerConfig": {
"type": "object",
"required": [
"graphql_endpoint"
],
"properties": {
"graphql_endpoint": {
"description": "The GraphQL endpoint the server will forward requests to",
"type": "string"
},
"listen": {
"description": "The address that the server should listen on",
"default": "127.0.0.1:4000",
"type": "string"
},
"logging": {
"description": "Basic logging configuration",
"anyOf": [
{
"$ref": "#/definitions/Logging"
},
{
"type": "null"
}
]
},
"path_prefix": {
"description": "The prefix for the endpoints the server should use; defaults to `/api/v1`",
"default": "/api/v1",
"type": "string"
}
}
}
}
}
2 changes: 1 addition & 1 deletion example/config-schema.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker run ghcr.io/apollosolutions/persisted-query-to-rest:v0.3.2 config-schema > config-schema.json
docker run ghcr.io/apollosolutions/persisted-query-to-rest:latest config-schema > config-schema.json
21 changes: 14 additions & 7 deletions example/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# yaml-language-server: $schema=config-schema.json
# Common config for all endpoints
common:
path_prefix: "/api/v1"
listen: "0.0.0.0:8080"
graphql_endpoint: "https://api.graphql-gtm-demo.com/e-commerce-gtm-demo/"
logging:
level: info
path_prefix: "/api/v1"
listen: "0.0.0.0:3000"
graphql_endpoint: "https://localhost:3000/"
logging:
level: info

# A list of all the new endpoints to create
endpoints:
- path: "/userInfo"
pq_id: "126c4cf641bff8deba6c863e00e0dc136f31374425d22339e9779a91ae4494d8"
# Create an endpoint that requires the id in the path
- path: "/users/:id"
pq_id: "123456789"
path_arguments:
# Map the arguments to the GraphQL arg called $userId
- from: "id"
to: "userId"
5 changes: 2 additions & 3 deletions example/start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
docker run \
-p 8080:8080 \
-it -p 8080:8080 \
--mount "type=bind,source=./config.yml,target=/app/config.yml" \
--name persisted-query-to-rest \
ghcr.io/apollosolutions/persisted-query-to-rest:v0.3.2 --config /app/config.yml
ghcr.io/apollosolutions/persisted-query-to-rest:latest --config /app/config.yml

0 comments on commit 3c2cacf

Please sign in to comment.