-
-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wip - Pothos EdgeDB Plugin #539
Draft
baristikir
wants to merge
9
commits into
hayes:main
Choose a base branch
from
baristikir:bt--edgedb-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9f8c270
Initial EdgeDB Plugin Setup
baristikir 3c28ac7
Add Type System for EdgeDBObject API
baristikir f46dd33
Fix Types
baristikir fceaa3f
Remove CHANGELOG
baristikir fbd3fe0
Fix CI
baristikir 054b723
Types Clean Up ++ Add basic logic of edgeDBField
baristikir eb18ba4
Fix resolve return types
baristikir f853b76
Add ReturnShape to Model Types ++ Fix edgeDBFields resolve return typ…
baristikir 8ec9e25
Fix ReturnShape's optionality with DeepPartial
baristikir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dbschema/edgeql-js/* | ||
TODO.md | ||
api-design.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dbschema | ||
edgedb.toml | ||
test | ||
tests | ||
.turbo | ||
babel.config.js | ||
tsconfig.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ISC License (ISC) | ||
Copyright 2021 Michael Hayes | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# EdgeDB Plugin for Pothos | ||
|
||
This plugin provides tighter integration with `edgedb`, making it easier to define edgedb based | ||
object types. | ||
|
||
## Example | ||
|
||
Here is a quick example of what an API using this plugin might look like. There is a more thorough | ||
breakdown of what the methods and options used in the example below. | ||
|
||
```typescript | ||
// Create an object type based on a edgedb model | ||
// without providing any custom type information | ||
builder.edgeDBObject('User', { | ||
fields: (t) => ({ | ||
// expose fields from the database | ||
id: t.exposeID('id'), | ||
email: t.exposeString('email'), | ||
name: t.exposeString('name', { nullable: true }), | ||
// Multi Link field for Users Posts | ||
posts: t.link("posts"), | ||
}), | ||
}); | ||
|
||
builder.queryType({ | ||
fields: (t) => ({ | ||
// Define a field that issues an optimized edgedb query | ||
me: t.edgeDBField({ | ||
type: 'User', | ||
resolve: async (query, root, args, ctx, info) => { | ||
const db_query = e | ||
.select(e.User, (user) => { | ||
// the `query` argument will add in the `select`s fields to | ||
// resolve as much of the request in a single query as possible | ||
...query, | ||
filter: e.op(user.id, '=', ctx.user.id), | ||
}); | ||
|
||
return await db.run(db_query); | ||
} | ||
}), | ||
}), | ||
}); | ||
``` | ||
|
||
Given this schema, you would be able to resolve a query like the following with a single edgedb | ||
query. | ||
|
||
```graphql | ||
query { | ||
me { | ||
posts { | ||
title | ||
author { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## EdgeDB Expressions | ||
|
||
The `e` variable provides everything you need to build an edgedb query. All EdgeQL commands, | ||
standard library functions, and types are available as properties on e. | ||
|
||
[Source](https://www.edgedb.com/docs/clients/js/querybuilder#expressions) | ||
|
||
```ts | ||
import e from './dbschema/edgeql-js'; | ||
|
||
// commands | ||
e.select; | ||
e.insert; | ||
e.update; | ||
e.delete; | ||
|
||
// types | ||
e.str; | ||
e.bool; | ||
e.cal.local_date; | ||
e.User; | ||
e.Post; | ||
e....; | ||
|
||
// functions | ||
e.str_upper; | ||
e.len; | ||
e.count; | ||
e.math.stddev; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module default { | ||
type Post { | ||
required property big_int_id -> bigint { | ||
constraint exclusive; | ||
}; | ||
required property created_at -> datetime { | ||
default := datetime_current(); | ||
constraint exclusive; | ||
readonly := true; | ||
}; | ||
required property updated_at -> datetime; | ||
|
||
required property title -> str; | ||
property content -> str; | ||
required property published -> bool; | ||
|
||
link author -> User; | ||
} | ||
|
||
type Media { | ||
required property url -> str; | ||
multi link posts -> PostMedia; | ||
link uploaded_by -> User; | ||
} | ||
|
||
type PostMedia { | ||
required link post -> Post; | ||
required link media -> Media; | ||
} | ||
|
||
type Comment { | ||
required property created_at -> datetime { | ||
default := datetime_current(); | ||
constraint exclusive; | ||
readonly := true; | ||
}; | ||
required property content -> str; | ||
required link author -> User; | ||
required link post -> Post; | ||
} | ||
|
||
type Profile { | ||
property bio -> str; | ||
required link user -> User; | ||
} | ||
|
||
type User { | ||
required property email -> str { | ||
constraint exclusive; | ||
}; | ||
property name -> str; | ||
multi link posts -> Post; | ||
multi link comments -> Comment; | ||
link profile -> Profile; | ||
multi link followers -> Follow; | ||
multi link following -> Follow; | ||
multi link media -> Media; | ||
} | ||
|
||
type Follow { | ||
required link from_user -> User; | ||
required link to_user -> User; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CREATE MIGRATION m1co7oxdqc52kxete3rozfhbkb67kofxnqspppu7ek6pe327a5mtyq | ||
ONTO initial | ||
{ | ||
CREATE TYPE default::Post { | ||
CREATE REQUIRED PROPERTY big_int_id -> std::bigint { | ||
CREATE CONSTRAINT std::exclusive; | ||
}; | ||
CREATE PROPERTY content -> std::str; | ||
CREATE REQUIRED PROPERTY created_at -> std::datetime { | ||
SET default := (std::datetime_current()); | ||
SET readonly := true; | ||
CREATE CONSTRAINT std::exclusive; | ||
}; | ||
CREATE REQUIRED PROPERTY published -> std::bool; | ||
CREATE REQUIRED PROPERTY title -> std::str; | ||
CREATE REQUIRED PROPERTY updated_at -> std::datetime; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
CREATE MIGRATION m1goni6inys6wt4wokvqvemtqiiambmkfxudnf6rsculrh645bozla | ||
ONTO m1co7oxdqc52kxete3rozfhbkb67kofxnqspppu7ek6pe327a5mtyq | ||
{ | ||
CREATE TYPE default::Comment { | ||
CREATE REQUIRED LINK post -> default::Post; | ||
CREATE REQUIRED PROPERTY content -> std::str; | ||
CREATE REQUIRED PROPERTY created_at -> std::datetime { | ||
SET default := (std::datetime_current()); | ||
SET readonly := true; | ||
CREATE CONSTRAINT std::exclusive; | ||
}; | ||
}; | ||
CREATE TYPE default::User { | ||
CREATE MULTI LINK comments -> default::Comment; | ||
CREATE MULTI LINK posts -> default::Post; | ||
CREATE REQUIRED PROPERTY email -> std::str { | ||
CREATE CONSTRAINT std::exclusive; | ||
}; | ||
CREATE PROPERTY name -> std::str; | ||
}; | ||
ALTER TYPE default::Comment { | ||
CREATE REQUIRED LINK author -> default::User; | ||
}; | ||
CREATE TYPE default::Follow { | ||
CREATE REQUIRED LINK from_user -> default::User; | ||
CREATE REQUIRED LINK to_user -> default::User; | ||
}; | ||
ALTER TYPE default::User { | ||
CREATE MULTI LINK followers -> default::Follow; | ||
CREATE MULTI LINK following -> default::Follow; | ||
}; | ||
CREATE TYPE default::Media { | ||
CREATE LINK uploaded_by -> default::User; | ||
CREATE REQUIRED PROPERTY url -> std::str; | ||
}; | ||
CREATE TYPE default::PostMedia { | ||
CREATE REQUIRED LINK media -> default::Media; | ||
CREATE REQUIRED LINK post -> default::Post; | ||
}; | ||
ALTER TYPE default::Media { | ||
CREATE MULTI LINK posts -> default::PostMedia; | ||
}; | ||
ALTER TYPE default::User { | ||
CREATE MULTI LINK media -> default::Media; | ||
}; | ||
ALTER TYPE default::Post { | ||
CREATE LINK author -> default::User; | ||
}; | ||
CREATE TYPE default::Profile { | ||
CREATE REQUIRED LINK user -> default::User; | ||
CREATE PROPERTY bio -> std::str; | ||
}; | ||
ALTER TYPE default::User { | ||
CREATE LINK profile -> default::Profile; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[edgedb] | ||
server-version = "2.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* | ||
!.gitignore | ||
!.npmignore | ||
!package.json |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
transformIgnorePatterns: [`node_modules`], | ||
transform: { | ||
'^.+\\.(t|j)sx?$': ['@swc/jest'], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"name": "@pothos/plugin-edgedb", | ||
"version": "3.4.0", | ||
"description": "An edgedb plugin for Pothos", | ||
"main": "./lib/index.js", | ||
"types": "./dts/index.d.ts", | ||
"module": "./esm/index.js", | ||
"exports": { | ||
"types": "./dts/index.d.ts", | ||
"import": "./esm/index.js", | ||
"require": "./lib/index.js" | ||
}, | ||
"scripts": { | ||
"generate": "edgeql-js --output-dir tests/client/", | ||
"type": "tsc --project tsconfig.type.json", | ||
"build": "pnpm build:clean && pnpm build:cjs && pnpm build:esm && pnpm build:dts", | ||
"build:clean": "git clean -dfX esm lib", | ||
"build:cjs": "swc src -d lib --config-file ../../.swcrc -C module.type=commonjs", | ||
"build:esm": "swc src -d esm --config-file ../../.swcrc -C module.type=es6 && pnpm esm:extensions", | ||
"build:dts": "tsc", | ||
"esm:extensions": "TS_NODE_PROJECT=../../tsconfig.json node -r @swc-node/register ../../.config/esm-transformer.ts", | ||
"test": "jest --runInBand" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/hayes/pothos.git" | ||
}, | ||
"author": "Michael Hayes", | ||
"license": "ISC", | ||
"keywords": [ | ||
"giraphql", | ||
"pothos", | ||
"graphql", | ||
"schema", | ||
"edgedb", | ||
"plugin" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"peerDependencies": { | ||
"@pothos/core": "*", | ||
"graphql": ">=15.1.0" | ||
}, | ||
"devDependencies": { | ||
"@pothos/core": "workspace:*", | ||
"@pothos/plugin-complexity": "workspace:*", | ||
"@pothos/plugin-errors": "workspace:*", | ||
"@pothos/plugin-relay": "workspace:*", | ||
"@pothos/plugin-simple-objects": "workspace:*", | ||
"@pothos/test-utils": "workspace:*", | ||
"edgedb": "^0.21.3", | ||
"graphql": "16.5.0", | ||
"graphql-tag": "^2.12.6" | ||
}, | ||
"gitHead": "9dfe52f1975f41a111e01bf96a20033a914e2acc" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably don't need giraphql in keywords anymore, I think pothos had gotten enough traction that there shouldn't be many people still looking for giraphql