Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dbquery/pagination/operations.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Page through customers from a database connection based pagination
query Customers($first: Int!, $after: String = "") {
query Customers($first: Int!, $after: String = "") {
customers(first: $first, after: $after) {
edges {
node {
Expand Down
59 changes: 35 additions & 24 deletions materializer/nestedfieldselection/api.graphql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# See preamble in README.md

type Document {
docId: String
content(id: String!): Content
@materializer(query: "content", arguments:[{name: "id" argument:"id"}])
author: Author
lastUpdate: Date
docId: String
content(id: String!): Content
@materializer(query: "content", arguments: [{ name: "id", argument: "id" }])
author: Author
lastUpdate: Date
}

type Content @mock {
Expand All @@ -15,36 +15,47 @@ type Content @mock {
}

type Query {
document: Document
@rest(
endpoint: "stepzen:empty"
transforms: [{
editor: """jq: {"author": { "name":"Roy Derks", "country":"Netherlands"}}"""
}]
)
# Content is exposed here to keep the snippet self-contained, but would otherwise not be exposed as an operation
content(id: String!): Content
@connector(type:"echo")
document: Document
@rest(
endpoint: "stepzen:empty"
transforms: [
{
editor: """
jq: {"author": { "name":"Roy Derks", "country":"Netherlands"}}
"""
}
]
)
# Content is exposed here to keep the snippet self-contained, but would otherwise not be exposed as an operation
content(id: String!): Content @connector(type: "echo")
}

type Author {
name: String!
country: String
name: String!
country: String
}

type Query {
book: Book
@rest(
endpoint: "stepzen:empty"
transforms: [{
editor: """jq: {"refId": "27", "name": "Fullstack GraphQL"}"""
}]
endpoint: "stepzen:empty"
transforms: [
{
editor: """
jq: {"refId": "27", "name": "Fullstack GraphQL"}
"""
}
]
)
}

type Book {
refId: String!
name: String
author: Author @materializer (query: "document {author}")
content: Content @materializer (query: "document {content}", arguments: {name: "id", field: "refId"})
}
author: Author @materializer(query: "document {author}")
content: Content
@materializer(
query: "document {content}"
arguments: { name: "id", field: "refId" }
)
}
6 changes: 3 additions & 3 deletions materializer/nestedfieldselection/index.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
schema @sdl(files:[
"api.graphql"
]){query: Query}
schema @sdl(files: ["api.graphql"]) {
query: Query
}
6 changes: 3 additions & 3 deletions protection/makeAllPublic/index.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
schema @sdl(files:[
"api.graphql"
]){query: Query}
schema @sdl(files: ["api.graphql"]) {
query: Query
}
52 changes: 27 additions & 25 deletions protection/makeSomePublic/api.graphql
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
type Customer {
name: String
city: String
name: String
city: String
}
type Query {
# An ecmascript generator of customer data.
# Of course, in real life you will call an API or a database. You can do that by changing the `endpoint` argument on the `@rest` directive.
# https://stepzen.com/docs/connecting-backends/how-to-connect-a-rest-service
customer (id: ID): Customer
@rest (endpoint: "stepzen:empty"
ecmascript: """
function transformREST(s) {
var id = get('id')
if (id==1)
return (JSON.stringify({"name":"John Doe","city":"Miami"}))
else
return (JSON.stringify({"name":"Jane Smith","city":"Santa Clara"}))
}
"""
# An ecmascript generator of customer data.
# Of course, in real life you will call an API or a database. You can do that by changing the `endpoint` argument on the `@rest` directive.
# https://stepzen.com/docs/connecting-backends/how-to-connect-a-rest-service
customer(id: ID): Customer
@rest(
endpoint: "stepzen:empty"
ecmascript: """
function transformREST(s) {
var id = get('id')
if (id==1)
return (JSON.stringify({"name":"John Doe","city":"Miami"}))
else
return (JSON.stringify({"name":"Jane Smith","city":"Santa Clara"}))
}
"""
)
customers: [Customer]
@rest (endpoint: "stepzen:empty"
ecmascript: """
function transformREST(s) {
return JSON.stringify([{"name":"John Doe","city":"Miami"},
{"name":"Jane Smith","city":"Santa Clara"}])
}
"""
customers: [Customer]
@rest(
endpoint: "stepzen:empty"
ecmascript: """
function transformREST(s) {
return JSON.stringify([{"name":"John Doe","city":"Miami"},
{"name":"Jane Smith","city":"Santa Clara"}])
}
"""
)
}
}
6 changes: 3 additions & 3 deletions protection/makeSomePublic/index.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
schema @sdl(files:[
"api.graphql"
]){query: Query}
schema @sdl(files: ["api.graphql"]) {
query: Query
}
31 changes: 15 additions & 16 deletions rest/morecomplexpost/api.graphql
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Here we create a `postbody` from the query argument
# Here we create a `postbody` from the query argument
# using `GetJSON` which will return a JSON item associated
# with one of the inputs.
# `GetJSON` will return a null value if the city or name was not specified.
# `GetJSON` is preferred for an 'Accept' header with an `application/JSON` value.
# The syntax is `{{.GetJSON "name-of-the-argument"}}`
#
#
# You can also use `Get` which will return a string version
# of the input--where possible--and is well suited for use in
# of the input--where possible--and is well suited for use in
# XML, forms, etc. However, `Get` gets more complicated
# in terms of careful escaping. Wherever possible, use `GetJSON`.


type Root {
args: JSON
data: String
Expand All @@ -26,17 +25,17 @@ type Root {
# that uses Go language templates and the custom
# stepzen function "Get" and "GetJSON".
type Query {
restquery(name:String!, city: String!): Root
@rest (endpoint: "https://httpbingo.org/post",
method: POST,
postbody: """
{"record": { "name": {{.GetJSON "name"}},
"city": "{{.GetJSON "city"}}"} }
"""
headers: [
{name: "Accept", value: "application/json"}
{name: "Content-Type", value: "application/json"}
]
restquery(name: String!, city: String!): Root
@rest(
endpoint: "https://httpbingo.org/post"
method: POST
postbody: """
{"record": { "name": {{.GetJSON "name"}},
"city": "{{.GetJSON "city"}}"} }
"""
headers: [
{ name: "Accept", value: "application/json" }
{ name: "Content-Type", value: "application/json" }
]
)
}

33 changes: 17 additions & 16 deletions rest/morecomplexpost/apidebug.graphql
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""
Explore an rest API using JSON as the return value as in `restJSONquery` below, then see what the
REST API returned in context of how the StepZen services process the request.

Try issuing the following with name and/or city removed to see the effects.
```
curl https://ACCOUNTNAME.stepzen.net/api/miscellaneous/__graphql \
--header "Authorization: Apikey $(stepzen whoami --apikey)" \
--header "Content-Type: application/json" \
--data '{"query": "{restJSONquery(name: \"Joe Smith\" city:\"New York\")}"}'
--data '{"query": "{restJSONquery(name: \"Joe Smith\" city:\"New York\")}"}'
```

StepZen services return diagnostics in the GraphQL response
Expand All @@ -17,21 +17,22 @@ curl https://ACCOUNTNAME.stepzen.net/api/miscellaneous/__graphql \
--header "Authorization: Apikey $(stepzen whoami --adminkey)" \
--header "Content-Type: application/json" \
--header "StepZen-Debug-Level: 1" \
--data '{"query": "{restJSONquery(name: \"Joe Smith\" city:\"New York\")}"}'
--data '{"query": "{restJSONquery(name: \"Joe Smith\" city:\"New York\")}"}'
```
"""
type Query {
# Set a JSON query return type to avoid any type conflicts that you might have during testing.
# You cannot subselect fields this way.
restJSONquery(name:String, city: String): JSON
@rest (endpoint: "https://httpbingo.org/post",
method: POST,
postbody: """
{"record": { "name": {{.GetJSON "name"}}, "city": {{.GetJSON "city"}}} }
"""
headers: [
{name: "Accept", value: "application/json"}
{name: "Content-Type", value: "application/json"}
],
# Set a JSON query return type to avoid any type conflicts that you might have during testing.
# You cannot subselect fields this way.
restJSONquery(name: String, city: String): JSON
@rest(
endpoint: "https://httpbingo.org/post"
method: POST
postbody: """
{"record": { "name": {{.GetJSON "name"}}, "city": {{.GetJSON "city"}}} }
"""
headers: [
{ name: "Accept", value: "application/json" }
{ name: "Content-Type", value: "application/json" }
]
)
}
}
31 changes: 16 additions & 15 deletions rest/postbody/api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Root {

"""
Since we used `application/x-www-form-urlencoded` as a value for our `Content-Type` header, StepZen will
encode the postbody as form-encoded and the httpbingo.org/post will return
encode the postbody as form-encoded and the httpbingo.org/post will return
it in form. You'll see that `args` and `data` will be empty, and `json` will be null, when you run the following query.
query MyQuery {
restquery(name: "Joe Smith", city: "New York") {
Expand All @@ -26,21 +26,22 @@ query MyQuery {
}
"""
type Query {
restquery(name:String, city: String): Root
restquery(name: String, city: String): Root
# Set a JSON query return type to avoid any type conflicts that you might have during testing.
# You cannot subselect fields this way.
# restquery(name:String, city: String): JSON
@rest (endpoint: "https://httpbingo.org/post",
method: POST,
headers: [{name: "Accept", value:"application/json"},
{name: "Content-Type", value: "application/x-www-form-urlencoded"}],

@rest(
endpoint: "https://httpbingo.org/post"
method: POST
headers: [
{ name: "Accept", value: "application/json" }
{ name: "Content-Type", value: "application/x-www-form-urlencoded" }
]
)
}


"""
When the 'Accept' header is `application/json`, StepZen will automatically populate the body.
When the 'Accept' header is `application/json`, StepZen will automatically populate the body.
Note: if method POST is used, The default for `Content-Type` is `application/json`.

Using the sample GraphQL query, data will show the contents of the postbody and json as transformed to JSON.
Expand All @@ -57,14 +58,14 @@ query MyQuery {
}
}
"""

type Query {
restjsonbodyquery(name:String, city: String): Root
restjsonbodyquery(name: String, city: String): Root
# Set a JSON query return type to avoid any type conflicts that you might have during testing.
# You cannot subselect fields this way.
# restjsonbodyquery(name:String, city: String): JSON
@rest (endpoint: "https://httpbingo.org/post",
method: POST,
headers: [{name: "Accept", value:"application/json"}]
@rest(
endpoint: "https://httpbingo.org/post"
method: POST
headers: [{ name: "Accept", value: "application/json" }]
)
}
}
6 changes: 3 additions & 3 deletions rest/postbody/index.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
schema @sdl(files:[
"api.graphql"
]){query: Query}
schema @sdl(files: ["api.graphql"]) {
query: Query
}
14 changes: 7 additions & 7 deletions rest/restWithConfigYaml/api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ curl https://ACCOUNTNAME.stepzen.net/api/miscellaneous/__graphql \
--header "Content-Type: application/json" \
--data '{"query": "{rest(q: [\"Joe Smith\" \"Jane Smith\"]) { args { q } url }}"}'
"""

type Query {
rest(q:[String]): Root
rest(q: [String]): Root
# Set a JSON query return type to avoid any type conflicts that you might have during testing.
# You cannot subselect fields this way.
# rest(q:[String]): JSON
@rest (endpoint: "https://httpbingo.org/get?apikey=$apikey",
method: GET,
headers: [{name: "Accept", value:"application/json"}],
configuration: "httpbin"
@rest(
endpoint: "https://httpbingo.org/get?apikey=$apikey"
method: GET
headers: [{ name: "Accept", value: "application/json" }]
configuration: "httpbin"
)
}
}
6 changes: 3 additions & 3 deletions rest/restWithConfigYaml/index.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
schema @sdl(files:[
"api.graphql"
]){query: Query}
schema @sdl(files: ["api.graphql"]) {
query: Query
}
6 changes: 3 additions & 3 deletions rest/restWithParameters/index.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
schema @sdl(files:[
"api.graphql"
]){query: Query}
schema @sdl(files: ["api.graphql"]) {
query: Query
}
Loading