REST: {
basePath: "/players",
description: "player service REST API",
routes: [typeDefs ์์ฑ์ ์๋น์ค์ ํ์ํ ์ ์(scalar๋ฅผ ์ ์ธํ ํ์
, ์ธํฐํ์ด์ค, ์ด๊ฑฐํ ๋ฑ ๋ชจ๋ ํํ)์ ์ถ๊ฐํ๊ฑฐ๋ ๊ธฐ์กด ํ์
(API Gateway์์ ์ ๊ณตํ๋ ๊ธฐ๋ณธ ํ์
๊ณผ ๋ถ์ฐ ์๋น์ค์์ ์ ๊ณตํ ํ์
๋ค)์ ํ์ฅ ํ ์ ์์ต๋๋ค. {
method: "GET",
path: "/:id",
deprecated: false,
description: "Get player information by id",
call: {
action: "player.get",
params: {
id: "@path.id",
},
},
}, {
method: "GET",
path: "/me",
deprecated: false,
description: "Get player information of mine",
call: {
action: "player.get",
params: {
id: "@context.user.player.id",
},
},
}, {
method: "GET",
path: "/me",
deprecated: false,
description: "Get player information of mine",
map: `({ path, query, body, context }) => context.user.player`,
}, {
method: "POST",
path: "/message",
deprecated: false,
description: "Push notifications to all players",
publish: {
event: "player.message",
broadcast: false,
params: {
userId: "@context.user.player.id",
message: "@body.message",
},
},
}, ],
},// @body ๊ฐ์ฒด ์ ์ฒด๋ฅผ ํ์ด๋ก๋๋ก ์ ๋ฌํ๊ฑฐ๋ ์คํธ๋ฆผ์ ์ ๋ฌ ํ ๋ ์ด์ฉ๋ฉ๋๋ค.
params: "@body",
// @ ๋ฌธ์์ด๋ก ์์๋์ง ์๋ ๊ฐ๋ค์ ํด์๋์ง ์๊ณ ๊ทธ๋๋ก ์ ๋ฌ๋ฉ๋๋ค.
params: {
foo: "@path.foo", // will bar parsed
bar: "query.bar", // will be "query.bar"
zzz: ["any", { obj: "ject", can: "be", "use": 2 }],
},
// ํญ์ string ํ์
์ ๊ฐ๋ @query, @path ๊ฐ์ฒด์ ์์ฑ๋ค์ ํํด์ ํ์
์ boolean์ด๋ number๋ก ๋ณํ ํ ์ ์์ต๋๋ค.
params: {
foo: "@path.foo:number",
bar: "@query.bar:boolean",
}, GraphQL: {
typeDefs: `
"""Soccer Player"""
type Player implements Node {
id: ID!
email: String!
name: String!
photoURL: String
position: String
"""A team player belongs to"""
team: Team
}
extend type Query {
"""Current Player"""
viewer: Player
player(id: ID!): Player
}
extend type Subscription {
playerMessage: String!
playerUpdated: Player
}
`, resolvers: { Player: { team: {
call: {
action: "team.get",
params: {
id: "@source.teamId",
},
},
}, position: `({ source, args, context, info }) => source.position.toUpperCase()`,
` // be noted that special field __isTypeOf got only three arguments
__isTypeOf: `({ source, context, info }) => return source.someSpecialFieldForThisType != null`,
// be noted that special field __resolveType got only three arguments
__resolveType: `
({ source, context, info }) => {
if (source.someSpecialFieldForThisType != null) {
return "TypeA";
} else {
return "TypeB";
}
}
`,
}, Query: {
viewer: {
call: {
action: "player.get",
params: {
id: "@context.user.player.id[]",
},
},
},
player: {
call: {
action: "player.get",
params: {
id: "@args.id[]",
},
},
},
},query {
viewer {
id
email
}
one: player(id: 1) {
id
email
}
two: player(id: 2) {
id
email
}
three: player(id: 3) {
id
email
}
} Subscription: {
playerMessage: {
subscribe: {
events: ["player.message"],
},
}, playerMessage: {
subscribe: {
events: ["player.message"],
map: `({ source, args, context, info }) => source.payload.message`,
},
},
},
},
}, protocol: {