Appsync mutatation query giving MalformedHttpRequestException via POST - graphql

I am trying out the default example for realtime updates on AWS appsync.
Schema
type Channel {
name: String!
data: AWSJSON!
}
type Mutation {
publish(name: String!, data: AWSJSON!): Channel
}
type Query {
getChannel: Channel
}
type Subscription {
subscribe(name: String!): Channel
#aws_subscribe(mutations: ["publish"])
}
Running this query through AWS query page gives success
mutation PublishData {
publish(data: "{\"msg\": \"hello world!\"}", name: "channel") {
data
name
}
}
When trying to execute the same through HTTP Post, it gives error.
curl --location --request POST 'https://XXXX.ap-south-1.amazonaws.com:443/graphql' \
--header 'x-api-key: XXXXX' \
--header 'Content-Type: application/graphql' \
--data-raw '{
"query": "mutation PublishData { publish(data: \"{\"msg\": \"hello world!\"}\", name: \"broadcast\") { data name } }",
"variables": "{}"
}'
Executing this query gives success
curl --location --request POST 'https://XXX.ap-south-1.amazonaws.com:443/graphql' \
--header 'x-api-key: XXXX' \
--header 'Content-Type: application/graphql' \
--data-raw '{
"query": "mutation PublishData { publish(data: \"{}\", name: \"broadcast\") { data name } }",
"variables": "{}"
}'
I am unable to figure out where is the syntax error.

I got it working using variables. This is the syntax.
{
"query": "mutation($data:AWSJSON!) { publish(data: $data, name: \"broadcast\") { data name } }",
"variables": {"data":"{\"abs\":1}"}
}

Related

How do I get a token's name, symbol, decimals, etc.?

e.g. does getting the name look like this?
args := fmt.Sprintf("{\"tokenOwner\":\"%s\"}", "bob.near")
argsBase64 := base64.StdEncoding.EncodeToString([]byte(args))
param := map[string]string{
"request_type": "call_function",
"finality": "final",
"account_id": "ref-finance.near",
"method_name": "name",
"args_base64": argsBase64,
}
This is part of the metadata of each token. You can read the metadata standard at nomicon.io.
In particular you can query the metadata of an NEP-141 Fungible Token using the function ft_metadata as following:
❯ export NEAR_ENV=mainnet
❯ near view 76a6baa20598b6d203d3eae6cc87e326bcb60e43.factory.bridge.near ft_metadata "{}"
View call: 76a6baa20598b6d203d3eae6cc87e326bcb60e43.factory.bridge.near.ft_metadata({})
{
spec: 'ft-1.0.0',
name: 'Law Diamond Token',
symbol: 'nLDT',
icon: 'https://near.org/wp-content/themes/near-19/assets/img/brand-icon.png',
reference: '',
reference_hash: '',
decimals: 18
}
Update: Make this call directly from the RPC.
You can query the RPC directly as follows:
curl --location --request POST 'https://archival-rpc.mainnet.near.org/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "call_function",
"finality": "final",
"account_id": "76a6baa20598b6d203d3eae6cc87e326bcb60e43.factory.bridge.near",
"method_name": "ft_metadata",
"args_base64": "e30="
}
}'
args_base64 field are the arguments serialised as base64. In this case it is an empty json:
base64("{}") = "e30="
The result is given as a sequence of bytes. In the case of ft_metadata it should be first decoded as a string and then decoded as json.

changing the type of id from string to uuid in solr 7.2+

I have created an example SolrCloud instance using example Settings in Solr 7.2.1 on windows:
bin/solr start -e cloud
bin/solr.cmd create -c trans -s 2 -rf 2
Then I updated the schema (as most of the data will come from Postgres and SQL Server:
curl -X POST -H 'Content-type:application/json' --data-binary '{
"add-field":{
"name":"trans",
"type":"string",
"stored":true,
"indexed":true},
"add-field":{
"name":"t",
"type":"pdate",
"stored":true,
"indexed":true},
"add-field":{
"name":"l",
"type":"pint",
"stored":true,
"indexed":true},
}' http://localhost:8983/solr/trans/schema
which results into the following schema:
curl http://localhost:8983/solr/trans/schema/fields
{
"responseHeader":{
"status":0,
"QTime":0},
"fields":[{
"name":"_root_",
"type":"string",
"docValues":false,
"indexed":true,
"stored":false},
{
"name":"_text_",
"type":"text_general",
"multiValued":true,
"indexed":true,
"stored":false},
{
"name":"_version_",
"type":"plong",
"indexed":false,
"stored":false},
{
"name":"id",
"type":"string",
"multiValued":false,
"indexed":true,
"required":true,
"stored":true},
{
"name":"l",
"type":"pint",
"indexed":true,
"stored":true},
{
"name":"t",
"type":"pdate",
"indexed":true,
"stored":true},
{
"name":"trans",
"type":"string",
"indexed":true,
"stored":true}]}
In our case, the ID has the type uuid. If I change it I get an error:
curl -X POST -H 'Content-type:application/json' --data-binary '{
"replace-field":{
"name":"id",
"type":"uuid",
"stored":true,
"indexed":true}
}' http://localhost:8983/solr/trans/schema/fields
{
"responseHeader":{
"status":500,
"QTime":48},
"error":{
"metadata":[
"error-class","org.apache.solr.common.SolrException",
"root-error-class","org.apache.solr.common.SolrException"],
"msg":"Can't load schema managed-schema: _root_ field must be defined using the exact same fieldType as the uniqueKey field (id) uses: uuid",
...
It does not help to change both the _root_ and id either:
curl -X POST -H 'Content-type:application/json' --data-binary '{
"replace-field":{
"name":"id",
"type":"uuid",
"stored":true,
},
"replace-field":{
"name":"_root_",
"type":"uuid",
"stored":true,
"docValues":false,
"indexed":true,
"stored":false}
}
' http://localhost:8983/solr/trans/schema
{
"responseHeader":{
"status":500,
"QTime":50},
"error":{
"metadata":[
"error-class","org.apache.solr.common.SolrException",
"root-error-class","org.apache.solr.common.SolrException"],
"msg":"Can't load schema managed-schema: _root_ field must be defined using the exact same fieldType as the uniqueKey field (id) uses: uuid",
How do I change the type of the id in solr properly?

How to update couchbase lite view with Rest API?

How to update couchbase lite view with Rest API ?
From Rest API how to tell indexer that view is updated . I have tried the below code but it did not work.It still returns the old index.
What is the correct way of telling indexer that view is updated so that it can recreate the index.
'PUT'
{db}/_design/todo
{
"_rev":"hf675757577hhfh",
"views":{
"list":{
"map":function(doc){
if(doc.type=='list')
{
emit(doc._id,{"name":doc.name});
}
},
//"version":"1.0" (I have tryied this but not work)
}
}
}
//My view create request was like below:
{db}/_design/todo
{
"views":{
"list":{
"map":function(doc){
if(doc.type=='list')
{
emit(doc._id,{"name":doc.name});
}
},
//"version":"1.0" (I have tryied this but not work)
}
}
}
It looks like you may just have some formatting problems. This shows how to do what you're trying from the command line:
curl -X PUT 'http://localhost:4985/db/_design/todo' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "_rev": "hf675757577hhfh", "views": { "list": { "map": "function(doc) { if (doc.type == \"list\") { emit(doc._id, { \"name\": doc.name }); }}"}}}'
You can test your results with this command:
curl -X GET 'http://localhost:4985/db/_design/todo/_view/list'
You may want to refer to the documentation, which has more examples, at https://developer.couchbase.com/documentation/mobile/current/guides/sync-gateway/views/index.html

How can I send a parse push to an installation id or device token

How can I use the Parse REST API to push to a specific deviceToken or installation Id? I make the request and it succeeds with a 200 response but I get no push.
curl -X POST \
-H "X-Parse-Application-Id: XYZ" \
-H "X-Parse-REST-API-Key: FOO" \
-H "Content-Type: application/json" \
-d '{
"where": {
"deviceToken": "someId"
},
"data": {
"alert": "Willie Hayes injured by own pop fly."
}
}' \
https://api.parse.com/1/push

Can a pointer field, to "user" class, be updated via rest api?

I have a class A that has a pointer (pointer field) to the special class User. Is it possible to automatically update the pointer field with the authenticated user, using the Rest API instead of having to call the API like the example bellow?
curl -X POST \
-H "X-Parse-Application-Id: ${APPLICATION_ID}" \
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
-H "X-Parse-Session-Token: ${SESSION_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"user":{ "__type": "Pointer", "className": "_User", "objectId": "${id}"}}' \
https://api.parse.com/1/classes/A
I would like to update the User field by just using the call:
curl -X POST \
-H "X-Parse-Application-Id: ${APPLICATION_ID}" \
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
-H "X-Parse-Session-Token: ${SESSION_TOKEN}" \
-H "Content-Type: application/json" \
https://api.parse.com/1/classes/A
And an A entry would be created.
A : {Pointer<_User> user_from_session, string objectId}
Any enlightenment is appreciated.
Cheers.
I've managed to accomplish what I wanted by adding an afterSave trigger. When creating A, with an authenticated request, I will read the current user from the session and set the field in the class. Bellow the example.
Parse.Cloud.afterSave("A", function (request, response) {
var record = request.object;
var user = Parse.User.current();
if (record.existed() == false) {
record.set("user", user);
record.save().
then(function (record) {
response.success();
}, function (error) {
response.error();
});
} else {
console.log("[DEBUG] Normal save (A).");
response.success();
}
});
Cheers.

Resources