Sudograph is a GraphQL database for the Internet Computer (IC).
Its goal is to become the simplest way to develop applications for the IC. Developers start by defining a GraphQL schema using the GraphQL SDL. Once the schema is defined, it can be included within a canister and deployed to the IC. An entire relational database is generated from the schema, with GraphQL queries and mutations enabling a variety of CRUD operations, including advanced querying over relational data.
For full documentation, see The Sudograph Book, which is hosted entirely on the IC by the way.
If you've already got Node.js, npm, Rust, the wasm32-unknown-unknown Rust compilation target, and dfx 0.7.0 installed then just run the following commands:
bash
mkdir my-new-project
cd my-new-project
npx sudograph
dfx start --background
dfx deploy
Once deployed, you can visit the following canisters from a Chromium browser: * playground: http://r7inp-6aaaa-aaaaa-aaabq-cai.localhost:8000 * frontend: http://rrkah-fqaaa-aaaaa-aaaaq-cai.localhost:8000
If the above did not work, try the full installation steps below.
You should have the following installed on your system:
If you already have the above installed, you can skip to Sudograph generate.
Run the following commands to install Node.js and npm. nvm is highly recommended and its use is shown below:
```bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
nvm install 14 ```
Run the following command to install Rust and the wasm32-unknown-unknown target:
```bash curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-unknown-unknown ```
Run the following command to install dfx 0.7.0:
```bash
DFX_VERSION=0.7.0 sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" ```
Start by making a new directory for your project. You then simply run the sudograph generate command:
```bash mkdir my-new-project
cd my-new-project
npx sudograph ```
Start up an IC replica and deploy:
```bash
dfx start
dfx start --background
dfx deploy ```
Make sure to run dfx deploy
for your first deploy. For quicker deployments after the first, you can run dfx deploy graphql
if you've only changed your schema or the Rust code within the graphql canister. dfx deploy graphql
will only deploy the graphql canister, which contains the generated database.
Start executing GraphQL queries and mutations against your database by going to the following URL in a Chromium browser: http://r7inp-6aaaa-aaaaa-aaabq-cai.localhost:8000.
View a simple frontend application that communicates with the graphql canister by going to the following URL in a Chromium browser: http://rrkah-fqaaa-aaaaa-aaaaq-cai.localhost:8000.
You can execute queries against the graphql canister from the command line if you wish:
```bash
dfx canister call graphql graphql_query '("query { readUser(input: {}) { id } }", "{}")'
dfx canister call graphql graphql_mutation '("mutation { createUser(input: { username: \"lastmjs\" }) { id } }", "{}")' ```
Before deploying to production you should understand that Sudograph is alpha/beta software. There are missing features and potential bugs. There is also no way to easily migrate data (if you change your schema, you'll need to delete your state and start over). But if you must deploy to production, here is the command:
bash
dfx deploy --network ic
The following are very likely to be implemented by Sudograph in the short to medium term future:
@auth(role: OWNER)
for individual fields The following may or may not be implemented by Sudograph, but they seem like good ideas:
Sudograph was inspired by many previous projects: