Skip to content

Commit

Permalink
Untested ideas for setupGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
pengwyn committed Jun 6, 2022
1 parent 61c2972 commit fb5e891
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
19 changes: 13 additions & 6 deletions server/ikura.graphql
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Zef.SchemaVersion: v1
# Zef.Authentication: {"Algo": "HS256", "VerificationKey": "2c3432fba16d204318282d820959521efcd43fa1f3d75abb9ec31e902c65f981", "Audience": "ikura.app", "Header": "X-Auth-Token"}


type User
@auth(
add: """
(info.context | tap[print] | get_in[('auth', 'admin')][False])
(info.context | get_in[('auth', 'admin')][False])
"""
query: """
(z >> RT.Email
Expand All @@ -14,7 +15,10 @@ type User
| collect])
"""
)
@upfetch(field: "email") {
@upfetch(field: "email")
@hook(
onCreate: "userCreate"
) {
sub: String
email: String! @unique @search
givenName: String
Expand All @@ -24,6 +28,9 @@ type User
transactions: [Transaction]
@incoming
@relation(source: "Transaction", rt: "User", target: "User")
categories: [Category]
@incoming
@relation(source: "Category", rt: "User", target: "User")
}

type Transaction
Expand All @@ -36,9 +43,8 @@ type Transaction
| collect])
"""
) {
user: User @relation(source: "Transaction", rt: "User", target: "User")
user: User @relation(rt: "User")
category: Category
@relation(source: "Transaction", rt: "Category", target: "Category")
amount: Int @search
date: DateTime @search
}
Expand All @@ -62,10 +68,11 @@ type Category
| collect])
"""
) {
user: User @relation(source: "Category", rt: "User", target: "User")

user: User
transactions: [Transaction]
@incoming
@relation(source: "Transaction", rt: "Category", target: "Category")
@relation(rt: "Category")
name: String
icon: String
created: DateTime
Expand Down
29 changes: 29 additions & 0 deletions server/ikura.zefops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from zef import *
from zef.ops import *




@func(g)
def setupGraph(data_g):
if length(data_g | now | all[ET.DefaultCategory]) == 0:
# ...
{ET.DefaultCategory: {
RT.Name: "Groceries",
RT.Icon: "blah"
}} | data_g | run


@func(g)
def userCreate(z):
print("UserCreate was run")
# Assign the users some categories by default.
data_g = Graph(z)

for def_cat in data_g | now | all[ET.DefaultCategory]:
new_cat = {ET.Category: {
RT.Name: def_cat | F.Name | collect,
RT.Icon: def_cat | F.Icon | collect,
RT.User: z,
}} | data_g | run

1 comment on commit fb5e891

@vercel
Copy link

@vercel vercel bot commented on fb5e891 Jun 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ikura – ./

ikura-zefhub.vercel.app
www.ikura.app
ikura.app
ikura.vercel.app
ikura-git-main-zefhub.vercel.app

Please sign in to comment.