Skip to content

Commit 0da77f1

Browse files
author
Adnan Rahić
authored
example(apollo federation blogpost): live demo code samples (#5314)
1 parent cb81fdb commit 0da77f1

File tree

29 files changed

+3224
-0
lines changed

29 files changed

+3224
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CUBEJS_DB_HOST=demo-db-examples.cube.dev
2+
CUBEJS_DB_PORT=5432
3+
CUBEJS_DB_NAME=fraud
4+
CUBEJS_DB_USER=cube
5+
CUBEJS_DB_PASS=12345
6+
CUBEJS_DB_TYPE=postgres
7+
CUBEJS_API_SECRET=SECRET
8+
CUBEJS_DEV_MODE=true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM --platform=linux/amd64 node:18.9.0-alpine3.15
2+
3+
WORKDIR /usr/src/app
4+
COPY package.json package-lock.json ./
5+
RUN npm install --omit=dev
6+
COPY . ./
7+
8+
CMD [ "node", "src/gateway.js" ]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM --platform=linux/amd64 node:18.9.0-alpine3.15
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY package.json package-lock.json ./
6+
RUN npm install --omit=dev
7+
COPY . ./
8+
9+
CMD [ "node", "src/server.js" ]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const postgres = require('postgres')
2+
const sql = postgres('postgres://cube:[email protected]:5432/fraud', { max: 10 })
3+
module.exports = sql
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '3'
2+
3+
services:
4+
server:
5+
image: us-central1-docker.pkg.dev/cube-devrel-team/apollo-server/server
6+
build:
7+
context: ./
8+
dockerfile: Dockerfile.server
9+
ports:
10+
- '4000:4000'
11+
gateway:
12+
image: us-central1-docker.pkg.dev/cube-devrel-team/apollo-server/gateway
13+
build:
14+
context: ./
15+
dockerfile: Dockerfile.gateway
16+
ports:
17+
- '4001:4001'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
type Fraud {
2+
id: ID!
3+
step: Float
4+
type: String
5+
isfraud: Int
6+
amountsum: Float
7+
}
8+
9+
type Query {
10+
fraudsByAmountSumWithStep(isFraud: Int, stepStart: Int, stepEnd: Int): [Fraud]
11+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
"""
2+
A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the `date-time` format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar.
3+
"""
4+
scalar DateTime
5+
6+
input FloatFilter {
7+
equals: Float
8+
notEquals: Float
9+
in: [Float]
10+
notIn: [Float]
11+
set: Boolean
12+
gt: Float
13+
lt: Float
14+
gte: Float
15+
lte: Float
16+
}
17+
18+
input StringFilter {
19+
equals: String
20+
notEquals: String
21+
in: [String]
22+
notIn: [String]
23+
contains: String
24+
notContains: String
25+
set: Boolean
26+
}
27+
28+
input DateTimeFilter {
29+
equals: String
30+
notEquals: String
31+
in: [String]
32+
notIn: [String]
33+
inDateRange: [String]
34+
notInDateRange: [String]
35+
beforeDate: String
36+
afterDate: String
37+
set: Boolean
38+
}
39+
40+
enum OrderBy {
41+
asc
42+
desc
43+
}
44+
45+
type TimeDimension {
46+
value: DateTime!
47+
second: DateTime!
48+
minute: DateTime!
49+
hour: DateTime!
50+
day: DateTime!
51+
week: DateTime!
52+
month: DateTime!
53+
quarter: DateTime!
54+
year: DateTime!
55+
}
56+
57+
type FraudMembers {
58+
count: Float
59+
amountSum: Float
60+
step: Float
61+
newbalancedest: String
62+
nameorig: String
63+
oldbalanceorg: String
64+
namedest: String
65+
newbalanceorg: String
66+
oldbalancedest: String
67+
type: String
68+
amount: Float
69+
isFraud: String
70+
isFlaggedFraud: String
71+
}
72+
73+
input FraudWhereInput {
74+
AND: [FraudWhereInput!]
75+
OR: [FraudWhereInput!]
76+
count: FloatFilter
77+
amountSum: FloatFilter
78+
step: FloatFilter
79+
newbalancedest: StringFilter
80+
nameorig: StringFilter
81+
oldbalanceorg: StringFilter
82+
namedest: StringFilter
83+
newbalanceorg: StringFilter
84+
oldbalancedest: StringFilter
85+
type: StringFilter
86+
amount: FloatFilter
87+
isFraud: StringFilter
88+
isFlaggedFraud: StringFilter
89+
}
90+
91+
input FraudOrderByInput {
92+
count: OrderBy
93+
amountSum: OrderBy
94+
step: OrderBy
95+
newbalancedest: OrderBy
96+
nameorig: OrderBy
97+
oldbalanceorg: OrderBy
98+
namedest: OrderBy
99+
newbalanceorg: OrderBy
100+
oldbalancedest: OrderBy
101+
type: OrderBy
102+
amount: OrderBy
103+
isFraud: OrderBy
104+
isFlaggedFraud: OrderBy
105+
}
106+
107+
input RootWhereInput {
108+
AND: [RootWhereInput!]
109+
OR: [RootWhereInput!]
110+
fraud: FraudWhereInput
111+
}
112+
113+
input RootOrderByInput {
114+
fraud: FraudOrderByInput
115+
}
116+
117+
type Result {
118+
fraud(where: FraudWhereInput, orderBy: FraudOrderByInput): FraudMembers!
119+
}
120+
121+
type Query {
122+
cube(where: RootWhereInput, limit: Int, offset: Int, timezone: String, renewQuery: Boolean, orderBy: RootOrderByInput): [Result!]!
123+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const { gql } = require('apollo-server-express')
2+
const sql = require('../database')
3+
4+
async function amountSumFraudsWithStep({ isFraud, stepStart, stepEnd }) {
5+
return sql`
6+
SELECT
7+
"fraud"."isFraud" as isfraud,
8+
"fraud"."step" as step,
9+
"fraud"."type" as type,
10+
sum("fraud"."amount") as amountsum
11+
FROM public.fraud AS "fraud"
12+
WHERE
13+
"fraud"."isFraud" = ${isFraud}
14+
AND
15+
"fraud"."step" BETWEEN ${stepStart} AND ${stepEnd}
16+
GROUP BY 1, 2, 3
17+
ORDER BY 1 ASC;
18+
`
19+
}
20+
21+
module.exports = {
22+
typeDefs: gql`
23+
extend type Query {
24+
fraudsByAmountSumWithStep(isFraud: Int, stepStart: Int, stepEnd: Int): [Fraud]
25+
}
26+
27+
type Fraud {
28+
id: ID!
29+
step: Float
30+
type: String
31+
isfraud: Int
32+
amountsum: Float
33+
}
34+
`,
35+
resolvers: {
36+
Query: {
37+
fraudsByAmountSumWithStep: async (obj, args, context, info) =>
38+
amountSumFraudsWithStep(
39+
{ isFraud: args.isFraud, stepStart: args.stepStart, stepEnd: args.stepEnd }
40+
)
41+
},
42+
}
43+
}

0 commit comments

Comments
 (0)