Yoga GraphiQL error: NOT NULL constraint failed: <model_id>.custom_Author

Hi Team,

I’m following the composeDB Get Start document and playing with composites and graphQL.

I created and deployed my first composite and start a graphql server with --did-private-key indicated in my terminal. However, when I tried to use mutation to create a piece of data, I got an authentication error:

Blockquote ERR Error: Ceramic instance is not authenticated
at mutateAndGetPayload (file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@composedb/runtime/dist/schema.js:530:27)
at resolve (/opt/homebrew/lib/node_modules/@composedb/cli/node_modules/graphql-relay/mutation/mutation.js:51:23)
at executeField (file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@graphql-tools/executor/esm/execution/execute.js:294:24)
at ValueOrPromise.then.results. (file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@graphql-tools/executor/esm/execution/execute.js:220:41)
at new ValueOrPromise (/opt/homebrew/lib/node_modules/@composedb/cli/node_modules/value-or-promise/build/main/ValueOrPromise.js:14:21)
at file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@graphql-tools/executor/esm/execution/execute.js:220:16
at promiseReduce (file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@graphql-tools/utils/esm/jsutils.js:15:15)
at executeFieldsSerially (file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@graphql-tools/executor/esm/execution/execute.js:218:12)
at executeOperation (file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@graphql-tools/executor/esm/execution/execute.js:202:18)
at file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@graphql-tools/executor/esm/execution/execute.js:62:37 {
path: [ ‘createWordBlock’ ],
locations: [ { line: 2, column: 3 } ],
extensions: [Object: null prototype] {}
}

Does anyone have an idea how I can solve this problem? Thank you.

Sorry. I didn’t add the private key correctly. But there is still error when I create data:

