Skip to content

Commit

Permalink
Merge pull request #19 from zefhub/auth-schema
Browse files Browse the repository at this point in the history
New op types
  • Loading branch information
thedanielforum authored Jul 4, 2022
2 parents 2d349fe + 388031e commit f960a76
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
6 changes: 4 additions & 2 deletions server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
RUN ln -fs /usr/share/zoneinfo/Asia/Singapore /etc/localtime

ADD ikura.graphql .
ADD ikura-prod.graphql .
ADD ikura.zefops.py .

RUN pip3 install zef==v0.15.6a2
RUN pip3 install zef==v0.15.7a3

# pip install stuff
ADD requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt

EXPOSE 5001

ENTRYPOINT ["python3", "-mzef.gql.simplegql", "--port", "5001", "--create", "ikura.graphql", "ikura-production"]
ENTRYPOINT ["python3", "-mzef.gql.simplegql", "--port", "5001", "--create", "--schema-file", "ikura-prod.graphql", "--hooks", "ikura.zefops.py", "--data-tag", "ikura-production"]
55 changes: 55 additions & 0 deletions server/ikura-prod.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Zef.SchemaVersion: v1
# Zef.Authentication: {"Algo": "HS256", "Audience": "ikura.app", "VerificationKeyEnv": "VERIFICATION_KEY_ENV", "Header": "X-Auth-Token"}

type User
@auth(
add: """
(info.context | get_in[('auth', 'admin')][False])
"""
query: """
(z | F.Email
| equals[info.context
| get_in[('auth', 'email')][None]
| collect])
"""
)
@upfetch(field: "email")
@hook(onCreate: "userCreate") {
sub: String
email: String! @unique @search
givenName: String
familyName: String
phone: String
birthday: DateTime
transactions: [Transaction]
@incoming
@relation(source: "Transaction", rt: "User", target: "User")
categories: [Category]
@incoming
@relation(source: "Category", rt: "User", target: "User")
}

type Transaction
@auth(
query: """
auth_field('user', 'query')
"""
) {
user: User @relation(rt: "User")
category: Category
amount: Int @search
date: DateTime @search
}

type Category
@auth(
query: """
auth_field('user', 'query')
"""
) {
user: User
transactions: [Transaction] @incoming @relation(rt: "Category")
name: String
icon: String
created: DateTime
}
7 changes: 3 additions & 4 deletions server/ikura.zefops.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ def setupGraph(data_g):
if length(data_g | now | all[ET.DefaultCategory]) == 0:
# ...
{ET.DefaultCategory: {
RT.Name: "Groceries",
RT.Icon: "blah"
RT.Name: "Transportation",
RT.Icon: "🚂"
}} | data_g | run


@func(g)
def userCreate(z):
Expand All @@ -26,4 +26,3 @@ def userCreate(z):
RT.Icon: def_cat | F.Icon | collect,
RT.User: z,
}} | data_g | run

1 comment on commit f960a76

@vercel
Copy link

@vercel vercel bot commented on f960a76 Jul 4, 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.vercel.app
ikura-git-main-zefhub.vercel.app
ikura-zefhub.vercel.app
www.ikura.app
ikura.app

Please sign in to comment.