I've been trying to fix this bug and I haven't been able to figure it out. I know this is similar to some of the other threads I've seen on here but I've verified it's not a typo and that the issue isn't with an incorrect data type. Would really appreciate the help and for someone to point out what i'm missing here. Thanks!
Edit: Here's the stack trace
{
"errors": [
{
"message": "Syntax Error: Expected Name, found Int \"-12\".",
"locations": [
{
"line": 8,
"column": 27
}
],
"extensions": {
"code": "GRAPHQL_PARSE_FAILED",
"exception": {
"stacktrace": [
"GraphQLError: Syntax Error: Expected Name, found Int \"-12\".",
" at syntaxError (/Users/vn/Documents/Blockchain/fabric/blockchain-fabric-api/node_modules/graphql/error/syntaxError.js:15:10)",
" at Parser.expectToken (/Users/vn/Documents/Blockchain/fabric/blockchain-fabric-api/node_modules/graphql/language/parser.js:1413:40)",
" at Parser.parseName (/Users/vn/Documents/Blockchain/fabric/blockchain-fabric-api/node_modules/graphql/language/parser.js:98:22)",
" at Parser.parseObjectField (/Users/vn/Documents/Blockchain/fabric/blockchain-fabric-api/node_modules/graphql/language/parser.js:591:21)",
" at Parser.item (/Users/vn/Documents/Blockchain/fabric/blockchain-fabric-api/node_modules/graphql/language/parser.js:575:21)",
" at Parser.any (/Users/vn/Documents/Blockchain/fabric/blockchain-fabric-api/node_modules/graphql/language/parser.js:1485:26)",
" at Parser.parseObject (/Users/vn/Documents/Blockchain/fabric/blockchain-fabric-api/node_modules/graphql/language/parser.js:580:20)",
" at Parser.parseValueLiteral (/Users/vn/Documents/Blockchain/fabric/blockchain-fabric-api/node_modules/graphql/language/parser.js:461:21)",
" at Parser.item (/Users/vn/Documents/Blockchain/fabric/blockchain-fabric-api/node_modules/graphql/language/parser.js:553:20)",
" at Parser.any (/Users/vn/Documents/Blockchain/fabric/blockchain-fabric-api/node_modules/graphql/language/parser.js:1485:26)"
]
}
}
}
]
}
You have creationTime as a string without quotes, so you need quotes
change it to this:
creationTime: "2007-12-03R10:15:30Z",
Related
I am receiving an Unexpected Execution Error in my query result and was wondering how I would better understand the error. What does Unexpected Execution Error mean?
{
"errors":[
{
"message":"Unexpected Execution Error",
"locations":[
{
"line":2,
"column":3
}
],
"path":[
"createProfile"
]
}
],
"data":{
}
}
I'm trying to define some docs in ES Painless Lab, to test some logic in Painless Lab, before running it on the actual index, but can't figure out how to do it, and the docs are not helping either. There is very little documentation on the actual syntax and it's not much help for someone with no Java background.
If I try to define a doc like this:
def docs = [{ "id": 1, "name": "Apple" }];
I get an error:
Unhandled Exception illegal_argument_exception
invalid sequence of tokens near ['{'].
Stack:
[
"def docs = [{ \"id\": 1, \"name\": \"Apple ...",
" ^---- HERE"
]
If I want to do it the Java way:
String message;
JSONObject json = new JSONObject();
json.put("test1", "value1");
message = json.toString();
I'm also getting an error:
Unhandled Exception illegal_argument_exception
invalid declaration: cannot resolve type [JSONObject]
Stack:
[
"... ring message;\nJSONObject json = new JSONObject();\n ...",
" ^---- HERE"
]
So what's the proper way to define an array of json objects to play with in Painless Lab?
After more experimenting, I found out that the docs can be passed in the parameters tab as:
{
"docs": [
{ "id": 1, "name": "Apple" },
{ "id": 2, "name": "Pear" },
{ "id": 3, "name": "Pineapple" }
]
}
and then access it from the code as
def doc = params.docs[1];
return doc["name"];
I'd be still interested how to define an object or array in the code itself.
I am practicing using directives with Graphql in Nodejs. When in the Playground I want to use the #include directive, the Graphql client tells me: "Unknow directive include". This is my code:
query getChar($id: ID!, $withGames: Boolean!) {
getCharacter(_id: $id) {
_id
name
race
games #include(if: $withGames) {
_id
title
}
image
}
}
In my Query Variables I have:
{
"id": "5f945a7b24c84f35ecfae633",
"withGames": false
}
but I get the following error:
{
"error": {
"errors": [
{
"message": "Unknown directive \"#include\".",
"locations": [
{
"line": 6,
"column": 11
}
],
"extensions": {
"code": "GRAPHQL_VALIDATION_FAILED",
"exception": {
"stacktrace": [
"GraphQLError: Unknown directive \"#include\".",
" at Object.Directive (C:\\Users\\MSI\\projects\\Graphql\\cursobasico\\node_modules\\graphql\\validation\\rules\\KnownDirectivesRule.js:56:29)",
" at Object.enter (C:\\Users\\MSI\\projects\\Graphql\\cursobasico\\node_modules\\graphql\\language\\visitor.js:323:29)",
" at Object.enter (C:\\Users\\MSI\\projects\\Graphql\\cursobasico\\node_modules\\graphql\\utilities\\TypeInfo.js:370:25)",
" at visit (C:\\Users\\MSI\\projects\\Graphql\\cursobasico\\node_modules\\graphql\\language\\visitor.js:243:26)",
" at Object.validate (C:\\Users\\MSI\\projects\\Graphql\\cursobasico\\node_modules\\graphql\\validation\\validate.js:69:24)",
" at validate (C:\\Users\\MSI\\projects\\Graphql\\cursobasico\\node_modules\\apollo-server-core\\src\\requestPipeline.ts:510:14)",
" at Object.<anonymous> (C:\\Users\\MSI\\projects\\Graphql\\cursobasico\\node_modules\\apollo-server-core\\src\\requestPipeline.ts:296:32)",
" at Generator.next (<anonymous>)",
" at fulfilled (C:\\Users\\MSI\\projects\\Graphql\\cursobasico\\node_modules\\apollo-server-core\\dist\\requestPipeline.js:5:58)",
" at processTicksAndRejections (internal/process/task_queues.js:97:5)"
]
}
}
}
]
}
}
What am I doing wrong?
It was a version problem of the graphql-tools. Checking the node_modules/graphql-tools/package.json file I observed that I was using version 4. I found here that version 4 had problems with the directives and the use of version 5 was recommended. This is what I did:
npm i graphql-tools#5.0.0
I restarted the server and refresh the Playground page and voila, I already have the #include directive and all the others available.
I'm trying to test the GraphQL server I built, by sending GraphQL queries to the server using Postman.
It works when I'm using raw radio button, but when I'm trying to use GraphQL radio button, it returns "message": "Syntax Error: Expected Name, found String \"query\"".
I have tried to change the syntax: mainly add or delete curly braces but nothing happened.
The query I sent in raw mode (working):
{
person(id:"123456789") {
personal_info {
address
}
}
}
The query I sent in GraphQL mode:
QUERY:
query getPerson ($id: String){
person(id: $id){
personal_info {
address
}
}
}
GRAPHQL VARIABLES:
{
"id": "123456789"
}
I expect to get the data I asked for, but I get the error message:
{
"errors": [
{
"message": "Syntax Error: Expected Name, found String \"query\"",
"locations": [
{
"line": 1,
"column": 2
}
]
}
]
}
I had the same problem. During researching I have found the next answer on stackoverflow, thanks #gbenga_ps.
Resolved by adding the correct header to Postman request:
Body of request should be something like next:
{
courses {
title
}
}
If incorrect content-type set, error like next happened:
{
"errors": [
{
"message": "Syntax Error: Expected Name, found String \"query\"",
"locations": [
{
"line": 1,
"column": 2
}
]
}
]
}
Trying to do a post on a graph query in rest assured and couldn't get the query right.
Request:
"{query\":inventoryPositions(productRef:\"SKU_3\"){edges{node{onHand quantities{edges{node{ref quantity type}}}}}}}")
Response:
{
"errors": [
{
"code": "400",
"message": "Could not read document: Unexpected character ('q' (code 113)): was expecting double-quote to start field name\n
}
]
}
I have also tried this but not working:
{"query":"{inventoryPositions(productRef:\"SKU_3\"){edges{node{onHand quantities{edges{node{ref quantity type}}}}}}}"}
Please help.
basically it need 2 escape wherever u post a variable for example
"{\n"
+ "\"query\": \"{inventoryPositions(productRef: \\"SKU_3\\" locationRef: \\"locRef1\\"){edges{node{onHand quantities{edges{node{ref quantity type}}}}}}}\"\n"
+ "}"
worked for me