Model relations Re: containers and items

Attempting to establish several bidirectional queries between models

Prototyping a DAO application for community growth.

Currently having trouble with the model architecture: GitHub - 0xCozart/nabu_server

type NabuProfileAlpha
  @loadModel(
    id: "kjzl6hvfrbw6c7m2o4v21vs0zc5b7y4lxrepf67z42ydmifpcnvxtby4fhu6mhl"
  ) {
  id: ID!
}

type DAO
  @loadModel(
    id: "kjzl6hvfrbw6c5e8lzp8pes8n3yrq5o3kai7el3yi7oqy44d85oksz90lczdfte"
  ) {
  id: ID!
}

type MembersDaoProfile
  @loadModel(
    id: "kjzl6hvfrbw6c75un6ip9ccmhbjh0ch38ds95ym675v66qjbg9phfzjeav03xpc"
  ) {
  id: ID!
}

type Relations
  @createModel(
    accountRelation: LIST
    description: "Relate Nabu profile to a DAO model."
  ) {
  nabuID: StreamID! @documentReference(model: "NabuProfileAlpha")
  nabu: NabuProfileAlpha! @relationDocument(property: "nabuID")
  membersDaoProfileID: StreamID! @documentReference(model: "MembersDaoProfile")
  membersDaoProfile: MembersDaoProfile!
    @relationDocument(property: "membersDaoProfileID")
  daoID: StreamID! @documentReference(model: "DAO")
  dao: DAO! @relationDocument(property: "daoID")
}
type Relations
  @loadModel(
    id: "kjzl6hvfrbw6c5awvbcox32lixov8g07p8e0e7m9aoz4nprmny751kfmm353oc3"
  ) {
  id: ID!
}

type NabuProfileAlpha
  @loadModel(
    id: "kjzl6hvfrbw6c7m2o4v21vs0zc5b7y4lxrepf67z42ydmifpcnvxtby4fhu6mhl"
  ) {
  daoList: [Relations] @relationFrom(model: "Relations", property: "daoID")
  daoProfiles: [Relations]
    @relationFrom(model: "Relations", property: "membersDaoProfileID")
}

Although the mutation to create the relation doc is successful (see below), when querying NabuProfile for the daoList or daoProfiles, I receive an empty array. Any help would be appreciated.

mutation RelationMutation {
  createRelations(
    input: {
      content: {
        nabuID: "k2t6wzhkhabz4w24beldx5qk00h6oh6vq6z5bhvmh0mbxoix8393yf8qjr9h4y"
        membersDaoProfileID: "kjzl6kcym7w8y7isrss6ifetnkrdn9yt669j1evabau1u99p1s6uk8dhju97o79"
        daoID: "kjzl6kcym7w8y50al2p6lxsrjvcj3h1d0j1a8uan1ezp7lp7jpkei6ubqlvnj86"
      }
    }
  ) {
    document {
      id
      daoID
      nabuID
      nabu {
        id
        displayName
      }
      dao {
        id
      }
    }
  }
}

Hello fren! I hope you are doing well.

I am answering this with best of my knowledge (you can try), maybe @mzk could give a better insight

Actually, the mutation name RelationMutation wouldn’t be actually creating anything for NabuProfile, daoList, daoProfiles. This is because createRelations expects you have the IDs when mutate over the other models. It would only establish the relations (for details have a look at query at the end)

Another way to think over this is, for example createDao has few required fields which are

  1. Name
  2. Chain
  3. Token
  4. CreatedAt
  5. Descrpition

By performing the mutation RelationMutation and providing only IDs we wouldn’t be creating mutations for the other models, but establishing relations which would be useful to make queries

Query I performed. (I have already performed mutation into those three models)

query MyQuery 
{
  relationsIndex(first: 10) 
{
    edges {
      node {
        dao {
          chain
          creator {
            id
            nabuProfileAlpha {
              displayName
              accountCreated
            }
          }
        }
      }
    }
  }
}

Result I got

{
  "data": {
    "relationsIndex": {
      "edges": [
        {
          "node": {
            "dao": {
              "chain": "cosmos:iov-mainnet",
              "creator": {
                "id": "did:key:z6MkhWwL6rCaEcjWBRJF72auqyuyCk2qMVpb3Tir51vARhkD",
                "nabuProfileAlpha": {
                  "displayName": "Ashutosh Jha",
                  "accountCreated": "2007-12-03T10:15:30Z"
                }
              }
            }
          }
        }
      ]
    }
  }
}

I hope it helps, if I misunderstood/missed something feel free to reply down below!!

2 Likes

This pieces together some notions I was missing. So in all, we would query the relation model directly instead of trying to go through the profile or dao model. I queried the RelationIndex on my end and got the results I was after!
Thank you Ashutosh, appreciate the help and the detailed response!

1 Like

@0x74c7b157af4E5418F0 - appreciate you jumping in and assisting!

@cozart - please let us know how else we can help, or if you have any other questions :slight_smile: