diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..2e336a6 --- /dev/null +++ b/example/README.md @@ -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 + diff --git a/example/config-schema.json b/example/config-schema.json new file mode 100644 index 0000000..0721768 --- /dev/null +++ b/example/config-schema.json @@ -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" + } + } + } + } +} diff --git a/example/config-schema.sh b/example/config-schema.sh index f337fab..ed04339 100644 --- a/example/config-schema.sh +++ b/example/config-schema.sh @@ -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 diff --git a/example/config.yml b/example/config.yml index f9f7961..70d709c 100644 --- a/example/config.yml +++ b/example/config.yml @@ -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" diff --git a/example/start.sh b/example/start.sh index f2a023b..8d76eba 100755 --- a/example/start.sh +++ b/example/start.sh @@ -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