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

@@ -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
"""#
}
}