The provided key element does not match the schema. GraphQL Mutation error - react-native

I am trying to test/run a mutation that creates groupChat in my DynamoDB by id,groupChatName, messages, createdTime, createdUser, users. I have 2 seperate tables, UserTable and GroupChatTable.The problem is I keep getting data is null and an error that says "the provided key element does not match the schema. ErrorCode: Validation Exception, request ID." Resolvers are attached to my tables so I am not sure why I am getting this error.
The weird thing is when I check the groupChatTable, my mutation is saved incorrectly as an input.This is what it looks like,
Ex: {"createdTime":{"S":"12:00"},"createdUser":{"S":"Me"},........
Below is the Mutation,Schema type,and Resolver.
createGroupChat(input:{
id: 4
groupChatName: "newgroup"
messages: "we love this group"
createdTime:"12:00"
createdUser: "Me"
users:"we, me"
}) {
id
groupChatName
messages
createdTime
createdUser
users
}
}```
```type GroupChat {
id: ID!
groupChatName: String!
messages: String
createdTime: String!
createdUser: String!
users: String
}```
```{
"version" : "2017-02-28",
"operation" : "PutItem",
"key" : {
"id": $util.dynamodb.toDynamoDBJson($util.autoId()),
},
"attributeValues" : $util.dynamodb.toMapValuesJson($ctx.args)
}```

It looks like the way data is being stored through resolver is incorrect and when it returns it doesn't match the schema
Instead of using $util.dynamodb.toMapValuesJson(($ctx.args))
use: $util.dynamodb.toMapValuesJson($util.parseJson($util.toJson($ctx.args.input)))

Related

GraphQL: Cannot return null for non-nullable field

I'd created gql fragment as below without photo part at first.
And then later I added photo {id} part on this fragment.
export const COMMENT_FRAGMENT = gql`
fragment CommentFragment on Comment {
id
user {
username
avatar
}
payload
isMine
createdAt
photo {
id
}
}
`;
But it shows error message:
"message": "Cannot return null for non-nullable field Comment.photo.",
"path": Array [
"seeFeed",
1,
"comments",
0,
"photo",
],
},
Strange thing is I checked several times that there's no null or empty field of photo.id of comments.
As you can see, Comment field has photo[] and photo has 'id', which means my fragment has no error.
When I searched about it people say it is not my query problem, but something about migration?
Can you help me? :(

How can I retrieve nested values in Keystone 5 for my list

I'm adding a list called 'tourlocation' to my Keystone 5 project. In my mongo database my tourlocations collection has an object called 'coordinates', with two values: 'lat' and 'long'. Example:
"coordinates" : {
"lat" : 53.343761,
"long" : -6.24953
},
In the previous version of keystone, I could define my tourlocation list coordinates object like this:
coordinates: {
lat: {
type: Number,
noedit: true
},
long: {
type: Number,
noedit: true
}
Now unfortunately, when I try to define the list this way it gives the error: The 'tourlocation.coordinates' field doesn't specify a valid type. (tourlocation.coordinates.type is undefined)'
Is there any way to represent objects in keystone 5?
#Alex Hughes I believe your error says "type" which you may need to add it like this
keystone.createList('User', {
fields: {
name: { type: Text }, // Look at the type "Text" even in the MongoDB you can choose the type but it will be better to choose it here from the beginning.
email: { type: Text },
},
});
Note that noedit: true is not supported in version 5 of KeystoneJS.
For more info look at this page https://www.keystonejs.com/blog/field-types#core-field-types

Is there a way to Index a doc to Elasticsearch with a specific _id filed?

I'm looking to simulate a state where I have a specific _id field inside an index.
Let's assume I want to take the EXACT same log from index1 in my example and index it into index2.
Like so:
This is my index1
{
_index: "index-number-one",
_type: "doc",
_id: "S0meSpec!f!cID",
_score: 1,
_source: {
message: "message1",
type: "type1",
tags: [
"_bla"],
number: 3
}
}
Now I want that exact same log in my index2
{
_index: "index-number-two",
_type: "doc",
_id: "S0meSpec!f!cID",
_score: 1,
_source: {
message: "message1",
type: "type1",
tags: [
"_bla"],
number: 3
}
}
Couldn't find an API in Elasticsearch that can insert a doc to an Index with a specific _id field... (?)
If this action isn't possible so that the Elasticsearch cluster won't have duplications in the _id field, I can imagine it's because they want to keep the ability to search a doc by it's _id
field which needs to be unique, in that case, assume that I don't mind deleting the entire doc from index1 (maybe save it aside as some variable in my code), but in the end, I need the doc in index2, to have the EXACT _id as index1 once had.
And if there's a way to edit an existing _id field it would also solve my problem.
Can anyone please shed any light on how to achieve that goal?
answer to myself,
I found that it can be done in a POST request on the index like so:
POST twitter/test-index-1234/abctype/Som3Cust0mID
{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}
And the outcome in ES:
{
_index: "test-index-1234",
_type: "abctype",
_id: "Som3Cust0mID",
_score: 1,
_source: {
user: "kimchy",
post_date: "2009-11-15T14:12:12",
message: "trying out Elasticsearch"
}
}
It is definitely possible to do this. IDs are unique per index, not per cluster.
Check the reindex API, it copies one index onto another and keeps the document IDs.
It is also possible to change the ID using a script inside the reindex call.

Validate the json Array with Either one field required in Mule 4

Request Json Looks like the below :-
{
"eNumber": 8506493,
"details": [
{
"id":12345,
"name": xyz123
}
]
}
As part of requirement, I need to check the "details" array that either "id" or "name" field must present. if "id" field is present, "name" is non-mandatory. if "name" field is present, "id" is non-mandatory. Throws error if not met.
I tried few options using filter the details array and check the size of the filtered array in the validation component. It does not seems to be working well. if anyone has got better solutions.please share it here.
This example code will return true or false if it passes your condition
%dw 2.0
import * from dw::core::Arrays
output application/json
---
payload.details every ((item) -> item.id? or item.name?)
The function I'm using is every that checks that all elements in an array passes the given criteria.
Later you can use a choice and a use the raise error or you can use the fail dw function with an if else.
You can restrict it at RAML level.
Sample RAML -
#%RAML 1.0
title: api
types:
test1:
type: object
properties:
id:
type: string
example: 123a
test2:
type: object
properties:
name:
type: string
example: xyz124
test3:
type: object
properties:
enumber:
type: string
example: 8506493a
details :
type: [test1 | test2]
/test:
post:
body:
application/json:
type: test3

400 error when trying to create a new user via createUser Mutation

When attempting to create a new user with the createUser mutation having just received the idToken from the Auth0 request, I receive the following error:
{
"data": null,
"errors": [{
"message": "Variable '$input_0' expected value of type 'SignupUserInput!' but got: {\"authProvider\":{\"auth0\":{\"idToken\":\"__idToken_Recieved_From_auth0_request__"}},\"clientMutationId\":\"0\"}. Reason: [in field 'name'] Expected non-null value, found null. (line 1, column 29):\nmutation CreateUserMutation($input_0:SignupUserInput!) {\n ^",
"locations": [{
"line": 1,
"column": 29
}]
}]
}
Any suggestions?
It looks like your User model has a required name field. If that is the case then you need to also add it to the mutation.