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

feat: More GraphQL fields #106

Merged
merged 1 commit into from
Jan 14, 2024
Merged
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
63 changes: 48 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ This project demonstrates using
<a target="_blank" href="https://microservices.io/patterns/data/saga.html">saga</a>
(effectively a distributed transaction) that interacts with multiple services
and has a robust, edge-case-proof rollback strategy, as well as durable function
execution.

**Temporal abstracts away failures.**

The upstream microservices that are called during the workflow all use gRPC.
execution. **Temporal abstracts away failures.**

## Resources:

Expand All @@ -40,8 +36,9 @@ make

> [!NOTE]
>
> Under the hood, we use [pkgx][pkgx] to run Temporal's [dev
> server][temporal-cli], and Docker to run [Jaeger][jaeger] (a telemetry
> Under the hood, we use [pkgx][pkgx] to run a bunch of internal tools,
> including Temporal's [dev server][temporal-cli]. We use Docker to run the
> infrastructure components, such as Postgres and [Jaeger][jaeger] (a telemetry
> backend).

[temporal-cli]: https://github.com/temporalio/cli
Expand Down Expand Up @@ -134,23 +131,57 @@ Every endpoint is also accessible via a GraphQL API powered by
```shell
pkgx tailcall start \
./tailcall/server.graphql \
./tailcall/org.graphql
./tailcall/org.graphql \
./tailcall/profile.graphql \
./tailcall/license.graphql
```

A GraphQL Playground will launch automatically for you.

Let's create an Org:
Let's create some data:

```graphql
mutation CreateOrg {
mutation Create {
createOrg(
input: {
id: "e0d77fa9-faa5-4a7d-83a3-92fe3a83544c"
id: "00000000-0000-0000-0000-000000000000"
name: "Kevin's Org"
}
) {
id
name
org {
id
name
}
}

createProfile(
input: {
id: "00000000-0000-0000-0000-000000000000"
fullName: "Kevin Chen"
orgId: "00000000-0000-0000-0000-000000000000"
}
) {
profile {
id
fullName
orgId
}
}

createLicense(
input: {
id: "00000000-0000-0000-0000-000000000000"
start: "2024-01-01T15:50-04:00"
end: "2024-01-07T15:50-04:00"
userId: "00000000-0000-0000-0000-000000000000"
}
) {
license {
id
start
end
userId
}
}
}
```
Expand All @@ -160,8 +191,10 @@ and then retrieve it:
```graphql
query GetOrg {
org(id: "e0d77fa9-faa5-4a7d-83a3-92fe3a83544c") {
id
name
org {
id
name
}
}
}
```
12 changes: 12 additions & 0 deletions cmd/svc/license/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,21 @@ func (s *Service) CreateLicense(

err = license.Upsert(ctx, s.db, true, []string{models.LicenseColumns.ID}, boil.Infer(), boil.Infer())
if err != nil {
log.Error("Failed to create License",
"id", req.Msg.GetId(),
"err", err,
)

return nil, fmt.Errorf("unable to insert record: %w", err)
}

log.Info("Successfully created License.",
"id", req.Msg.GetId(),
"user_id", req.Msg.GetUserId(),
"start", req.Msg.GetStart(),
"end", req.Msg.GetEnd(),
)

res := &licensev1beta1.CreateLicenseResponse{
License: &licensev1beta1.License{
Id: license.ID,
Expand Down
13 changes: 12 additions & 1 deletion cmd/svc/profile/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *Service) CreateProfile(
log.Info("Creating Profile...",
"id", req.Msg.GetId(),
"org_id", req.Msg.GetOrgId(),
"name", req.Msg.GetFullName(),
"full_name", req.Msg.GetFullName(),
)

profile := models.Profile{
Expand All @@ -51,9 +51,20 @@ func (s *Service) CreateProfile(

err := profile.Upsert(ctx, s.db, true, []string{models.ProfileColumns.ID}, boil.Infer(), boil.Infer())
if err != nil {
log.Error("Failed to create Profile",
"id", req.Msg.GetId(),
"err", err,
)

return nil, fmt.Errorf("unable to insert record: %w", err)
}

log.Info("Successfully created Profile.",
"id", req.Msg.GetId(),
"org_id", req.Msg.GetOrgId(),
"full_name", req.Msg.GetFullName(),
)

res := &profilePB.CreateProfileResponse{
Profile: &profilePB.Profile{
Id: profile.ID,
Expand Down
35 changes: 35 additions & 0 deletions tailcall/license.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
type Timestamp {
seconds: Int!
nanos: Int!
}

input TimestampInput {
seconds: Int!
nanos: Int!
}

type License {
id: ID!
start: Timestamp!
end: Timestamp!
userId: String!
}

input GetLicenseRequest {
id: String!
}

type GetLicenseResponse {
license: License!
}

input CreateLicenseInput {
id: ID!
start: TimestampInput!
end: TimestampInput!
userId: String!
}

type CreateLicenseResponse {
license: License!
}
1 change: 0 additions & 1 deletion tailcall/org.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

type Org {
id: ID!
name: String!
Expand Down
23 changes: 23 additions & 0 deletions tailcall/profile.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
type Profile {
id: ID!
fullName: String!
orgId: String!
}

input GetProfileRequest {
id: String!
}

type GetProfileResponse {
profile: Profile!
}

input CreateProfileInput {
id: ID!
fullName: String!
orgId: String!
}

type CreateProfileResponse {
profile: Profile!
}
28 changes: 28 additions & 0 deletions tailcall/server.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ type Query {
baseURL: "http://localhost:9090"
path: "/orgs/{{args.id}}"
)

profile(id: ID!): GetProfileResponse!
@http(
baseURL: "http://localhost:9091"
path: "/profiles/{{args.id}}"
)

license(id: ID!): GetLicenseResponse!
@http(
baseURL: "http://localhost:9092"
path: "/licenses/{{args.id}}"
)
}

type Mutation {
Expand All @@ -31,4 +43,20 @@ type Mutation {
path: "/orgs/{{args.input.id}}"
body: "{{args.input}}"
)

createProfile(input: CreateProfileInput!): CreateProfileResponse!
@http(
baseURL: "http://localhost:9091"
method: "POST"
path: "/profiles/{{args.input.id}}"
body: "{{args.input}}"
)

createLicense(input: CreateLicenseInput!): CreateLicenseResponse!
@http(
baseURL: "http://localhost:9092"
method: "POST"
path: "/licenses/{{args.input.id}}"
body: "{{args.input}}"
)
}
Loading