Skip to content
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

graphql #21

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions composites/00-dev.graphql
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@

type CeramicDev
@createModel(accountRelation: SINGLE, description: "A Ceramic developer") {
developer: DID! @documentAccount
languages: Language!
}

type AttestToDev @createModel(accountRelation: LIST, description: "Signals if user attests to another developer profile") {
attester: DID! @documentAccount
attestedProfileId: StreamID! @documentReference(model: "CeramicDev")
profile: CeramicDev! @relationDocument(property: "attestedProfileId")
signal: Boolean!
}

enum Proficiency {
Beginner
Intermediate
Expand All @@ -31,4 +17,25 @@ type Language {
WebAssembly: Proficiency
Solidity: Proficiency
Other: Proficiency
}
}

type CeramicDev
@createModel(
accountRelation: SET
accountRelationFields: ["context"]
description: "A Ceramic developer") {
developer: DID! @documentAccount
context: String! @string(maxLength: 100)
languages: Language!
attestations: [AttestToDev] @relationFrom(model: "AttestToDev", property: "attestedProfileId")
}

type AttestToDev @createModel(
accountRelation: SET
accountRelationFields: ["attestedProfileId"]
description: "Signals if user attests to another developer profile") {
attester: DID! @documentAccount
attestedProfileId: StreamID! @documentReference(model: "CeramicDev")
profile: CeramicDev! @relationDocument(property: "attestedProfileId")
signal: Boolean!
}
14 changes: 8 additions & 6 deletions composites/01-extension.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
type AttestToDev @loadModel(id: "$ATTEST_ID") {
id: ID!
type AttestToDev @createModel(
accountRelation: SET
accountRelationFields: ["attestedProfileId"]
description: "Signals if user attests to another developer profile") {
attester: DID! @documentAccount
attestedProfileId: StreamID! @documentReference(model: "CeramicDev")
profile: CeramicDev! @relationDocument(property: "attestedProfileId")
signal: Boolean!
}

type CeramicDev @loadModel(id: "$DEVELOPER_ID") {
attestations: [AttestToDev] @relationFrom(model: "AttestToDev", property: "attestedProfileId")
}
109 changes: 34 additions & 75 deletions scripts/run.mjs
Original file line number Diff line number Diff line change
@@ -1,82 +1,41 @@
import ora from 'ora'

import { spawn } from "child_process"
import { EventEmitter } from 'events'
import { writeComposite } from './composites.mjs';

const events = new EventEmitter()
const spinner = ora();

const ceramic = spawn("npm", ["run", "ceramic"]);
ceramic.stdout.on("data", (buffer) => {
console.log('[Ceramic]', buffer.toString())
if (buffer.toString().includes("0.0.0.0:7007")) {
events.emit("ceramic", true);
spinner.succeed("ceramic node started");
}
})

ceramic.stderr.on('data', (err) => {
console.log(err.toString())
})

const bootstrap = async () => {
// TODO: convert to event driven to ensure functions run in correct orders after releasing the bytestream.
// TODO: check if .grapql files match their .json counterparts
// & do not create the model if it already exists & has not been updated
try {
spinner.info("[Composites] bootstrapping composites");
await writeComposite(spinner)
spinner.succeed("Composites] composites bootstrapped");
} catch (err) {
spinner.fail(err.message)
ceramic.kill()
throw err
}
enum Proficiency {
Beginner
Intermediate
Advanced
Expert
}

const graphiql = async () => {
spinner.info("[GraphiQL] starting graphiql");
const graphiql = spawn('node', ['./scripts/graphiql.mjs'])
spinner.succeed("[GraphiQL] graphiql started");
graphiql.stdout.on('data', (buffer) => {
console.log('[GraphiqQL]',buffer.toString())
})
type Language {
JavaScript: Proficiency
Python: Proficiency
Rust: Proficiency
Java: Proficiency
Swift: Proficiency
Go: Proficiency
Cpp: Proficiency
Scala: Proficiency
WebAssembly: Proficiency
Solidity: Proficiency
Other: Proficiency
}

const next = async () => {
const next = spawn('npm', ['run', 'nextDev'])
spinner.info("[NextJS] starting nextjs app");
next.stdout.on('data', (buffer) => {
console.log('[NextJS]', buffer.toString())
})
type CeramicDev
@createModel(
accountRelation: SET
accountRelationFields: ["context"]
description: "A Ceramic developer") {
developer: DID! @documentAccount
context: String! @string(maxLength: 100)
languages: Language!
attestations: [AttestToDev] @relationFrom(model: "AttestToDev", property: "attestedProfileId")
}

const start = async () => {
try {
spinner.start('[Ceramic] Starting Ceramic node\n')
events.on('ceramic', async (isRunning) => {
if (isRunning) {
await bootstrap()
await graphiql()
await next()
}
if(isRunning === false) {
ceramic.kill()
process.exit()
}
})
} catch (err) {
ceramic.kill()
spinner.fail(err)
}
type AttestToDev @createModel(
accountRelation: SET
accountRelationFields: ["attestedProfileId"]
description: "Signals if user attests to another developer profile") {
attester: DID! @documentAccount
attestedProfileId: StreamID! @documentReference(model: "CeramicDev")
profile: CeramicDev! @relationDocument(property: "attestedProfileId")
signal: Boolean!
}

start()

process.on("SIGTERM", () => {
ceramic.kill();
});
process.on("beforeExit", () => {
ceramic.kill();
});