You are viewing a single comment's thread from:
RE: graphQL advanced: 고오급 graphQL 테크닉 - Mutation 후 Query를 한반에!
launchpad가 망할 것을 대비하여 전체 소스를 댓글로 첨부한다.
import { makeExecutableSchema } from 'graphql-tools';
const ballMaxCount = 5;
let ballCount = ballMaxCount;
let scores = [];
const typeDefs = `
type Score {
result: Boolean
}
type Query {
getBallCount: Int
getScores: [ Score ]
}
type Mutation {
submitKick: Query
}
`;
const resolvers = {
Query: {
getBallCount: (root, args, context) => ballCount,
getScores: ()=> scores
},
Mutation: {
submitKick: (root, args, context) => {
if (ballCount === 0) {
ballCount = ballMaxCount;
scores = [];
}
let result = !~~(Math.random()+0.5);
scores.push( { result } );
ballCount--;
return {
result
};
}
}
};
export const schema = makeExecutableSchema({
typeDefs,
resolvers,
});
export function context(headers, secrets) {
return {
headers,
secrets,
};
};
아놔 진짜 launchpad 망했네. 나님 선견지명 무엇?
![](https://steemitimages.com/640x0/https://cdn.steemitimages.com/DQmR7RbD2hqtKzUVGizVBAJsDbvU9PCrbaZyYd8kMi6qhb2/image.png)