ERR Error: HTTP request to ‘http://0.0.0.0:7007/api/v0/streams’ failed with status ‘Internal Server Error’: {“error”:“insert into kjzl6hvfrbw6cau91r014mzfyldnlmkgbkw4x20rvmofihjh2lrt2ma56j1p170 (controller_did, created_at, custom_Author, first_anchored_at, last_anchored_at, stream_content, stream_id, tip, updated_at) values (‘did:key:z6MknNKJWbPnKXaCtRhUd9ompahUMwk4mBMzRYM8ZQJGMpq2’, 1679973714512, NULL, NULL, NULL, ‘{"Date":"2023-03-28T13:51:00Z","Type":"Text Block","Content":"My First WordBlock in composeDB"}’, ‘kjzl6kcym7w8yb8hj2gifgvydmm8b1hdgrhj1jxakxsgrdp8ifnknrg8kav8bjv’, ‘bagcqcera73sbf4cs52qaplksoqeuljtgl4rdwimkev7v7fzm3epzqecwcn5q’, 1679973714512) on conflict (stream_id) do update set stream_id = ‘kjzl6kcym7w8yb8hj2gifgvydmm8b1hdgrhj1jxakxsgrdp8ifnknrg8kav8bjv’,controller_did = ‘did:key:z6MknNKJWbPnKXaCtRhUd9ompahUMwk4mBMzRYM8ZQJGMpq2’,stream_content = ‘{"Date":"2023-03-28T13:51:00Z","Type":"Text Block","Content":"My First WordBlock in composeDB"}’,tip = ‘bagcqcera73sbf4cs52qaplksoqeuljtgl4rdwimkev7v7fzm3epzqecwcn5q’,updated_at = 1679973714512 - SQLITE_CONSTRAINT: NOT NULL constraint failed: kjzl6hvfrbw6cau91r014mzfyldnlmkgbkw4x20rvmofihjh2lrt2ma56j1p170.custom_Author”}
at fetchJson (file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@ceramicnetwork/common/lib/utils/http-utils.js:27:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Document.createFromGenesis (file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@ceramicnetwork/http-client/lib/document.js:43:27)
at async CeramicClient.createStreamFromGenesis (file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@ceramicnetwork/http-client/lib/ceramic-http-client.js:48:24)
at async DocumentLoader.create (file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@composedb/runtime/dist/loader.js:67:24)
at async Object.createDoc (file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@composedb/runtime/dist/context.js:25:20)
at async mutateAndGetPayload (file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@composedb/runtime/dist/schema.js:532:126)
at async file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/@envelop/core/esm/orchestrator.js:373:27
at async YogaServer.getResultForParams (file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/graphql-yoga/esm/server.js:324:26)
at async YogaServer.handle (file:///opt/homebrew/lib/node_modules/@composedb/cli/node_modules/graphql-yoga/esm/server.js:74:29) {
path: [ ‘createWordBlock’ ],
locations: [ { line: 2, column: 3 } ],
extensions: [Object: null prototype] {}
}

I don’t think this “custom_Author” can be set up by me.

Hey @monicaz. Would you be able to share your Ceramic daemon config here? Do you have any configurations for anchor there? If you could share the contents of your daemon.config.json here that would be helpful.
In addition to that, do you get this error only when you write mutations? Are you able to read the data?

Hi @Justina ,

I only added my admin-did to the config file.

{
“anchor”: {
“auth-method”: “did”
},
“http-api”: {
“cors-allowed-origins”: [
“.*”
],
“admin-dids”: [“did:key:…<my_did>”]
},
“ipfs”: {
“mode”: “bundled”
},
“logger”: {
“log-level”: 2,
“log-to-files”: false
},
“metrics”: {
“metrics-exporter-enabled”: false
},
“network”: {
“name”: “testnet-clay”
},
“node”: {
“privateSeedUrl”: “inplace:ed25519#f2dc87ff7602da7a305c7b147b123323cb1eeb66e02c1ebca2c62d17b092474f”
},
“state-store”: {
“mode”: “fs”,
“local-directory”: “/Users/tongyuzhao/.ceramic/statestore/”
},
“indexing”: {
“db”: “sqlite:///Users/tongyuzhao/.ceramic/indexing.sqlite”,
“allow-queries-before-historical-sync”: true,
“disable-composedb”: false,
“enable-historical-sync”: false
}
}

And yes, I think I only get this error from mutations. I created my own models and composite so I don’t have existing data to query. But I can get a blank list back when I try to read data. Like this:

{
“data”: {
“wordBlockIndex”: {
“edges”:
}
}
}

Please investigate this issue. Thank you!

Thanks for sharing this @monicaz. I tried to replicate this but can’t seem to get the same error. When you start your ceramic node, do you see the following in the output?

[2023-03-29T15:39:21.420Z] IMPORTANT: Connected to anchor service 'https://cas-clay.3boxlabs.com' with supported anchor chains ['eip155:100']
[2023-03-29T15:39:27.874Z] IMPORTANT: Ceramic API running on 0.0.0.0:7007'

Hi @Justina,

Yes, I can see the logs below:

[2023-03-28T23:05:56.386Z] IMPORTANT: Connecting to IPFS node available as /ip4/10.6.16.170/tcp/4011/p2p/12D3KooWHPfV5Hyf5hjG7PbBJC8RXGCgnM5J7SnzgmVmDbG74Gsg, /ip4/127.0.0.1/tcp/4011/p2p/12D3KooWHPfV5Hyf5hjG7PbBJC8RXGCgnM5J7SnzgmVmDbG74Gsg

[2023-03-28T23:05:56.410Z] IMPORTANT: Initializing SQLite connection

[2023-03-28T23:06:00.322Z] IMPORTANT: DID set to ‘did:key:’

[2023-03-28T23:06:00.322Z] IMPORTANT: Connecting to ceramic network ‘testnet-clay’ using pubsub topic ‘/ceramic/testnet-clay’

[2023-03-28T23:06:00.352Z] IMPORTANT: Starting indexing for Model kjzl6hvfrbw6cau91r014mzfyldnlmkgbkw4x20rvmofihjh2lrt2ma56j1p170

[2023-03-28T23:06:03.786Z] IMPORTANT: Starting indexing for Model kjzl6hvfrbw6c6nykczv7cohwpopwv63ysq9ffppwhhdoy1jhve7akwysgfc3pd

[2023-03-28T23:06:04.516Z] IMPORTANT: Starting indexing for Model kjzl6hvfrbw6c5ru0l2ugftet212h5ke9wp1tr54asc0ccxfijks48wriw44pxi

[2023-03-28T23:07:44.223Z] IMPORTANT: Connected to anchor service ‘https://cas-clay.3boxlabs.com’ with supported anchor chains [‘eip155:100’]

[2023-03-28T23:07:44.885Z] IMPORTANT: Ceramic API running on 0.0.0.0:7007’

I think I may find the problem. The DID shown in the log “IMPORTANT: DID set to ‘did:key:’” is different from the did I created from the private key( == the did I added to the config file). How would this happen?

Ok, after deeper investigation, I am almost certain that issue is related to how data model is defined (more specifically - constraints on specific fields) and the data that is being written when mutation is being performed.

Would you be able to share the mutation you are trying to run? I’d like to try and replicate it.

Thank you for the help!

I have three models: WordBlock; Tag; and BlockTag(relation). They are in a many-to-many relationship.
The runtime.json file looks like this:

{
“models”: {
“WordBlock”: {
“id”: “kjzl6hvfrbw6cau91r014mzfyldnlmkgbkw4x20rvmofihjh2lrt2ma56j1p170”,
“accountRelation”: { “type”: “list” }
},
“Tag”: {
“id”: “kjzl6hvfrbw6c6nykczv7cohwpopwv63ysq9ffppwhhdoy1jhve7akwysgfc3pd”,
“accountRelation”: { “type”: “list” }
},
“BlockTag”: {
“id”: “kjzl6hvfrbw6c5ru0l2ugftet212h5ke9wp1tr54asc0ccxfijks48wriw44pxi”,
“accountRelation”: { “type”: “list” }
}
},
“objects”: {
“WordBlock”: {
“Url”: { “type”: “string”, “required”: false },
“Date”: { “type”: “datetime”, “required”: true },
“Note”: { “type”: “string”, “required”: false },
“Type”: { “type”: “string”, “required”: true },
“Author”: { “type”: “did”, “required”: false },
“Status”: { “type”: “string”, “required”: false },
“Content”: { “type”: “string”, “required”: true },
“Tags”: {
“type”: “view”,
“viewType”: “relation”,
“relation”: {
“source”: “queryConnection”,
“model”: “kjzl6hvfrbw6c5ru0l2ugftet212h5ke9wp1tr54asc0ccxfijks48wriw44pxi”,
“property”: “WordlBlockID”
}
}
},
“Tag”: {
“Text”: { “type”: “string”, “required”: true },
“WordBlocks”: {
“type”: “view”,
“viewType”: “relation”,
“relation”: {
“source”: “queryConnection”,
“model”: “kjzl6hvfrbw6c5ru0l2ugftet212h5ke9wp1tr54asc0ccxfijks48wriw44pxi”,
“property”: “TagID”
}
}
},
“BlockTag”: {
“TagID”: { “type”: “streamid”, “required”: true },
“WordBlockID”: { “type”: “streamid”, “required”: true },
“Tags”: {
“type”: “view”,
“viewType”: “relation”,
“relation”: {
“source”: “document”,
“model”: “kjzl6hvfrbw6c6nykczv7cohwpopwv63ysq9ffppwhhdoy1jhve7akwysgfc3pd”,
“property”: “TagID”
}
},
“WordBlock”: {
“type”: “view”,
“viewType”: “relation”,
“relation”: {
“source”: “document”,
“model”: “kjzl6hvfrbw6cau91r014mzfyldnlmkgbkw4x20rvmofihjh2lrt2ma56j1p170”,
“property”: “WordBlockID”
}
}
}
},
“enums”: {},
“accountData”: {
“wordBlockList”: { “type”: “connection”, “name”: “WordBlock” },
“tagList”: { “type”: “connection”, “name”: “Tag” },
“blockTagList”: { “type”: “connection”, “name”: “BlockTag” }
}
}

And the mutation request is

mutation CreateNewWordBlock($i: CreateWordBlockInput!) {
createWordBlock(input: $i) {
document {
id
Date
Type
Content
}
}
}

Variables:

{
“i”: {
“content”: {
“Date”: “2023-03-28T13:51:00Z”,
“Type”: “Text Block”,
“Content”: “My First WordBlock in composeDB”
}
}
}

Any idea?

@Justina

And error message in Graphiql

Hi @Justina,

I found the problem and successfully created a piece of data!

I have to add an Author to create a block. However, when I create the schema, I set Author as not required. The idea is that the Author of a block and the Owner of a block can be different people. And the Author can be Unknown as well. Is it possible that I can skip the Author field? Or I should always set the default Author to the current user?

Thank you.