Skip to content

problem: web-of-trust dgraph.go doesn't set schema type on Profile so GraphQL queries don't work #11

Description

@macro88

Need to set dgraph.type = "Profile" when creating nodes. GraphQL only returns nodes with the matching type; your DQL code creates nodes without that triple.

changes in dgraph.go:

1. Add type definition in the DQL schema and keep predicates the same

func (c *Client) EnsureSchema(ctx context.Context) error {
    schema := `pubkey: string @index(exact) @upsert .
kind3CreatedAt: int @index(int) .
last_db_update: int @index(int) .
follows: [uid] @reverse .
followers: [uid] .

type Profile {
  pubkey
  follows
  followers
  kind3CreatedAt
  last_db_update
}`
    return c.dg.Alter(ctx, &api.Operation{Schema: schema})
}

2. Set dgraph.type when creating follower and followees

  followerNQuads := fmt.Sprintf(`
            _:follower <pubkey> %q .
            _:follower <dgraph.type> "Profile" .
            _:follower <kind3CreatedAt> "%d" .
            _:follower <last_db_update> "%d" .
        `, signerPubkey, kind3createdAt, lastUpdate)
  var createNQuads string
        followeeUIDs := make([]string, len(followeeList))

        for i, followee := range followeeList {
            key := fmt.Sprintf("followee_%d", i)
            if nodes, exists := bulkResult[key]; exists && len(nodes) > 0 {
                // Followee exists
                followeeUIDs[i] = nodes[0].UID
            } else {
                // Need to create followee
                blankNodeID := fmt.Sprintf("new_followee_%d", i)
                createNQuads += fmt.Sprintf("_:%s <pubkey> %q .\n", blankNodeID, followee)
                createNQuads += fmt.Sprintf("_:%s <dgraph.type> \"Profile\" .\n", blankNodeID)
                followeeUIDs[i] = "_:" + blankNodeID
            }
        }

3. Ensure type on updates that might implicitly create nodes

 setNquads := `
        uid(f) <pubkey> "` + signerPubkey + `" .
        uid(f) <dgraph.type> "Profile" .
        uid(f) <kind3CreatedAt> "` + fmt.Sprintf("%d", kind3createdAt) + `" .
        uid(f) <last_db_update> "` + fmt.Sprintf("%d", lastUpdate) + `" .`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions