graphQLErrors is undefined, how extract errors from apollo response - graphql

I am implemented class-validator on the server for a registration form. My goal is to catch errors and write an error message to a specific field by error.
I read in docs that should get errors from graphQLErrors but in my case it is undefined.
my mutation:
const { data, errors } = await apolloClient.mutate<RegistrationWithEmail, RegistrationWithEmailVariables>({
mutation: registrationWithEmailMutation,
variables: {
payload: {
....
},
},
})
errors object:
"[
{
"message": "Argument Validation Error",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"registrationWithEmail"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"validationErrors": [
{
"target": {
"role": "creator",
"email": "myemail#email.com",
"password": "myweakpassword",
"firstName": "Edgaras",
"lastName": "Karka"
},
"value": "myweakpassword",
"property": "password",
"children": [],
"constraints": {
"matches": "WEAK_PASSWORD"
}
}
],
"stacktrace": [
"Error: Argument Validation Error",
" at Object.<anonymous> (/node_modules/type-graphql/dist/resolvers/validate-arg.js:21:19)",
" at Generator.throw (<anonymous>)",
" at rejected (/node_modules/tslib/tslib.js:105:69)",
" at processTicksAndRejections (internal/process/task_queues.js:86:5)"
]
}
}
}
]"

In case this might help someone, you can access the error properties by
yourMutation().catch(err => console.log(err.graphQLErrors[0].extensions.code))

Related

Google Ads API - Optimize Campaign By Specific Conversion Action(s)

I am using Google Ads PHP library to create Campaign.
I created almost any type of campaigns but didn't manage to optimize them by specific Conversion Actions.
For example:
I have created 3 different Conversion Actions:
customers/[CUSTOMER_ID]/conversionActions/[CONVERSION_ACTION_ID_0]
customers/[CUSTOMER_ID]/conversionActions/[CONVERSION_ACTION_ID_1]
customers/[CUSTOMER_ID]/conversionActions/[CONVERSION_ACTION_ID_2]
Then I created a Campaign:
customers/[CUSTOMER_ID]/campaigns/[CAMPAIGN_ID]
I set bidding strategy to MAXIMIZE_CONVERSIONS and then tried to set Conversion Actions to optimize to.
This is my code snippet:
$campaign->setMaximizeConversions(
new CommonMaximizeConversions([
'target_cpa' => $this->convert()->micros(1)
])
);
$campaign->setSelectiveOptimization(
new SelectiveOptimization([
'conversion_actions' => [
'customers/[CUSTOMER_ID]/conversionActions/[CONVERSION_ACTION_ID_0]',
'customers/[CUSTOMER_ID]/conversionActions/[CONVERSION_ACTION_ID_1]'
]
])
);
It gives me this error:
{
"message": {
"message": "Request contains an invalid argument.",
"code": 3,
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.ads.googleads.v10.errors.GoogleAdsFailure",
"errors": [
{
"errorCode": {
"requestError": "UNKNOWN"
},
"message": "The error code is not in this version.",
"trigger": {
"stringValue": ""
},
"location": {
"fieldPathElements": [
{
"fieldName": "operations",
"index": 0
},
{
"fieldName": "create"
},
{
"fieldName": "selective_optimization"
},
{
"fieldName": "conversion_actions"
}
]
}
}
],
"requestId": "xbgMUFFeP4447GFW_nJrIA"
}
]
},
}
Can you tell me what I am doing wrong? Or suggest any help?.
Thanks.

Calling "Campaign Manager 360 API -> conversions.batchinsert " and getting all the time the error "code": "NOT_FOUND"

I am trying to create conversions using "Method: conversions.batchinsert" from the API Explorer provided by google on the same API page.
I do not why I am getting the error with code 200
Request
{
"kind": "dfareporting#conversionsBatchInsertRequest",
"conversions": [
{
"timestampMicros": "1635788776043000",
"ordinal": "1635788776043000",
"kind": "dfareporting#conversion",
"floodlightConfigurationId": "12067120",
"floodlightActivityId": "11765909",
"dclid": "testdclid"
}
]
}
Response
{
"hasFailures": true,
"status": [
{
"conversion": {
"floodlightConfigurationId": "12067120",
"floodlightActivityId": "11765909",
"timestampMicros": "1635788776043000",
"ordinal": "1635788776043000",
"kind": "dfareporting#conversion",
"dclid": "testdclid"
},
"errors": [
{
"code": "NOT_FOUND",
"message": "",
"kind": "dfareporting#conversionError"
}
],
"kind": "dfareporting#conversionStatus"
}
],
"kind": "dfareporting#conversionsBatchInsertResponse"
}
```

Apollo GraphQL Server - Multiple queries from the same single request returns only only error despite all the queries returns errors

We are making a GraphQL request with multiple different queries (query1 and query2) in it. Both of these queries return an error(NOT_FOUND_ERROR) from our business logic and we are expecting a response with 2 errors in it. But we are getting a response with only one error. Why are we not getting multiple errors in the response?
E.g.
Query
query {
query1 {
id
}
query2 {
id
}
}
Expected Response (2 Errors)
{
"errors": [
{
"message": "NOT_FOUND_ERROR",
"locations": [
{
"line": 2,
"column": 5
}
],
"path": [
"device"
],
"extensions": {
"code": "NOT_FOUND_ERROR"
}
},
{
"message": "NOT_FOUND_ERROR",
"locations": [
{
"line": 2,
"column": 5
}
],
"path": [
"device"
],
"extensions": {
"code": "NOT_FOUND_ERROR"
}
}
],
"data": null
}
Current Response (1 Error)
{
"errors": [
{
"message": "NOT_FOUND_ERROR",
"locations": [
{
"line": 2,
"column": 5
}
],
"path": [
"device"
],
"extensions": {
"code": "NOT_FOUND_ERROR"
}
}
],
"data": null
}
We are getting multiple errors as expected when the request has invalid queries.
E.g.
Query
query {
invalid_query1 {
id
}
invalid_query2 {
id
}
}
How can I get multiple custom errors from our business logic when using multiple queries in the same request?
Version: apollo-server-express(2.15.1)
Thank you

Google compute engine API:backendError(503)

I am having trouble figuring out the problem with the API hit to create a Google virtual machine through Google Compute Engine API.
URL: https://cloud.google.com/compute/docs/reference/latest/instances/insert?apix=true#examples
My request data is:
{
"machineType": "zones/us-central1-c/machineTypes/f1-micro",
"name": "api-test",
"networkInterfaces": [
{
"accessConfigs": [
{
"type": "ONE_TO_ONE_NAT",
"name": "External NAT"
}
],
"network": "global/networks/default"
}
],
"disks": [
{
"boot": true,
"autoDelete": true,
"type": "SCRATCH"
}
]
}
and I am getting output:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "Code: '55C355EC47648.A8E5D85.FA0DAF10'"
}
],
"code": 503,
"message": "Code: '55C355EC47648.A8E5D85.FA0DAF10'"
}
}
Doesn't give me any reason for the error. Same issue is when I hit the API using Ruby Library. Authentication is fine as I can do various other stuff like getting the images and running instances data. Please help me out.
Figured out the problem. We have to use the disks type as "PERSISTENT" rather than "SCRATCH" and specify the disks["initializeParams"]["sourceImage"] as an existing image from https://console.cloud.google.com/compute/images and then use it like this in the request body of your request:
{
"name": "api-test3",
"machineType": "zones/us-central1-c/machineTypes/f1-micro",
"networkInterfaces": [
{
"accessConfigs": [
{
"type": "ONE_TO_ONE_NAT",
"name": "External NAT"
}
],
"network": "global/networks/default"
}
],
"disks": [
{
"boot": "true",
"type": "PERSISTENT",
"autoDelete": "true",
"initializeParams": [
{
"sourceImage": "global/images/ubuntu-1404-lts"
}
]
}
]
}

How to parse json with mixed child objects using Sprint Rest Template

I have a json response which looks like below
{
"resourceType": "Topic",
"metadata": {
"lastUpdated": "2016-12-15T14:51:33.490-06:00"
},
"entry": [
{
"resource": {
"resourceType": "Outcome",
"issue": [
{
"response": "error",
"code": "exception"
},
{
"response": "success",
"code": "informational"
},
{
"response": "success",
"code": "informational"
}
]
}
},
{
"resource": {
"resourceType": "Data",
"id": "80",
"subject": {
"reference": "dataFor/80"
},
"created": "2016-06-23T04:29:00",
"status": "current"
}
},
{
"resource": {
"resourceType": "Data",
"id": "90",
"subject": {
"reference": "dataFor/90"
},
"created": "2016-06-23T04:29:00",
"status": "current"
}
}
]
}
Data and Outcome Class extends Resource.
I am using Spring RestTemplate.getForObject(url, someClass). I get below error
has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not read JSON: Unrecognized field "response" (Class com.model.Resource), not marked as ignorable
at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream#77a3e67a;
I understand that the json is not getting parsed to the child class of Resource. I want to do something like RestTemplate.getForObject(url, someClass) but this is not supported by java generics (wildcard). Please help
You'll want to use jackson to deserialize to a dynamic type, using resourceType as the field to indicate the actual type. Add these to your Resource class.
#JsonTypeInfo(property = "resourceType", use = Id.NAME)
#JsonSubTypes({ #Type(Data.class),
#Type(Outcome.class)
})
Here is a unit test that will prove out the behavior.
#Test
public void deserializeJsonFromResourceIntoData () throws IOException {
Data data = (Data) new ObjectMapper().readValue("{" +
" \"resourceType\": \"Data\"," +
" \"id\": \"80\"," +
" \"subject\": {" +
" \"reference\": \"dataFor/80\"" +
" }," +
" \"created\": \"2016-06-23T04:29:00\"," +
" \"status\": \"current\"" +
" }", Resource.class);
assertEquals(Integer.valueOf(80), data.getId());
assertEquals("dataFor/80", data.getSubject().getReference());
}
As for the cast, I've done it here just to demonstrate that it works, however, to be truly polymorphic, you probably want to have Resource contain all the behavior you need, and then everything is just a Resource.

Resources