π5λΆ μμ Google App Engineμ Apollo GraphQL μλ² κ΅¬μ±νκΈ°!
Design by @imrahelk
κ΅¬κΈ μ± μμ§(Google App Engine)μ μλ² μμ΄ λ°±μλ API μλ²λ₯Ό ꡬμΆνκΈ° μ’μ νλ«νΌμ
λλ€. κ°λ°μκ° μ€λ‘μ§ μ± κ°λ°μλ§ μ§μ€ν μ μμ΅λλ€. μΉμλ², λ‘λλ°Έλ°μ€, λ€νΈμν¬ κ΅¬μ± λ± λͺ°λΌλ λ©λλ€. γ
γ
νμ¬ GAEλ JAVA, PHP, Node.js, Python, C#, .Net, Ruby, Go λ±μ μΈμ΄λ₯Ό μ§μν©λλ€. μμΈν λ΄μ©μ GAE μ¬μ΄νΈλ₯Ό μ°Έκ³ νμΈμ.
μ λ 2014λ λμ "μ λ μ§μ½λ―Ήμ€λ κ΅¬κΈ μ±μμ§μ μ ννλ" μ¬λΌμ΄λλ₯Ό λ³΄κ³ λμ, GAEλ₯Ό μ λ§ λ§μ΄ μ΄μ©νμ΅λλ€. GAEλ PaaS(Platform as a service) μλΉμ€μ λλ€. νμ€(PaaS)λ§κ³ λ SaaS, IaaS, BaaS λ± λ€μν ννμ ν΄λΌμ°λ μλΉμ€κ° μ‘΄μ¬ν©λλ€.
BaaSκ° μμ μλ Backend as a serviceλ₯Ό μλ―Ένμ΅λλ€. νμ§λ§ μ΄μ λ Blockchain as a serviceλ₯Ό μλ―Ένλ κ² κ°μ΅λλ€. μ΄μ λ λΈλ‘체μΈλ ν΄λΌμ°λ μλΉμ€ ννλ‘ μ¬μ©νλ μλμ
λλ€. μλ§μ‘΄μ μλ
(2018)λΆν° λΈλ‘μ²΄μΈ ν΄λΌμ°λ μλΉμ€λ₯Ό μμνμ΅λλ€.
- AWSμμμ λΈλ‘체μΈ: https://aws.amazon.com/ko/blockchain/
κ·Έλ¦¬κ³ BaaS νλκΉ κ΅λ΄ KTHμμ μλΉμ€νλ baas.ioκ° μκ°λ©λλ€. baas.ioλ μ λ§ μ μ¬μ©νμμ΅λλ€. νμ§λ§ μ μ μ€νλ νκΈ°μ μ μμ¬μ λ€μκΈΈλ‘ μ¬λΌμ Έμ λ무 μνκΉμ μ΅λλ€. μ°Έκ³ λ‘ baas.ioλ κ°κ²©μ΄ λ¬΄μ² μ λ ΄νμ΅λλ€. baas.ioλ₯Ό λͺ¨λ₯΄μλ λΆμ μν΄ κ΄λ ¨ κΈ°μ¬λ₯Ό λ§ν¬ν©λλ€.
- KTH, λͺ¨λ°μΌ μ± κ°λ° λμ°λ―Έ μλΉμ€ μΆμ: http://www.bloter.net/archives/132383
μλμ λ¨κ³λ₯Ό λ°λ₯΄λ©΄ 5λΆ μμ Apollo GraphQL Serverλ₯Ό Google App Engine (GAE)μμ μ€νν μ μμ΅λλ€. λ΄μ©μ "Apollo GraphQL Server on Google App Engine in under 5 minutes!" λΈλ‘κ·Έλ₯Ό μ°Έκ³ νμμ΅λλ€.
νλ‘μ νΈ μμ±νκΈ°
apollo-graphql-server λλ ν 리λ₯Ό λ§λλλ€.
$ mkdir apollo-graphql-server
$ cd apollo-graphql-server
μλ λͺ
λ Ήμ μ€ννκ³ package.json νμΌμ μμ±ν©λλ€.
$ npm init
μλ λͺ
λ Ήμ μ€ννμ¬ νμν λͺ¨λμ μ€μΉν©λλ€.
$ npm install --save graphql-yoga
graphql-yogaλ₯Ό μ¬μ©νλ©΄ GraphQL Serverλ₯Ό λ§€μ° μ½κ² ꡬνν μ μμ΅λλ€. μμΈν λ΄μ©μ graphql-yoga μ¬μ΄νΈμμ νμΈν΄μ£ΌμΈμ.
index.js λ§λ€κΈ°
ndex.js νμΌμ λ§λ€κ³ μλ λ΄μ©μ μ
λ ₯ν©λλ€.
const { GraphQLServer } = require('graphql-yoga');
const PORT = process.env.PORT || 8080;
const typeDefs = `
type Query {
hello: String!
}
`;
const resolvers = {
Query: {
hello: () => "Hi"
}
}
const server = new GraphQLServer({ typeDefs, resolvers });
server.start({ port: PORT }, () => {
console.log(`Server running on http://localhost:${PORT}`)
});
μλ²λ
process.env.PORTλ³μμμ ν¬νΈλ₯Ό μ§μ νλλ‘ ν©λλ€. μ΄κ²μ GAE λ°νμμ μν΄ μ€μ λ νκ²½ λ³μμ λλ€. 그리κ³PORTκ°μ GAE λ°νμμ μν΄ 8080μΌλ‘ μ€μ λ©λλ€.
package.json
package.json νμΌμμ μμ μ€ν¬λ¦½νΈμ node λ° npm λ²μ μ μ§μ ν©λλ€.
"scripts": {
"start": "npx babel-node index"
}
"engines": {
"node": "> = 8.16",
"npm": "5.x"
}
app.yaml
GAEμ λ°°ν¬νκΈ° μν΄μλ app.yaml νμΌμ΄ νμν©λλ€. app.yaml νμΌμ λ§λ€κ³ μλ λ΄μ©μ μ
λ ₯ν©λλ€.
runtime: nodejs
env: flex
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
automatic_scaling:
min_num_instances: 1
max_num_instances: 20
cool_down_period_sec: 60
cpu_utilization:
target_utilization: 0.80
app.yaml νμΌ μ 보λ 곡μ λ¬Έμλ₯Ό μ°Έκ³ νμΈμ.
μ± λ°°ν¬νκΈ°
μλ λͺ λ Ήμ μ€ννλ©΄ μ±μ λ°°ν¬νκΈ° μμν©λλ€. λ°°ν¬κ° μλ£λκΈ°κΉμ§ 1~2λΆ μ λ μμλ©λλ€.
gcloud app deploy
μ± μ€ννκΈ°
μλ λͺ λ Ήμ μ€ννλ©΄ κΈ°λ³Έ λΈλΌμ°μ μμ μ± URLλ‘ μ΄λν©λλ€.
gcloud app browse
https://[your-project-id].appspot.comμ κ°μ URLλ‘ μ΄λνκ² λ©λλ€. κ·ΈλΌ μλμ κ°μ΄ GraphiQL μΈν°νμ΄μ€λ₯Ό λ³Ό μ μμ΅λλ€.
μ¬κΈ°κΉμ§ μ½μ΄μ£Όμ
μ κ°μ¬ν©λλ€.