I have a problem in my .NET Web API - I am just posting data in my table before I am checking Is the record already inserted in the table but I get this error:
An error occurred while starting a transaction on the provider connection. See the inner exception for details.
This is my code:
[HttpPost]
[Route("api/tblProducts/AddToWishCart", Name = "GetAddWishCartList")]
public IHttpActionResult AddToWishCart(tblWishCart3 wishList)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
IEnumerable<GetAllCartListByStatusAndUserPrdIdWeightId_Result> tblCartWishList = dbO.GetAllCartListByStatusAndUserPrdIdWeightId(wishList.Status, wishList.UserId, wishList.PrdId, wishList.Extra3).AsEnumerable();
if (tblCartWishList == null)
{
var AltAddress = dbO.AddWishCart4(wishList.UserId, wishList.PrdId, wishList.Name, wishList.Weight, wishList.MRP, wishList.SellingPrice, wishList.OffPerentage, wishList.Quantity, wishList.Status, wishList.AddDate, wishList.Pic1, wishList.Extra1, wishList.Extra2, wishList.Extra3, wishList.Extra4, wishList.Extra5, wishList.Extra6, wishList.Extra7, wishList.Extra8, wishList.Extra9, wishList.Extra10);
}
else
{
}
return CreatedAtRoute("GetAddWishCartList", new { id = wishList.UserId }, wishList);
}
Related
If there is an array inside the DTO, I tried using List<Map<String, Object>> but it doesn't work properly. Could you possibly know how?
Below is my code.
Below is my code.
#Test
void graphqlTest() {
Map<String, Object> tag = new ConcurrentHashMap<>() {{
put("id", 1L);
put("name", "aaaaa");
}};
List<Map<String, Object>> tagInputList = new ArrayList<>();
tagInputList.add(tag);
Map<String, Object> input = new ConcurrentHashMap<>() {{
put("list", tagInputList);
}};
graphQlTester.documentName("tag")
.operationName("followMyTags")
.variable("input", input)
.execute()
.errors()
.verify()
.path("followMyTags.list")
.entityList(TagDto.class);
}
Below is error message.
Response has 1 unexpected error(s) of 1 total. If expected, please filter them out: [server operation something wrong]
Request: document='query queryTags {
queryTags {
list {
id
name
}
}
}
query queryFollowedTags {
queryFollowedTags {
list {
id
name
}
}
}
mutation followMyTags($input: TagsInput!) {
followMyTags(input: $input) {
list {
id
name
}
}
}
mutation unfollowMyTags($input: TagsInput!) {
unfollowMyTags(input: $input) {
list {
id
name
}
}
}', operationName='followMyTags', variables={input={list=[{name=aaaaa, id=1}]}}
java.lang.AssertionError: Response has 1 unexpected error(s) of 1 total. If expected, please filter them out: [server operation something wrong]
I tried using an array instead of a list via toArray, but it still didn't work.
my requirement is to call Odata .net API from GraphQL service.
My GQL query
query
{
cARequests {
id
cARequestStatus
reviewedBy {
name
email
}
assignedTo {
name
email
}
reviewedBy {
name
}
requestDate
reasonIfRejected
mPxN
mPxN
account {
accountNumber
}
}
}
My ODATA Request
[HttpGet(Name = "GetCARequest")]
[EnableQuery(PageSize=10)]
public IQueryable<GQLOdata> Get()
{
return Enumerable.Range(1, 5).Select(index => new GQLOdata
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.AsQueryable();
}
I dont know how to call this ODATA API from GraphQL API. What configuration I have to make and what services I have to add. Please guide me in the right direction
I'm new to quarkus and reactive programming. I'm currently facing an issue with quarkus-reactive-postgresql extension.
I have a list containing events that perform a database update. Each event has to be updated independently (so I don't use a transaction).
Here is my web service:
#POST
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public Uni<JsonObject> synchro(List<Event> events) {
List<Uni<RowSet<Row>>> queries = new ArrayList<>();
List<Event> success = new ArrayList<>();
List<Event> fails = new ArrayList<>();
for (Event evt : events) {
// Perform update
var query = client.preparedQuery("My failing query")
.execute(Tuple.of(evt.field));
// Subscribe. It's ok. Add event to success list
query.subscribe().with(unused -> success.add(evt));
// It's failure. Add event to failures
query.onFailure(throwable -> {
log.error(String.format("Unable to update event %s", evt.toString()), throwable);
fails.add(evt);
return true;
});
queries.add(query);
}
return Uni.combine().all().unis(queries)
.combinedWith(ArrayList::new)
.onItem().transform(list -> new JsonObject()
.put("success", success.stream().map(Event::toJson).collect(Collectors.toList()))
.put("errors", fails.stream().map(Event::toJson).collect(Collectors.toList()))
);
}
Quarkus reactive pg extension throws an exception :
2021-08-06 10:35:37,665 ERROR [io.qua.mut.run.MutinyInfrastructure] (vert.x-eventloop-thread-23) Mutiny had to drop the following exception: io.vertx.pgclient.PgException: { "message": "column \"fake_column\" of relation \"table\" does not exist", "severity": "ERROR", "code": "42703", "position": "18", "file": "analyze.c", "line": "2263", "routine": "transformUpdateTargetList" }
However, .onFailure is not triggered and ever fill my failures list.
Is it a bug or something goes wrong with my code ?
Thanks for your help,
In case someone is struggling with this as I did, you can try adding the following code:
.onFailure().transform(ex -> {
if (ex.getClass().equals(PgException.class)) {
//here you can do log and stuff
//in case, you only need to return this boolean you can create
//custom handler for your custom exception
return new CustomException(ex);
}else{
return new Exception(ex);
});
transform() function somehow lets you return an exception no matter what your method was supposed to return, here is some resource for it:
https://cescoffier.github.io/mutiny-doc-sandbox/getting-started/handling-failures
Concerning handling the exception, here is a source that really helped me: https://howtodoinjava.com/resteasy/resteasy-exceptionmapper-example/
I have objects of type student and team in my schema and a table student_team that keeps records of their relationships.
To manage these I use the following calls:
// to add a student team relationship
mutation CreateStudentTeam($studentId: UUID!, $teamId: UUID!) {
createStudentTeam(
input: { studentTeam: { studentId: $studentId, teamId: $teamId } }
) {
student {
id
}
team {
id
}
}
}
// to remove a student team relationship
mutation DeleteStudentTeam($studentId: UUID!, $teamId: UUID!) {
deleteStudentTeamByStudentIdAndTeamId(input: {studentId:$studentId, teamId:$teamId}) {
student {
id
}
team {
id
}
}
}
// to view teams with students
query Teams {
teams {
nodes {
id
name
students {
nodes {
id
fullName
}
}
}
}
}
My application presents data based on these relationships as listings.
A team might be presented with a listing of students.
I'm a bit confused about how to update the local state after making these calls.
Would the best thing to do to just redo the fetch for the data with the Teams query?
I'd love to know how best to do it with the Apollo Link State.
Thanks!
You need to do it manually using update prop passed:
graphql(YourMutation, {
options: {
update: (cache, result) => {
const query = TeamsQuery
const currentQueryData = cache.readQuery({query})
const updatedData = //change your data regarding of the mutation
cache.writeQuery({query, data: graphql updatedData })
}
}
}
also have a look at this part of the docs
I've recently started exploring Graph databases (in particular Neo4j and OrientDB) and have come across a problem I can't seem to put my finger on.
I'm running a local installation of OrientDB (OrientDB Server v2.0-M3 is active.).
I'm using Tinkerpops to connect to, and run queries against, the graph.
I'm using Java and Spring on a local Tomcat 7 server.
Testing my API I'm using Postman on Chrome.
Here's my faulty GET method:
#RequestMapping(value = "/articles", method = RequestMethod.GET)
public
#ResponseBody
Vector<Article> list() {
OrientGraph graph = new OrientGraph("remote:/local/path/to/orientdb/databases/mydb", "user", "password");
FramedGraphFactory factory = new FramedGraphFactory();
FramedGraph manager = factory.create(graph);
Vector<Article> articles = new Vector<>();
try {
Iterable<Vertex> vertices = graph.getVerticesOfClass("Article", false);
Iterator<Vertex> it = vertices.iterator();
if (it.hasNext()) {
do {
Article a = (Article) manager.frame(it.next(), Article.class);
articles.add(a);
} while (it.hasNext());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
graph.shutdown();
}
return articles;
}
This generates the following error:
{
"timestamp": 1418562889304,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.http.converter.HttpMessageNotWritableException",
"message": "Could not write JSON: Database instance is not set in current thread. Assure to set it with: ODatabaseRecordThreadLocal.INSTANCE.set(db); (through reference chain: java.util.Vector[0]->$Proxy43[\"name\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Database instance is not set in current thread. Assure to set it with: ODatabaseRecordThreadLocal.INSTANCE.set(db); (through reference chain: java.util.Vector[0]->$Proxy43[\"name\"])",
"path": "/articles"
}
I've been trying to figure this out, trying the "fix" that the error suggests. I've also tried to use TransactionalGraph instead of OrientGraph.
Here's the catch... I'm also using a similar method for getting a single resource. This method only works if I'm using the "System.out.println", otherwise it fails with the same error.
#RequestMapping(value = "/article", method = RequestMethod.GET)
public
#ResponseBody
Article get(
#RequestParam(value = "number", required = true) long number
) {
TransactionalGraph graph = new OrientGraph("remote:/path/to/local/orientdb/orientdb/databases/mydb", "user", "password");
FramedGraphFactory factory = new FramedGraphFactory();
FramedGraph manager = factory.create(graph);
Article article = null;
try {
Iterable<Article> articles = manager.getVertices("number", number, Article.class);
article = articles.iterator().next();
System.out.println(article.getName());
} catch (Exception e) {
e.printStackTrace();
} finally {
graph.shutdown();
}
return article;
}
Any help appreciated!
You should leave the graph (=connection) open while you're using the result. Can you move the graph.shutdown() after browsing your result set?