am I setting the schema wrongly? - graphql

am I setting the schema wrongly? I can mutation & Query in playground, but in the frontend hit this error: "Network error: Unexpected token < in JSON at position 0", then I checked in backend, that shows below message, may anyone help me?
# import * from './generated/prisma.graphql'
type Mutation{
createLeague(name: String, zhName: String, image: String, season: String, nation: String, clubs: Club): League!
createClub(name: String, zhName: String, tla: String, badge: String, leagues: League): Club!
}
type Query{
leagues: [League]!
clubs: [Club]!
}
Error: The type of Mutation.createLeague(clubs:) must be Input Type but got: Club.
The type of Mutation.createClub(leagues:) must be Input Type but got: League.
at assertValidSchema (/mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/graphql/type/validate.js:78:11)
at Object.validate (/mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/graphql/validation/validate.js:55:35)
at doRunQuery (/mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/apollo-server-core/dist/runQuery.js:111:42)
at /mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/apollo-server-core/dist/runQuery.js:21:56
at process._tickCallback (internal/process/next_tick.js:68:7)
Error: The type of Mutation.createLeague(clubs:) must be Input Type but got: Club.
The type of Mutation.createClub(leagues:) must be Input Type but got: League.
at assertValidSchema (/mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/graphql/type/validate.js:78:11)
at Object.validate (/mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/graphql/validation/validate.js:55:35)
at doRunQuery (/mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/apollo-server-core/dist/runQuery.js:111:42)
at /mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/apollo-server-core/dist/runQuery.js:21:56
at process._tickCallback (internal/process/next_tick.js:68:7)

Related

Parse message in CloudWatch Logs Insights

Here are two example messages of the lambda:
WARNING:
Field Value
#ingestionTime 1653987507053
#log XXXXXXX:/aws/lambda/lambda-name
#logStream 2022/05/31/[$LATEST]059106a15343448486b43f8b1168ec64
#message 2022-05-31T08:58:18.293Z b1266ad9-95aa-4c4e-9416-e86409f6455e WARN error catched and errorHandler configured, handling the error: Error: Error while executing handler: TypeError: Cannot read property 'replace' of undefined
#requestId b1266ad9-95aa-4c4e-9416-e86409f6455e
#timestamp 1653987498296
ERROR:
Field Value
#ingestionTime 1653917638480
#log XXXXXXXX:/aws/lambda/lambda-name
#logStream 2022/05/30/[$LATEST]bf8ba722ecd442dbafeaeeb3e7251024
#message 2022-05-30T13:33:57.406Z 8b5ec77c-fb30-4eb3-bd38-04a10abae403 ERROR Invoke Error {"errorType":"Error","errorMessage":"Error while executing configured error handler: Error: No body found in handler event","stack":["Error: Error while executing configured error handler: Error: No body found in handler event"," at Runtime.<anonymous> (/var/task/index.js:3180:15)"]}
#requestId 8b5ec77c-fb30-4eb3-bd38-04a10abae403
#timestamp 1653917637407
errorMessage
Error while executing configured error handler: Error: No body found in handler event
errorType
Error
stack.0 Error: Error while executing configured error handler: Error: No body found in handler event
stack.1 at Runtime.<anonymous> (/var/task/index.js:3180:15)
Can you help me understand how to set up the query in order to have a table with the following columns and their values:
from #message extract timestamp, requestID, type (WARN or ERROR), errorMessage and if feasible also the name of the lambda from #log and the #logStream.
If we'd look at the documentation on AWS Insights parse method
We can use asterisks * to capture details which for you would be:
fields #timestamp, #message, #log, #logStream, #requestId
| parse #message "* * * *" as timestamp, requestId, type, body
| display #timestamp, #requestId, #log, #logStream, body
If you'd like to also capture the error message try to now parse the body as well:
fields #timestamp, #message, #log, #logStream, #requestId
| parse #message "* * * *" as timestamp, requestId, type, body
| parse body "*,\"errorMessage\":\"*\"*" as startBody, errorMessage, endBody
| display #timestamp, #requestId, #log, #logStream, body, errorMessage
Should work but please feel free to look up any additional information in the AWS documentation, they've made it very thorough👌🏽

Failure: Inconsistent type in JSPB repeated field array. Got undefined expected object

