Skip to content

Commit

Permalink
Update HTTP API Content-Type to application/graphql+-
Browse files Browse the repository at this point in the history
  • Loading branch information
mangalaman93 committed Jun 11, 2019
1 parent 683bc20 commit 04d75c3
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions dgraph/cmd/alpha/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ func queryHandler(w http.ResponseWriter, r *http.Request) {
return
}

case "application/graphqlpm":
case "application/graphql+-":
params.Query = string(body)

default:
x.SetStatus(w, x.ErrorInvalidRequest, "Unsupported Content-Type. "+
"Supported content types are application/json, application/graphqlpm")
"Supported content types are application/json, application/graphql+-")
return
}

Expand Down
36 changes: 18 additions & 18 deletions dgraph/cmd/alpha/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func TestTransactionBasic(t *testing.T) {
}
}
`
_, ts, err := queryWithTs(q1, "application/graphqlpm", 0)
_, ts, err := queryWithTs(q1, "application/graphql+-", 0)
require.NoError(t, err)

m1 := `
Expand All @@ -323,18 +323,18 @@ func TestTransactionBasic(t *testing.T) {
require.Equal(t, "balance", parsedPreds[0])
require.Equal(t, "name", parsedPreds[1])

data, _, err := queryWithTs(q1, "application/graphqlpm", 0)
data, _, err := queryWithTs(q1, "application/graphql+-", 0)
require.NoError(t, err)
require.Equal(t, `{"data":{"balances":[]}}`, data)

// Query with same timestamp.
data, _, err = queryWithTs(q1, "application/graphqlpm", ts)
data, _, err = queryWithTs(q1, "application/graphql+-", ts)
require.NoError(t, err)
require.Equal(t, `{"data":{"balances":[{"name":"Bob","balance":"110"}]}}`, data)

// Commit and query.
require.NoError(t, commitWithTs(keys, preds, ts))
data, _, err = queryWithTs(q1, "application/graphqlpm", 0)
data, _, err = queryWithTs(q1, "application/graphql+-", 0)
require.NoError(t, err)
require.Equal(t, `{"data":{"balances":[{"name":"Bob","balance":"110"}]}}`, data)
}
Expand All @@ -351,7 +351,7 @@ func TestTransactionBasicNoPreds(t *testing.T) {
}
}
`
_, ts, err := queryWithTs(q1, "application/graphqlpm", 0)
_, ts, err := queryWithTs(q1, "application/graphql+-", 0)
require.NoError(t, err)

m1 := `
Expand All @@ -369,18 +369,18 @@ func TestTransactionBasicNoPreds(t *testing.T) {
require.Equal(t, mts, ts)
require.Equal(t, 3, len(keys))

data, _, err := queryWithTs(q1, "application/graphqlpm", 0)
data, _, err := queryWithTs(q1, "application/graphql+-", 0)
require.NoError(t, err)
require.Equal(t, `{"data":{"balances":[]}}`, data)

// Query with same timestamp.
data, _, err = queryWithTs(q1, "application/graphqlpm", ts)
data, _, err = queryWithTs(q1, "application/graphql+-", ts)
require.NoError(t, err)
require.Equal(t, `{"data":{"balances":[{"name":"Bob","balance":"110"}]}}`, data)

// Commit and query.
require.NoError(t, commitWithTs(keys, nil, ts))
data, _, err = queryWithTs(q1, "application/graphqlpm", 0)
data, _, err = queryWithTs(q1, "application/graphql+-", 0)
require.NoError(t, err)
require.Equal(t, `{"data":{"balances":[{"name":"Bob","balance":"110"}]}}`, data)
}
Expand All @@ -397,7 +397,7 @@ func TestTransactionBasicOldCommitFormat(t *testing.T) {
}
}
`
_, ts, err := queryWithTs(q1, "application/graphqlpm", 0)
_, ts, err := queryWithTs(q1, "application/graphql+-", 0)
require.NoError(t, err)

m1 := `
Expand All @@ -415,12 +415,12 @@ func TestTransactionBasicOldCommitFormat(t *testing.T) {
require.Equal(t, mts, ts)
require.Equal(t, 3, len(keys))

data, _, err := queryWithTs(q1, "application/graphqlpm", 0)
data, _, err := queryWithTs(q1, "application/graphql+-", 0)
require.NoError(t, err)
require.Equal(t, `{"data":{"balances":[]}}`, data)

// Query with same timestamp.
data, _, err = queryWithTs(q1, "application/graphqlpm", ts)
data, _, err = queryWithTs(q1, "application/graphql+-", ts)
require.NoError(t, err)
require.Equal(t, `{"data":{"balances":[{"name":"Bob","balance":"110"}]}}`, data)

Expand All @@ -433,7 +433,7 @@ func TestTransactionBasicOldCommitFormat(t *testing.T) {

// Commit (using a list of keys instead of a map) and query.
require.NoError(t, commitWithTsKeysOnly(keys, ts))
data, _, err = queryWithTs(q1, "application/graphqlpm", 0)
data, _, err = queryWithTs(q1, "application/graphql+-", 0)
require.NoError(t, err)
require.Equal(t, `{"data":{"balances":[{"name":"Bob","balance":"110"}]}}`, data)

Expand Down Expand Up @@ -507,32 +507,32 @@ func TestHttpCompressionSupport(t *testing.T) {
err := runMutation(m1)
require.NoError(t, err)

data, resp, err := queryWithGz(q1, "application/graphqlpm", false, false, "")
data, resp, err := queryWithGz(q1, "application/graphql+-", false, false, "")
require.NoError(t, err)
require.Equal(t, r1, data)
require.Empty(t, resp.Header.Get("Content-Encoding"))

data, resp, err = queryWithGz(q1, "application/graphqlpm", false, true, "")
data, resp, err = queryWithGz(q1, "application/graphql+-", false, true, "")
require.NoError(t, err)
require.Equal(t, r1, data)
require.Equal(t, "gzip", resp.Header.Get("Content-Encoding"))

data, resp, err = queryWithGz(q1, "application/graphqlpm", true, false, "")
data, resp, err = queryWithGz(q1, "application/graphql+-", true, false, "")
require.NoError(t, err)
require.Equal(t, r1, data)
require.Empty(t, resp.Header.Get("Content-Encoding"))

data, resp, err = queryWithGz(q1, "application/graphqlpm", true, true, "")
data, resp, err = queryWithGz(q1, "application/graphql+-", true, true, "")
require.NoError(t, err)
require.Equal(t, r1, data)
require.Equal(t, "gzip", resp.Header.Get("Content-Encoding"))

// query with timeout
data, resp, err = queryWithGz(q1, "application/graphqlpm", false, false, "1ms")
data, resp, err = queryWithGz(q1, "application/graphql+-", false, false, "1ms")
require.EqualError(t, err, ": context deadline exceeded")
require.Equal(t, "", data)

data, resp, err = queryWithGz(q1, "application/graphqlpm", false, false, "1s")
data, resp, err = queryWithGz(q1, "application/graphql+-", false, false, "1s")
require.NoError(t, err)
require.Equal(t, r1, data)
require.Empty(t, resp.Header.Get("Content-Encoding"))
Expand Down
2 changes: 1 addition & 1 deletion dgraph/cmd/alpha/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func processToFastJSON(q string) string {
}

func runGraphqlQuery(q string) (string, error) {
output, _, err := queryWithTs(q, "application/graphqlpm", 0)
output, _, err := queryWithTs(q, "application/graphql+-", 0)
return string(output), err
}

Expand Down
2 changes: 1 addition & 1 deletion dgraph/cmd/bulk/systest/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ for suite in $script_dir/suite*; do
sleep 2

popd >/dev/null # out of tmp
result=$(curl --silent -H "Content-Type: application/graphqlpm" localhost:8080/query -XPOST -d @$suite/query.json)
result=$(curl --silent -H "Content-Type: application/graphql+-" localhost:8080/query -XPOST -d @$suite/query.json)
if ! $(jq --argfile a <(echo $result) --argfile b $suite/result.json -n 'def post_recurse(f): def r: (f | select(. != null) | r), .; r; def post_recurse: post_recurse(.[]?); ($a | (post_recurse | arrays) |= sort) as $a | ($b | (post_recurse | arrays) |= sort) as $b | $a == $b')
then
echo "Actual result doesn't match expected result:"
Expand Down
2 changes: 1 addition & 1 deletion dgraph/cmd/bulk/systest/test-bulk-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function QuerySchema
{
INFO "running schema query"
local out_file="schema.out"
curl -sS -H "Content-Type: application/graphqlpm" localhost:$HTTP_PORT/query -XPOST -d'schema(pred:[genre,language,name,revenue,predicate_with_default_type,predicate_with_index_no_uid_count,predicate_with_no_uid_count]) {}' | python -c "import json,sys; d=json.load(sys.stdin); json.dump(d['data'],sys.stdout,sort_keys=True,indent=2)" > $out_file
curl -sS -H "Content-Type: application/graphql+-" localhost:$HTTP_PORT/query -XPOST -d'schema(pred:[genre,language,name,revenue,predicate_with_default_type,predicate_with_index_no_uid_count,predicate_with_no_uid_count]) {}' | python -c "import json,sys; d=json.load(sys.stdin); json.dump(d['data'],sys.stdout,sort_keys=True,indent=2)" > $out_file
echo >> $out_file
}

Expand Down
2 changes: 1 addition & 1 deletion ee/acl/acl_curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestCurlAuthorization(t *testing.T) {
// test fail open with the accessJwt
queryArgs := func(jwt string) []string {
return []string{"-H", fmt.Sprintf("X-Dgraph-AccessToken:%s", jwt),
"-H", "Content-Type: application/graphqlpm",
"-H", "Content-Type: application/graphql+-",
"-d", query, curlQueryEndpoint}
}
z.VerifyCurlCmd(t, queryArgs(accessJwt), &z.FailureConfig{
Expand Down
2 changes: 1 addition & 1 deletion systest/queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ func SchemaQueryTestHTTP(t *testing.T, c *dgo.Dgraph) {

var bb bytes.Buffer
bb.WriteString(`schema{}`)
res, err := http.Post("http://localhost:8180/query", "application/graphqlpm", &bb)
res, err := http.Post("http://localhost:8180/query", "application/graphql+-", &bb)
require.NoError(t, err)
require.NotNil(t, res)
defer res.Body.Close()
Expand Down
10 changes: 5 additions & 5 deletions wiki/content/clients/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,12 @@ new transaction is initiated.**
### Run a query

To query the database, the `/query` endpoint is used. Remember to set the `Content-Type` header
to `application/graphqlpm` in order to ensure that the body of the request is correctly parsed.
to `application/graphql+-` in order to ensure that the body of the request is correctly parsed.

To get the balances for both accounts:

```sh
$ curl -H "Content-Type: application/graphqlpm" -X POST localhost:8080/query -d $'
$ curl -H "Content-Type: application/graphql+-" -X POST localhost:8080/query -d $'
{
balances(func: anyofterms(name, "Alice Bob")) {
uid
Expand Down Expand Up @@ -773,7 +773,7 @@ Example of a compressed request via curl:
```sh
$ curl -X POST \
-H 'Accept-Encoding: gzip' \
-H "Content-Type: application/graphqlpm" \
-H "Content-Type: application/graphql+-" \
localhost:8080/query -d $'schema {}' | gzip --decompress
```

Expand All @@ -793,15 +793,15 @@ $ zcat query.gz # query.gz is gzipped compressed
$ curl -X POST \
-H 'Content-Encoding: gzip' \
-H 'Accept-Encoding: gzip' \
-H "Content-Type: application/graphqlpm" \
-H "Content-Type: application/graphql+-" \
localhost:8080/query --data-binary @query.gz | gzip --decompress
```

{{% notice "note" %}}
Curl has a `--compressed` option that automatically requests for a compressed response (`Accept-Encoding` header) and decompresses the compressed response.

```sh
$ curl -X POST --compressed -H "Content-Type: application/graphqlpm" localhost:8080/query -d $'schema {}'
$ curl -X POST --compressed -H "Content-Type: application/graphql+-" localhost:8080/query -d $'schema {}'
```
{{% /notice %}}

Expand Down
4 changes: 2 additions & 2 deletions wiki/content/get-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ curl localhost:8080/alter -XPOST -d $'
Run this query to get all the movies. The query works below all the movies have a starring edge

```sh
curl -H "Content-Type: application/graphqlpm" localhost:8080/query -XPOST -d $'
curl -H "Content-Type: application/graphql+-" localhost:8080/query -XPOST -d $'
{
me(func: has(starring)) {
name
Expand All @@ -291,7 +291,7 @@ Run this query to get "Star Wars" movies released after "1980". Try it in the u


```sh
curl -H "Content-Type: application/graphqlpm" localhost:8080/query -XPOST -d $'
curl -H "Content-Type: application/graphql+-" localhost:8080/query -XPOST -d $'
{
me(func:allofterms(name, "Star Wars")) @filter(ge(release_date, "1980")) {
name
Expand Down
14 changes: 7 additions & 7 deletions wiki/content/query-language/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,7 @@ For the purposes of debugging, you can attach a query parameter `debug=true` to

Query with debug as a query parameter
```sh
curl -H "Content-Type: application/graphqlpm" http://localhost:8080/query?debug=true -XPOST -d $'{
curl -H "Content-Type: application/graphql+-" http://localhost:8080/query?debug=true -XPOST -d $'{
tbl(func: allofterms(name@en, "The Big Lebowski")) {
name@en
}
Expand Down Expand Up @@ -2903,7 +2903,7 @@ curl -H "Content-Type: application/rdf" localhost:8080/mutate?commitNow=true -XP

The shortest path between Alice and Mallory (assuming UIDs 0x2 and 0x5 respectively) can be found with query:
```sh
curl -H "Content-Type: application/graphqlpm" localhost:8080/query -XPOST -d $'{
curl -H "Content-Type: application/graphql+-" localhost:8080/query -XPOST -d $'{
path as shortest(from: 0x2, to: 0x5) {
friend
}
Expand Down Expand Up @@ -2941,7 +2941,7 @@ Which returns the following results. (Note, without considering the `weight` fac

The shortest two paths are returned with:
```sh
curl -H "Content-Type: application/graphqlpm" localhost:8080/query -XPOST -d $'{
curl -H "Content-Type: application/graphql+-" localhost:8080/query -XPOST -d $'{
path as shortest(from: 0x2, to: 0x5, numpaths: 2) {
friend
}
Expand All @@ -2955,7 +2955,7 @@ Edges weights are included by using facets on the edges as follows.

{{% notice "note" %}}One facet per predicate in the shortest query block is allowed.{{% /notice %}}
```sh
curl -H "Content-Type: application/graphqlpm" localhost:8080/query -XPOST -d $'{
curl -H "Content-Type: application/graphql+-" localhost:8080/query -XPOST -d $'{
path as shortest(from: 0x2, to: 0x5) {
friend @facets(weight)
}
Expand Down Expand Up @@ -3014,7 +3014,7 @@ curl -H "Content-Type: application/graphqlpm" localhost:8080/query -XPOST -d $'{

Constraints can be applied to the intermediate nodes as follows.
```sh
curl -H "Content-Type: application/graphqlpm" localhost:8080/query -XPOST -d $'{
curl -H "Content-Type: application/graphql+-" localhost:8080/query -XPOST -d $'{
path as shortest(from: 0x2, to: 0x5) {
friend @filter(not eq(name, "Bob")) @facets(weight)
relative @facets(liking)
Expand All @@ -3029,7 +3029,7 @@ curl -H "Content-Type: application/graphqlpm" localhost:8080/query -XPOST -d $'{
The k-shortest path algorithm (used when numPaths > 1)also accepts the arguments ```minweight``` and ```maxweight```, which take a float as their value. When they are passed, only paths within the weight range ```[minweight, maxweight]``` will be considered as valid paths. This can be used, for example, to query the shortest paths that traverse between 2 and 4 nodes.

```sh
curl -H "Content-Type: application/graphqlpm" localhost:8080/query -XPOST -d $'{
curl -H "Content-Type: application/graphql+-" localhost:8080/query -XPOST -d $'{
path as shortest(from: 0x2, to: 0x5, numpaths: 2, minweight: 2, maxweight: 4) {
friend
}
Expand Down Expand Up @@ -3069,7 +3069,7 @@ Some points to keep in mind while using recurse queries are:
`fragment` keyword allows you to define new fragments that can be referenced in a query, as per [GraphQL specification](https://facebook.github.io/graphql/#sec-Language.Fragments). The point is that if there are multiple parts which query the same set of fields, you can define a fragment and refer to it multiple times instead. Fragments can be nested inside fragments, but no cycles are allowed. Here is one contrived example.

```sh
curl -H "Content-Type: application/graphqlpm" localhost:8080/query -XPOST -d $'
curl -H "Content-Type: application/graphql+-" localhost:8080/query -XPOST -d $'
query {
debug(func: uid(1)) {
name@en
Expand Down

0 comments on commit 04d75c3

Please sign in to comment.