After long hours session of finding any documentation, I am forced to ask the community.
Currently the query I am making from Java code(also tried the same with Postman) to query GraphQL:
Request:
{"query":"{findPublisherByLicenseNumber(licenseNumber : \"UAE_DXB_CMH-971\") {name licenseNumber}}"}
Response:
{
"data": {
"findPublisherByLicenseNumber": {
"name": "Cantaloupe Media House",
"licenseNumber": "UAE_DXB_CMH-971"
}
}
}
This is the query which I have made in my backend to query endpoint: http://mg-api.com/mg-graphQL
As of now I have mentioned two fields only but actual Schema has many.
type Publisher {
ID: ID!
name: String!
licenseNumber: String!
address: String
contactNumber: String
mobileNumber: String
areaCode: Int!
...
... #few more fields
books: [Book]
}
extend type Query {
findAllPublishers: [Publisher]!
findPublisherByLicenseNumber(licenseNumber: String!) : Publisher!
}
The fragment that I want to add in Query:
fragment publisherInfo on Publisher {
ID
name
licenseNumber
address
contactNumber
areaCode
}
Tried like this
{"query":"{findPublisherByLicenseNumber(licenseNumber : \"UAE_DXB_CMH-971\") {...publisherInfo}}", "fragment" : "fragment publisherInfo on Publisher {ID name licenseNumber address contactNumber areaCode }"}
but got ValidationError with message : Undefined fragment publisherInfo.
{
"data": null,
"errors": [
{
"message": "Validation error of type UndefinedFragment: Undefined fragment pubInfo # 'findPublisherByLicenseNumber'",
"locations": [
{
"line": 1,
"column": 67,
"sourceName": null
}
],
"description": "Undefined fragment pubInfo",
"validationErrorType": "UndefinedFragment",
"queryPath": [
"findPublisherByLicenseNumber"
],
"errorType": "ValidationError",
"path": null,
"extensions": null
}
]
}
When I try to achieve the same with GraphiQL UI then it works.
I have not started to look to call this from UI Frameworks where I need to use graphql.js in Vanilla JS/Angular/React/Vue etc.
As of now I am looking to utilize this from my backend code logic as there is a middleware between UI and my graphql service.
The only thing I found was left unanswered and if answered then totally in vague manner : S.O Question
Any help is appreciated.
SOLVED
Need to pass fragment before method;
{"query":"fragment pubInfo on Publisher {name licenseNumber contactNumber} {findPublisherByLicenseNumber(licenseNumber :\"UAE_DXB_CMH-971\") {...pubInfo}}"}
SOLVED
Need to pass fragment before/after method call body {} in the same Query;
{"query":"fragment pubInfo on Publisher {name licenseNumber contactNumber} {findPublisherByLicenseNumber(licenseNumber :\"UAE_DXB_CMH-971\") {...pubInfo}}"}
Related
I am trying to post a text on LinkedIn using UGC through Postman.
Here is my request body:
{
"author": "urn:li:person:{uid of my account}",
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"text": "Hello World! This is my first Share on LinkedIn!"
},
"shareMediaCategory": "NONE"
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
}
}
Note: uid of my account is fetched through - https://api.linkedin.com/v2/me
The response I am getting is:
{
"message": "ERROR :: /author :: \"urn:li:person:oQRNppEnm\" does not match urn:li:company:\\d+|urn:li:member:\\d+\n",
"status": 422
}
Can anyone please help out here?
I had such a mistake. I used wrong value from https://api.linkedin.com/v2/me request answer. You need to add id in your request query if you haven't already,
for example
https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName)
also you need to use value from id field of JSON answer:
{"id\":\"XyyyyXXXXX\"}
It will be some kind of value with numbers and letters, not just numbers.
Im trying to make this operation in java:
db.product.aggregate([{
$match: { gtin: { $in: ["7890203", "7890204" ]}}}])
.group({
_id: "$gtin",
status: {$last: "$status"},
createdDate: {$last: "$createdDate"}
})
This return only the last document for given gtins. (Thats my goal).
The java code:
Criteria criteria = Criteria.where("gtin").in(gtinList);
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(criteria),
Aggregation.group("_id", "gtin")
.last("status").as("status")
.last("createdDate").as("createdDate"));
mongoTemplate.aggregate(aggregation, "product", Product.class).getMappedResults();
It return all the documents for the given gtins (i want only the last one based on createdDate).
I tried another approach for group like this:
Aggregation.group(Fields.from(Fields.field("_id", "gtin")))
.last("status").as("status")
.last("createdDate").as("createdDate"));
But i got an exception :nested exception is java.lang.IllegalArgumentException: invalid hexadecimal representation of an ObjectId: [9788580414851]
Same if i take out "_id" from group.
Can anyone help me achieve this?
Thanks in advance.
Edit: sample documents
{
"_id": "5fc140b3f6cb564068997e7d",
"sideProductId": {
"value": "89545"
},
"createdDate": "2020-11-27T18:08:51.799Z",
"lastUpdatedDate": "2020-11-27T18:08:52.860Z",
"status": "CONCLUDED",
"direction": "SIDE1_SIDE3",
"gtin": "78902030",
"attempt": 1,
"_class": "product.Product"
}
The response from mongoaggregation after the query:
{
"_id": "78902030",
"status": "CONCLUDED",
"createdDate": "2020-11-27T18:08:50.121Z"
}
Edit 2:
Finally got it. #varman asked about the java class i was using.
Mongotemplate was mapping to the #document class, which has the _id as an ObjectId.
Had to create a new class to map it correctly with only the fields i want.
_id, status, createdDate, but _id as a String to map gtin to it.
I have a model which looks like this:
{
"projectName": "MyFirstProject",
"projectId": "1234",
"testCaseList": [
{
"testCaseName": "TestCase1",
"steps": [
{
"Action": "Click on this",
"Result": "pass"
},
{
"Action": "Click on that",
"Result": "pass"
}
]
},
{
"testCaseName": "TestCase2",
"steps": [
{
"Action": "Click on him",
"Result": "pass"
},
{
"Action": "Click on her",
"Result": "pass"
}
]
}
]
}
However, as this is a nested object, I am having difficulties updating it using the method:
default PanacheUpdate update(String update, Object... params)
I am using Repository Pattern and below is my code snippet:
List<TestCase> newTestCaseList = ...;
update("testCaseList", newTestCaseList).where("projectId=?1",projectId);
which actually throws the following error:
org.bson.json.JsonParseException: JSON reader was expecting ':' but found ','.
at org.bson.json.JsonReader.readBsonType(JsonReader.java:149)
at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:82)
at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:41)
at org.bson.codecs.BsonDocumentCodec.readValue(BsonDocumentCodec.java:101)
at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:84)
at org.bson.BsonDocument.parse(BsonDocument.java:63)
at io.quarkus.mongodb.panache.runtime.MongoOperations.executeUpdate(MongoOperations.java:634)
at io.quarkus.mongodb.panache.runtime.MongoOperations.update(MongoOperations.java:629)
My Current Approach
What currently works for me is to use default void update(Entity entity) instead when updating nested objects.
This however presents a few considerations:
Extra code is required to fetch the entire document, parse through, and update the required fields
Since update(Entity entity) works on a document level, it will also update unchanged parts of the document, which isn't ideal.
I guess the encountered error states nothing but a limitation of Panache for mongoDB for the moment through the standard offered PanacheQL.
The issue should be worked-around using native mongoDB Java API that can be accessed through the PanacheMongoEntityBase#mongoCollection:
mongoCollection().updateOne(
eq("projectId", projectId),
new Document("$set", new Document("testCaseList", newTestCaseList))
);
Is it possible to set the value of context variable from java. I have modified the node json and added a action in that action in the result property I want to set data from my local database. So I am getting the action in java code and trying to set the value of result property of action object, below is the code which i am trying but it is not working. can some one suggest a better approach for this.
if(response.getActions()!=null) {
System.out.println("actions : "+response.getActions());
for (int i = 0; i < response.getActions().size(); i++) {
System.out.println(" i : "+response.getActions().get(i).getName());
if(response.getActions().get(i).getName()=="Apply_For_Loan") {
response.getActions().get(i).setResultVariable("123");
}
}
}
For setting value of result_variable in to the context below is my code.
if(response.getActions().get(i).getName().equals("Apply_For_Loan")) {
System.out.println("in action");
Assistant service = new Assistant("2018-12-12");
service.setUsernameAndPassword(userId, password);
service.setEndPoint(endPoint);
String result=response.getActions().get(i).getResultVariable();
Context context = response.getContext();
context.put(result, "123");
MessageOptions msg=new MessageOptions.Builder(watsonId)
.input(new InputData.Builder("Apply For Loan").build())
.context(context)
.build();
response=service.message(msg).execute();
System.out.println("msg : "+response);
}
Below is the response which i am getting after re-executing the assistant call.
{
"output": {
"generic": [
{
"response_type": "text",
"text": "Hello RSR, you loan application of 5420 is created. Please note the Loan Number for future use "
}
],
"text": [
"Hello RSR, you loan application of 5420 is created. Please note the Loan Number for future use "
],
"nodes_visited": [
"node_1_1544613102320",
"node_1_1544613102320"
],
"log_messages": []
},
"input": {
"text": "Apply For Loan"
},
"intents": [
{
"intent": "ApplyForLoan",
"confidence": 1.0
}
],
"entities": [],
"context": {
"number": 9.971070056E9,
"$Loan_Number": "123",
"system": {
"initialized": true,
"dialog_stack": [
{
"dialog_node": "node_1_1544613102320"
}
],
"dialog_turn_counter": 3.0,
"dialog_request_counter": 3.0,
"_node_output_map": {
"node_1_1544613102320": {
"0": [
0.0
]
}
},
"branch_exited": true,
"branch_exited_reason": "completed"
},
"Mail_Id": "Email_Id",
"conversation_id": "b59c7a02-2cc6-4149-ae29-602796ab22e1",
"person": "RSR",
"rupees": 5420.0
},
"actions": [
{
"name": "Apply_For_Loan",
"type": "client",
"parameters": {
"pername": "RSR",
"loanamount": 5420.0
},
"result_variable": "$Loan_Number"
}
]
}
In above response $Loan_Number is the result variable which i have updated from java code and the same result_variable i am using in the output text to return the $Loan_Number, but in output text it is still coming blank and in actions also it is still coming blank?
The simple answer to your question is no, you can't set anything in the JSON Model using setResultVariable. It should work like this:
1) Define an action on your Dialognode
The result_variable defines the <result_variable_name>, e.g. where the result of that action should be stored in the conversation context. If you execute some server side action, you read the result from the specified context location. In this example, the location is context.result_of_action, the context might be omitted. More details are here.
2) Process the action in Java Client
DialogNodeAction action = response.getActions().get(0);
final String result_variable = action.getResultVariable();
The result_variable is like a key. You obtain the value from your DB and add it to the context:
Context context = response.getContext();
context.put(result_variable, "value from DB");
new MessageOptions.Builder("Your ID")
.input(new InputData.Builder("Your response").build())
.context(context) // setting context
.build();
Finally the Watson Assistant Dialog (or some other App) can get the result from the Client:
"context": {
"result_of_action": "value from DB",
The Objects you read using the Java API are being parsed from JSON using Gson and need to be re-parsed back to JSON when construction a new API Call.
Edit after question update
In your example:
"actions": [
{
"name": "Apply_For_Loan",
"type": "client",
"parameters": {
"pername": "RSR",
"loanamount": 5420.0
},
"result_variable": "$Loan_Number"
}
the key result_variable tells other modules in your app where to find the result of your action. So $Loan_Number should not be the value but the key to the value in the session context (a kind of method contract).
Let's say you set the value to context.my_result, then your Watson Assistant should be able to access the "123" from DB in the next dialog node under "context.my_result".
First, sorry for my poor english, but let me try to explain my problem.
I'm working in an application using elasticsearch java api for managed my documents.
Everything works fine, i'm able to search in DB and save on my index, i can count my documents aggregate by field and a lot of cool things, but i stucked on a weird problem.
When i trying to search my document by field called name, some documents doesn't return on search.
Let me give an example:
My documents is look like this(just for example):
id: 1
name: book
type: pdf
id: 2
name: Test of my search service
type: zip
When i trying to search, if i search by name, send as parameter the value "book", it works fine, but when i trying to search, send my parameter value "service", the result is empty.
Here my search code:
SearchRequestBuilder src1 = client.prepareSearch().setQuery(QueryBuilders.queryStringQuery(parameter).field("name"));
Anyone knows, why this search doesn't find my parameter value "service" on name field of document with id 2?
Thanks!
Additional information:
My general index information:
{
"template": "*",
"settings": {
"index.refresh_interval": "5s"
},
"mappings": {
"_default_": {
"_all": {
"enabled": true
},
"dynamic_templates": [
{
"string_fields": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"index": "not_analyzed",
"omit_norms": true,
"type": "string"
}
}
}
],
"properties": {
"#version": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
Well, after searching for hours and hours, i solved my problem.
To solve this issue, i used the wildcards query from elasticsearch java api and now i'm able to search a string parameter in my fields.
Here's the code:
SearchRequestBuilder srch1 = client.prepareSearch()
.setIndices("index_name")
.setTypes("type_name")
.setSearchType(SearchType.DFS_QUERY_AND_FETCH)
.setQuery(QueryBuilders.wildcardQuery("field_name", "*"+string_parameter+"*"));
After construction of your SearchRequestBuilder just add it into your MultipleSearchResponse or SearchResponse:
MultiSearchResponse sr = client.prepareMultiSearch()
.add(srch1)
.add(srch2)
.add(srch3)
.execute().actionGet();
In my case, i have 3 distinct queries, so i used MultipleSearchResponse.