Inconsistent type in JSPB repeated field array. Got undefined expected object +AssertionError: Failure: Inconsistent type in JSPB repeated field array. Got undefined expected object
I am using fabric, and I think this is a problem with the chain code, but can't point the problem.
here is the stacktrace:
Fri, 29 Apr 2022 13:12:24 GMT + Failure: Inconsistent type in JSPB repeated field array. Got undefined expected object +AssertionError: Failure: Inconsistent type in JSPB repeated field array. Got undefined expected object
at new goog.asserts.AssertionError (/Users/user/hl-f/backend/node_modules/google-protobuf/google-protobuf.js:87:1065)
at Object.goog.asserts.fail (/Users/user/hl-f/backend/node_modules/google-protobuf/google-protobuf.js:90:89)
at /Users/user/hl-f/backend/node_modules/google-protobuf/google-protobuf.js:502:168
at Array.forEach (<anonymous>)
at Object.goog.array.forEach (/Users/user/hl-f/backend/node_modules/google-protobuf/google-protobuf.js:101:188)
at Function.jspb.Message.assertConsistentTypes_ (/Users/user/hl-f/backend/node_modules/google-protobuf/google-protobuf.js:502:114)
at Function.jspb.Message.bytesListAsU8 (/Users/user/hl-f/backend/node_modules/google-protobuf/google-protobuf.js:501:217)
at proto.protos.ChaincodeInput.getArgsList_asU8 (/Users/user/hl-f/backend/node_modules/#hyperledger/fabric-gateway/dist/protos/peer/chaincode_pb.js:557:59)
at proto.protos.ChaincodeInput.serializeBinaryToWriter (/Users/user/hl-f/backend/node_modules/#hyperledger/fabric-gateway/dist/protos/peer/chaincode_pb.js:508:15)
at jspb.BinaryWriter.writeMessage (/Users/user/hl-f/backend/node_modules/google-protobuf/google-protobuf.js:451:479)+
the code that do this is a simple AddAsset query that i modified,
#Transaction()
public async AddAsset(ctx: Context, assetid : string,email: string,phone :string,address :string): Promise<void> {
const exists = await this.AssetExists(ctx, assetid);
if (exists) {
throw new Error(`The asset ${assetid} already exists`);
}
const asset = {
AssetID: assetid,
Email: email,
Phone: phone,
Address: address,
};
await ctx.stub.putState(assetid, Buffer.from(stringify(sortKeysRecursive(asset))));
}
Always double check, triple check your app/backend, when encountering this problem.
you might have a similar problem to this:
json = {
Assetid : "123",
...
}
contract.submitTransaction("AddAsset", json.AssetID, ...);
explanation:
json.Assetid = 123
while
json.AssetID = undefined
I feel stupid, on how much time i wasted on this bug, thinking it was the chaincode,
And remember double, triple check.
And happy coding.

Why do I get "storage decode error: input too short" error?

So I have a rust contract that has a storage mapper for an arbitrary value. I store it based on a identifier which is an u64.
#[view(getVersion)]
#[storage_mapper("someValue")]
fn get_value(&self, identifier:u64) -> SingleValueMapper<u64>
When I query this using the API or erdJs I always get
{
"statusCode": 400,
"code": "user error",
"message": "storage decode error: input too short"
}
What am I doing wrong?
So what I was doing wrong here was not the code of the contract itself but rather I was calling a query for a value that was not stored.
I was trying to reach a value that was not set in my case. For example I had these values
1 -> 100
2 -> 200
3 -> 300
5 -> 500
notice how identifier "4" does not have any reference stored. So I was trying to query this view for the identifier "4" and therefore I was getting a storage decode error because the storage was empty for that value.

How to get file name that causes GraphQLError: Syntax Error: Unterminated string

In our team we sometimes get an GraphQl syntax error, when modifying our schema.
However, we don't seem to get the name of file causing the issue? The error looks like this:
GraphQLError: Syntax Error: Unterminated string.
at syntaxError (<full-path-to-project>>node_modules/graphql/error/syntaxError.js:15:10)
at readString (<full-path-to-project>>node_modules/graphql/language/lexer.js:513:38)
at readToken (<full-path-to-project>>node_modules/graphql/language/lexer.js:267:14)
at Object.lookahead (<full-path-to-project>>node_modules/graphql/language/lexer.js:54:43)
at Object.advanceLexer [as advance] (<full-path-to-project>>node_modules/graphql/language/lexer.js:44:33)
at Parser.parseStringLiteral (<full-path-to-project>>node_modules/graphql/language/parser.js:519:17)
at Parser.parseDescription (<full-path-to-project>>node_modules/graphql/language/parser.js:728:19)
at Parser.parseFieldDefinition (<full-path-to-project>>node_modules/graphql/language/parser.js:856:28)
at Parser.optionalMany (<full-path-to-project>>node_modules/graphql/language/parser.js:1497:28)
at Parser.parseFieldsDefinition (<full-path-to-project>>node_modules/graphql/language/parser.js:846:17)
at Parser.parseObjectTypeDefinition (<full-path-to-project>>node_modules/graphql/language/parser.js:798:23)
at Parser.parseTypeSystemDefinition (<full-path-to-project>>node_modules/graphql/language/parser.js:696:23)
at Parser.parseDefinition (<full-path-to-project>>node_modules/graphql/language/parser.js:146:23)
at Parser.many (<full-path-to-project>>node_modules/graphql/language/parser.js:1518:26)
at Parser.parseDocument (<full-path-to-project>>node_modules/graphql/language/parser.js:111:25)
at parse (<full-path-to-project>>node_modules/graphql/language/parser.js:36:17) {
message: 'Syntax Error: Unterminated string.',
locations: [ { line: 27, column: 51 } ]
}
Is this normal - and how do I get the file causing the problem?

Error: invalid argument 0: json: cannot unmarshal hex string of odd length into Go struct field SendTxArgs.data of type hexutil.Bytes

i have a problem that i've been trying to solve for a whole day...
I'm using Vagrant and truffle to migrate a couple of SmartContracts. The problem
occurs right at the migration when i get an error for one of the contracts.
This is the output of the console, any help will be very much appriciated:
Deploying StringUtils...
... 0xfff3df73a1aa886c9006dab692b3dd36fa0f0b4ab1a1f8a933b679c7d17cbadc
StringUtils: 0x9d13c6d3afe1721beef56b55d303b09e021e27ab
Linking StringUtils to Appalto
Deploying Appalto...
... undefined
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: invalid argument 0: json: cannot unmarshal hex string of odd length into Go struct field SendTxArgs.data of type hexutil.Bytes
at Object.InvalidResponse (C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\errors.js:38:1)
at C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\requestmanager.js:86:1
at C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-migrate\index.js:225:1
at C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-provider\wrapper.js:134:1
at XMLHttpRequest.request.onreadystatechange (C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\httpprovider.js:128:1)
at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:64:1)
at XMLHttpRequest._setReadyState (C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:354:1)
at XMLHttpRequest._onHttpResponseEnd (C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:509:1)
at IncomingMessage.<anonymous> (C:\Users\valer\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:469:1)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:139:11)
at process._tickCallback (internal/process/next_tick.js:181:9)```

Resources