Create graphql package

Signed-off-by: jffarge <slumbering.pierrot@gmail.com>
This commit is contained in:
jffarge 2021-10-22 17:39:16 +02:00 committed by jffarge
parent 79f86227f3
commit 6825309f31
7 changed files with 148 additions and 2 deletions

View File

@ -27,6 +27,7 @@
- [gcp/secretmanager](./gcp/secretmanager.md) - Google Cloud Secret Manager - [gcp/secretmanager](./gcp/secretmanager.md) - Google Cloud Secret Manager
- [git](./git.md) - Git operations - [git](./git.md) - Git operations
- [go](./go.md) - Go build operations - [go](./go.md) - Go build operations
- [graphql](./graphql.md) - -
- [http](./http.md) - - - [http](./http.md) - -
- [io](./io.md) - IO operations - [io](./io.md) - IO operations
- [java/maven](./java/maven.md) - Maven is a build automation tool for Java - [java/maven](./java/maven.md) - Maven is a build automation tool for Java

23
docs/reference/graphql.md Normal file
View File

@ -0,0 +1,23 @@
---
sidebar_label: graphql
---
# alpha.dagger.io/graphql
```cue
import "alpha.dagger.io/graphql"
```
## graphql.#Query
### graphql.#Query Inputs
_No input._
### graphql.#Query Outputs
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*post.statusCode* | `string` |- |
|*post.body* | `string` |- |
|*data* | `_\|_` |- |

2
stdlib/.dagger/env/graphql/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# dagger state
state/**

27
stdlib/.dagger/env/graphql/values.yaml vendored Normal file
View File

@ -0,0 +1,27 @@
plan:
package: ./graphql/tests
name: graphql
inputs:
TestDockersocket:
socket:
unix: /var/run/docker.sock
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
age:
- recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSAyRUk0Q3BNOFBRUEl0amtZ
QS9ZeVdPaTZ5aE5Nbk90eC80aURGZytxQ2g0CjNZSVVvcnVldzNzN3VybjRXMy9T
Sml1QmV6YW1tVlVKUEI5aE5XWTcrY00KLS0tIE05ZllhMkppSFRyN2ZjdUlvMktV
V0J1ZC9BVEJCb1pWcWdsc0lkWDdmYWcKFA7YrasrdKXAnbv4xtebelPia4GREZa7
lv1rAmsTc7w4MER5h+syxHHr2C0fsysR6WZHNS+lRPH+b4eZCvgHvg==
-----END AGE ENCRYPTED FILE-----
lastmodified: "2021-11-25T13:14:38Z"
mac: ENC[AES256_GCM,data:EuIpdctm28LZwIgdoq+73l1VzG2198s4Kb1qQSeGE5kqscPIFskh1c+DsP5VDtDCExRC5sAVHnDIwWst+Zh5Q9TzbLtMg/+5bYYtBWtf/XZldb1aaGRHdl/g4mILvmZmxdCDmU8BFv7snmIswsrP8X3dY3ItOG85hAJndoY6irA=,iv:UfFVg/gs3qEn3xDQv6g9UqLw4josOCl1Xjl3RsH+9k0=,tag:fUcFZFHdd6Mod+RXdf7sUg==,type:str]
pgp: []
encrypted_suffix: secret
version: 3.7.1

View File

@ -0,0 +1,39 @@
package graphql
import (
"encoding/json"
"alpha.dagger.io/dagger"
"alpha.dagger.io/http"
)
#Query: {
// Contents of the graphql query
query: string
// graphql variables
variable: [key=string]: _
// graphql url
url: string
//API Token
token: dagger.#Input & dagger.#Secret | *null
post: http.#Post & {
"url": url
request: {
body: json.Marshal({
"query": query
variables: json.Marshal(variable)
})
header: "Content-Type": "application/json"
token: token
}
}
payload: {
data: {...}
errors?: {...}
}
payload: json.Unmarshal(post.response.body)
data: payload.data @dagger(output)
errors?: payload.errors @dagger(output)
}

View File

@ -0,0 +1,55 @@
package graphql
import (
"encoding/json"
"alpha.dagger.io/alpine"
"alpha.dagger.io/dagger"
"alpha.dagger.io/docker"
"alpha.dagger.io/os"
"alpha.dagger.io/http"
)
TestDockersocket: dagger.#Stream & dagger.#Input
TestQuery: {
run: docker.#Run & {
name: "graphql-faker"
ref: "apisguru/graphql-faker"
socket: TestDockersocket
ports: ["8080:9002"]
}
// Waits for TestRun to finish initializing
Testhealth: http.#Wait & {
url: "http://localhost:8080/graphql?query={%7BallCompanies%20%7B%0A%20%20%20%20id%0A%20%20%7D%0A%7D}"
}
queryWithoutToken: #Query & {
url: Testhealth.url
query: #"""
{
company(id: "NjExNjAwMjE5Nw==") {
id
}
}
"""#
}
testRaw: os.#Container & {
image: alpine.#Image & {
package: jq: "~=1.6"
}
env: STATUS: "\(queryWithoutToken.post.response.statusCode)"
shell: args: ["--noprofile", "--norc", "-eo", "pipefail", "-c"]
files: "/content.json": {
content: json.Marshal(queryWithoutToken.data)
mode: 0o500
}
command: #"""
test "$STATUS" = "200"
test "$(cat /content.json | jq '.allCompanies | length')" -gt 1
"""#
}
}

View File

@ -44,7 +44,7 @@ import (
} }
command: #""" command: #"""
curlArgs=( curlArgs=(
"$URL" "$URL"
-L --fail --silent --show-error -L --fail --silent --show-error
--write-out "%{http_code}" --write-out "%{http_code}"
-X "$METHOD" -X "$METHOD"
@ -60,7 +60,6 @@ import (
if [ -e /token ]; then if [ -e /token ]; then
curlArgs+=("-H" "Authorization: bearer $(cat /token)") curlArgs+=("-H" "Authorization: bearer $(cat /token)")
fi fi
curl "${curlArgs[@]}" > /status curl "${curlArgs[@]}" > /status
"""# """#
} }